Algorithm Design, Anal. & Imp., Homework 4 Solution
|
|
- Beryl Lyons
- 6 years ago
- Views:
Transcription
1 Algorithm Design, Anal. & Imp., Homework 4 Solution Note: The solution is for your personal use for this course. You are not allowed to post the solution in public place. There could be mistakes in the solution; if you find any, let me know. Questions 1: Solve problem 24-2 (CLRS page 678) ( ) (a). Say that x nests in y and y nests in z. This means that we can formulate a π mapping for both nesting relations such that: x πi < y i and y πj < z j Because all values of i and j are unique and drawn from the set 1 d we can find for each i a j such that i = π j. Then we have: x πi < y i = y πj < z j x πi < z j And we can find such a unique z j for every x πi. (b). Sort in non-decreasing order the d dimenson values within both x = (x 1, x 2 x d ) and y = (y 1, y 2 y d ). Compare x i and y i for every value of i = 1 to d. If x i < y i for all i then x nests within y. (c). Sort the d dimension values within each box B i. This takes O(d lg d) for every box, totalling to O(nd lg d) for the n boxes. For each possible pair of box (B i, B j ) check if B i nests in B j or if B j nests in B i. Each pair-comparison takes O(d) and there are O(n 2 ) pairs in total, so all nesting pair relations can be obtained in O(dn 2 ) steps. We create a graph with n nodes each representing one of the B i s. For each (B i, B j ) pair such that B i nests in B j we add a directed edge from B i to B j. This graph construction takes O(n 2 ) time. Now add a new vertices s to the graph, such that s has an outgoing edge to each vertices. Run topological sort on the resulting graph with s as the root vertex. Since V = O(n) for this graph, the runnning time for topological sort is O(n + n 2 ). Now consider all the vertices in topological order. For each vertex u examine its adjacency list and for each edge (u, v) anti-relax the edge as: 1
2 1 if d[v] < d[u] + w(u, v) 2 d[v] = d[u] + w(u, v) 3 π[v] = u This traversal takes O(E) = O(n 2 ) time. When the traversal terminates, find the vertex v with the largest d[v] value in O(n) time. Remove s from the graph and call PRINT-PATH on the vertex v. The overall running time of the algorithm is bounded by O(dn 2 + nd lg d). 2: Solve problem 23-3(a), and 23-3(b) (CLRS page 640) (8+7) (a). For graph G(V, E), T b is its Bottleneck Spanning Tree (BST), and T m is its MST. We claim that T b = T m. Proof : Assume that, T b T m ; also assume that the heaviest edge in T b is b with weight w b, and the heaviest edge in T m is m with weight w m. Case 1 (w b = w m ): The weight of the bottleneck edge in T b is equal to the weight of the heaviest edge in T m ; then, for the bottleneck problem, we can simply return T m instead of T b, as both have the same optimal value (weight of the heaviest edge). Then the bottleneck tree is an MST, and we are done with the proof. Case 2 (w b < w m ): Since, b is the heaviest edge in T b, and w b < w m, the edge m does not present in T b ; also weights of all the edges in T b is strictly smaller than w m. Now, consider the tree T m ; by removing the edge m from T m we obtain a forest with two trees. Since, m / T b, there must exist (at least) one edge, x, such that x T b and x / T m, and x connects the trees in the above forest to make another spanning tree of G, which is: T = T m {x} \ {m}; since weight of x is strictly smaller than w m, the tree T has smaller weight than the MST T m. Then T m is not an MST, we reach a contradiction, so this case can t happen. Case 3 (w b > w m ): In this case, the weight of the heaviest edge m in T m is strictly smaller than the weight of the bottleneck edge b in T b. Then T b is not a BST, because we have T m whose heaviest edge is smaller than the heaviest edge of T b. We reach another contradiction, so this case also cannot happen. Considering all the above cases, T b = T m (proved) (b). From the graph G, we remove all the edges that have weight higher than b. Then we run the Breadth-First-Search (BFS) on the modified graph to check if the graph is still connected. If it is, then the graph has a BST whose value is at most b, if the graph is not connected, it can t have a BST with a value b. The cost of BFS is linear, O(V + E). 3: Solve problem (CLRS page 1101) (15) 2
3 The longest-simple-cycle problem is the problem of determining a simple cycle (no repeated vertices) of maximum length in a graph. Show that this problem is NP-complete. We first define the decision version of the longest-simple-cycle problem as below: LongestSimpleCycle(G, k): Given an undirected graph G and an integer k, does G has a simple cycle of length at least k. Now, we will show that LongestSimpleCycle(G, k) is N P-Complete. We will reduce a known N P-Complete problem, namely HamCycle(H) problem for this proof. The HamCycle(H) is defined as below: HamCycle(H): Given an undirected graph H does H has a Hamintonian cycle. LongestSimpleCycle(G, k) N P: Proof: Let (G, k) be an instance of LongestSimpleCycle. Given a certificate of proof y, which is a sequence of vertices, we can simply scan through the graph G in polynomial time to verify that y is a cycle, no vertex in y appears more than once, and length of y is k or higher. HamCycle(H) p LongestSimpleCycle(G, k): Proof: From an instance of HamCycle(H), we construct an instance LongestSimpleCycle(H, V ). The instrumentation is trivial and it can be done in constant (polynomial) time. Now we claim, the graph H(V, E) has a Hamintonian cycle, if and only if the length of its longest simple cycle is equal to V. The claim is correct, because if H(V, E) has a Hamiltonian cycle, that cycle is a simple path of length V. On the other hand, if H does not have a Hamiltonian cycle, the length of the longest simple in H must be strictly less than V. The above proofs conclude that the LongestSimpleCycle is N P-Complete. 4: Suppose you have a black-box subroutine to solve the decision version of the clique problem that is defined in Section Give an algorithm that accepts an undirected graph G and returns a clique of maximum size. The running time of your algorithm should be polynomial in O( V ) and O( E ), considering that each query to the black-box takes O(1) time. (15) The decision version of clique problem takes as input two parameter, an undirected graph G(V, E) and a number k <= V. It returns yes if a clique of size k is present in graph G, no otherwise. Our assumption is that, this black-box operation takes O(1) time. Now, we give an algorithm which uses this black-box operation to return a clique of largest size. First, we find the size of the largest clique in a given graph G. For that we call black-box(g, i) where i = V. If black-box returns yes, we know that the size of largest clique is V or else we call black-box again but before that we decrement the possible largest clique size by 1 (black-box(g, i)) 3
4 with i = V 1. We repeat decrementing i and calling black-box, until we find the size of the largest clique. Thus, largest clique size = i, such that, black-box(g, i) = yes and (x>i) black-box(g, x) = no. Suppose k is the size of largest clique of graph G. For each v V we create G(V, E ) where V = V \ {v} and E = E \ {{(v, u)} {(u, v)} : u V } and check if the largest clique of new graph is also k. If yes we consider the new graph G instead of G for the next iteration. We return G(V, E) when V = k Find-max-clique(G(V, E)) 1 for i = V to 1: 2 if (black-box(g, i) == yes): 3 break; 4 tv = V 5 for each v tv : 6 G = (V, E ) where, V = V {v} and E = E {{(v, u)} {(u, v)} : u V } 7 if (black-box(g, i) == yes): 8 G = G 9 10 if V == k: 11 return G Complexity : Finding the size of largest clique can take at most V k call to black-box. Next from line 7 in each iteration we consider one node of the graph and no node is considered more than once. Consequently at most V call to black-box. All other computations are negligible with respect to black-box. Therefore, complexity of the algorithm is O( V ). 5: You are given a set of cities, along with the pattern of highways between them, in the form of an undirected graph G = (V, E). Each stretch of highway, e E connects two of the cities, and you know its length in miles, l e. You want to go from city s to city t. There s one problem: your car can only hold enough gas to cover L miles. There are gas stations in each city, but not between cities. Therefore, you can only take a route if every one of its edges has length l e L. a. Given the limitation on your car s fuel tank capacity, show how to determine in linear time whether there is a feasible route from s to t. (5) b. You are planning to buy a new car, and you want to know the minimum fuel tank capacity that is needed to travel from s to t. Give a O(E lg V ) algorithm to determine this. (5) Solution: a. Solution is trivial as removing all edges from the graph with length greater than L and then 4
5 performing a Depth-First-Search (DFS) starting from s and see if t can be reached (Running time of DFS is linear i.e., O(V + E) b. For this problem, we need to find a path from s to t, such that the largest edge-weight on the path is the smallest. We call it a bottleneck path from s to t. The maximum length edge on the bottleneck path is the bottleneck edge, and your car must have a fuel capacity to cover the distance of this bottleneck edge. Note that bottleneck path is not necessarily a shortest path. For example, assume, the shortest path distance from s to t has two edges with total weight of 10 (4 + 6), but there exist another path from s to t that has four edges with total weight of 11 ( ); clearly, the shortest path is not the bottleneck path, as the maximum edge weight in the second path is 3, which is smaller that the maximum edge weight in the first path (which is 6). To obtain a bottleneck path, we will modify the Dijkstra s algorithm as below: In Dijkstra s shortest path algorithm, for every vertex we have a field d, which is also the key field of the priority queue, Q. We replace the d field by another field called dist, such that u.dist stores the length of the bottleneck edge on a bottleneck path from s to u. The field, dist will be the key field of the priority queue in this solution. On initialization, s.dist = 0, and u.dist = for all u V \ {s}. To udpate u.dist, we need to modify the Relax subroutine as shown below. Then we call Dijkstra s algorithm by replacing the Initialize-Single-Source(G, s) with Initialize-Single-Source- Bottleneck(G, s). and also by replacing the Relax(u, v, w) with Relax-Bottleneck(u, v, w). Once Dijkstra terminates, the desired answer to the question is t.dist. Initialize-Single-Source-Bottleneck(G, s) 1 for each vertex v G.V 2 v.dist = 3 v.π = nil 4 5 s.dist = 0 Relax-Bottleneck(u, v.w) 1 if max(u.dist, w(u, v)) < v.dist 2 v.dist = max(u.dist, w(u, v)) 3 v.π = u Correctness Proof and Complexity: Bottleneck path holds optimal substructure property, i.e., for every vertex v, if u is the predecessor of v in a bottleneck path from s to v, the bottleneck edge from s to v is either the bottlenck edge on the path from s to u or the edge (u, v), whichever is larger. This is exactly what we implemented in the above Relax-Bottleneck subroutine. The complexity is O((E + V ) lg V ) = O(E lg V ) 5
Single Source Shortest Path
Single Source Shortest Path A directed graph G = (V, E) and a pair of nodes s, d is given. The edges have a real-valued weight W i. This time we are looking for the weight and the shortest path from s
More informationFundamental Algorithms CSCI-GA /Summer Solution to Homework 8
Fundamental Algorithms CSCI-GA.70-00/Summer 206 Solution to Homework 8 Problem (CLRS 23.-6). ( point) Show that a graph has a unique minimum spanning tree if, for every cut of the graph, there is a unique
More informationUnit 2: Algorithmic Graph Theory
Unit 2: Algorithmic Graph Theory Course contents: Introduction to graph theory Basic graph algorithms Reading Chapter 3 Reference: Cormen, Leiserson, and Rivest, Introduction to Algorithms, 2 nd Ed., McGraw
More informationShortest Path Problem
Shortest Path Problem CLRS Chapters 24.1 3, 24.5, 25.2 Shortest path problem Shortest path problem (and variants) Properties of shortest paths Algorithmic framework Bellman-Ford algorithm Shortest paths
More informationExam 3 Practice Problems
Exam 3 Practice Problems HONOR CODE: You are allowed to work in groups on these problems, and also to talk to the TAs (the TAs have not seen these problems before and they do not know the solutions but
More informationUnit 5F: Layout Compaction
Course contents Unit 5F: Layout Compaction Design rules Symbolic layout Constraint-graph compaction Readings: Chapter 6 Unit 5F 1 Design rules: restrictions on the mask patterns to increase the probability
More informationUnit 3: Layout Compaction
Unit 3: Layout Compaction Course contents Design rules Symbolic layout Constraint-graph compaction Readings: Chapter 6 Unit 3 1 Design rules: restrictions on the mask patterns to increase the probability
More informationMinimum Spanning Trees
Minimum Spanning Trees Overview Problem A town has a set of houses and a set of roads. A road connects and only houses. A road connecting houses u and v has a repair cost w(u, v). Goal: Repair enough (and
More informationUndirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1
Undirected Graphs Terminology. Free Trees. Representations. Minimum Spanning Trees (algorithms: Prim, Kruskal). Graph Traversals (dfs, bfs). Articulation points & Biconnected Components. Graph Matching
More informationSolutions to relevant spring 2000 exam problems
Problem 2, exam Here s Prim s algorithm, modified slightly to use C syntax. MSTPrim (G, w, r): Q = V[G]; for (each u Q) { key[u] = ; key[r] = 0; π[r] = 0; while (Q not empty) { u = ExtractMin (Q); for
More informationSample Solutions to Homework #4
National Taiwan University Handout #25 Department of Electrical Engineering January 02, 207 Algorithms, Fall 206 TA: Zhi-Wen Lin and Yen-Chun Liu Sample Solutions to Homework #4. (0) (a) Both of the answers
More information2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.
1. T F: Consider a directed graph G = (V, E) and a vertex s V. Suppose that for all v V, there exists a directed path in G from s to v. Suppose that a DFS is run on G, starting from s. Then, true or false:
More informationMinimum Spanning Trees My T. UF
Introduction to Algorithms Minimum Spanning Trees @ UF Problem Find a low cost network connecting a set of locations Any pair of locations are connected There is no cycle Some applications: Communication
More informationComputer Science & Engineering 423/823 Design and Analysis of Algorithms
Computer Science & Engineering 423/823 Design and Analysis of Algorithms Lecture 07 Single-Source Shortest Paths (Chapter 24) Stephen Scott and Vinodchandran N. Variyam sscott@cse.unl.edu 1/36 Introduction
More informationChapter 22. Elementary Graph Algorithms
Graph Algorithms - Spring 2011 Set 7. Lecturer: Huilan Chang Reference: (1) Cormen, Leiserson, Rivest, and Stein, Introduction to Algorithms, 2nd Edition, The MIT Press. (2) Lecture notes from C. Y. Chen
More informationMinimum Spanning Trees
Minimum Spanning Trees Problem A town has a set of houses and a set of roads. A road connects 2 and only 2 houses. A road connecting houses u and v has a repair cost w(u, v). Goal: Repair enough (and no
More informationfrom notes written mostly by Dr. Carla Savage: All Rights Reserved
CSC 505, Fall 2000: Week 9 Objectives: learn about various issues related to finding shortest paths in graphs learn algorithms for the single-source shortest-path problem observe the relationship among
More informationData Structures and Algorithms. Werner Nutt
Data Structures and Algorithms Werner Nutt nutt@inf.unibz.it http://www.inf.unibz/it/~nutt Chapter 10 Academic Year 2012-2013 1 Acknowledgements & Copyright Notice These slides are built on top of slides
More informationHomework Assignment #3 Graph
CISC 4080 Computer Algorithms Spring, 2019 Homework Assignment #3 Graph Some of the problems are adapted from problems in the book Introduction to Algorithms by Cormen, Leiserson and Rivest, and some are
More informationCOMP251: Single source shortest paths
COMP51: Single source shortest paths Jérôme Waldispühl School of Computer Science McGill University Based on (Cormen et al., 00) Problem What is the shortest road to go from one city to another? Eample:
More information22 Elementary Graph Algorithms. There are two standard ways to represent a
VI Graph Algorithms Elementary Graph Algorithms Minimum Spanning Trees Single-Source Shortest Paths All-Pairs Shortest Paths 22 Elementary Graph Algorithms There are two standard ways to represent a graph
More informationCSE 431/531: Analysis of Algorithms. Greedy Algorithms. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo
CSE 431/531: Analysis of Algorithms Greedy Algorithms Lecturer: Shi Li Department of Computer Science and Engineering University at Buffalo Main Goal of Algorithm Design Design fast algorithms to solve
More informationChapter 9 Graph Algorithms
Chapter 9 Graph Algorithms 2 Introduction graph theory useful in practice represent many real-life problems can be slow if not careful with data structures 3 Definitions an undirected graph G = (V, E)
More informationMinimum Spanning Trees Ch 23 Traversing graphs
Next: Graph Algorithms Graphs Ch 22 Graph representations adjacency list adjacency matrix Minimum Spanning Trees Ch 23 Traversing graphs Breadth-First Search Depth-First Search 11/30/17 CSE 3101 1 Graphs
More information11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions
Introduction Chapter 9 Graph Algorithms graph theory useful in practice represent many real-life problems can be slow if not careful with data structures 2 Definitions an undirected graph G = (V, E) is
More informationGraph Representation
Graph Representation Adjacency list representation of G = (V, E) An array of V lists, one for each vertex in V Each list Adj[u] contains all the vertices v such that there is an edge between u and v Adj[u]
More informationGraphs. Part II: SP and MST. Laura Toma Algorithms (csci2200), Bowdoin College
Laura Toma Algorithms (csci2200), Bowdoin College Topics Weighted graphs each edge (u, v) has a weight denoted w(u, v) or w uv stored in the adjacency list or adjacency matrix The weight of a path p =
More informationDist(Vertex u, Vertex v, Graph preprocessed) return u.dist v.dist
Design and Analysis of Algorithms 5th September, 2016 Practice Sheet 3 Solutions Sushant Agarwal Solutions 1. Given an edge-weighted undirected connected chain-graph G = (V, E), all vertices having degree
More informationCSE 100 Minimum Spanning Trees Prim s and Kruskal
CSE 100 Minimum Spanning Trees Prim s and Kruskal Your Turn The array of vertices, which include dist, prev, and done fields (initialize dist to INFINITY and done to false ): V0: dist= prev= done= adj:
More informationCS200: Graphs. Rosen Ch , 9.6, Walls and Mirrors Ch. 14
CS200: Graphs Rosen Ch. 9.1-9.4, 9.6, 10.4-10.5 Walls and Mirrors Ch. 14 Trees as Graphs Tree: an undirected connected graph that has no cycles. A B C D E F G H I J K L M N O P Rooted Trees A rooted tree
More informationQuiz 2 Practice Problems
Introduction to Algorithms: 6.006 Massachusetts Institute of Technology April 2, 2008 Professors Srini Devadas and Erik Demaine Handout 9 1 True/False Quiz 2 Practice Problems Decide whether these statements
More informationCSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms. Lecturer: Shi Li
CSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms Lecturer: Shi Li Department of Computer Science and Engineering University at Buffalo Main Goal of Algorithm Design Design fast
More information6.006 Introduction to Algorithms Spring 2008
MIT OpenCourseWare http://ocw.mit.edu 6.006 Introduction to Algorithms Spring 2008 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Introduction to Algorithms:
More informationCOT 6405 Introduction to Theory of Algorithms
COT 6405 Introduction to Theory of Algorithms Topic 16. Single source shortest path 11/18/2015 1 Problem definition Problem: given a weighted directed graph G, find the minimum-weight path from a given
More informationOutlines: Graphs Part-2
Elementary Graph Algorithms PART-2 1 Outlines: Graphs Part-2 Graph Search Methods Breadth-First Search (BFS): BFS Algorithm BFS Example BFS Time Complexity Output of BFS: Shortest Path Breath-First Tree
More informationShortest path problems
Next... Shortest path problems Single-source shortest paths in weighted graphs Shortest-Path Problems Properties of Shortest Paths, Relaxation Dijkstra s Algorithm Bellman-Ford Algorithm Shortest-Paths
More informationGraph representation
Graph Algorithms 1 Graph representation Given graph G = (V, E). May be either directed or undirected. Two common ways to represent for algorithms: 1. Adjacency lists. 2. Adjacency matrix. When expressing
More informationCS 270 Algorithms. Oliver Kullmann. Breadth-first search. Analysing BFS. Depth-first. search. Analysing DFS. Dags and topological sorting.
Week 5 General remarks and 2 We consider the simplest graph- algorithm, breadth-first (). We apply to compute shortest paths. Then we consider the second main graph- algorithm, depth-first (). And we consider
More informationLecture 10. Elementary Graph Algorithm Minimum Spanning Trees
Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees T. H. Cormen, C. E. Leiserson and R. L. Rivest Introduction to Algorithms, 3rd Edition, MIT Press, 2009 Sungkyunkwan University Hyunseung Choo
More informationCOP 4531 Complexity & Analysis of Data Structures & Algorithms
COP 4531 Complexity & Analysis of Data Structures & Algorithms Lecture 9 Minimum Spanning Trees Thanks to the text authors who contributed to these slides Why Minimum Spanning Trees (MST)? Example 1 A
More informationUnit 8: Coping with NP-Completeness. Complexity classes Reducibility and NP-completeness proofs Coping with NP-complete problems. Y.-W.
: Coping with NP-Completeness Course contents: Complexity classes Reducibility and NP-completeness proofs Coping with NP-complete problems Reading: Chapter 34 Chapter 35.1, 35.2 Y.-W. Chang 1 Complexity
More informationCS 270 Algorithms. Oliver Kullmann. Analysing BFS. Depth-first search. Analysing DFS. Dags and topological sorting.
General remarks Week 5 2 We finish, by analysing it. Then we consider the second main graph- algorithm, depth-first (). And we consider one application of, of graphs. Reading from CLRS for week 5 Chapter
More informationTIE Graph algorithms
TIE-20106 1 1 Graph algorithms This chapter discusses the data structure that is a collection of points (called nodes or vertices) and connections between them (called edges or arcs) a graph. The common
More informationDesign and Analysis of Algorithms 演算法設計與分析. Lecture 13 December 18, 2013 洪國寶
Design and Analysis of Algorithms 演算法設計與分析 Lecture 13 December 18, 2013 洪國寶 1 Homework #10 1. 24.1-1 (p. 591 / p. 654) 2. 24.1-6 (p. 592 / p. 655) 3. 24.3-2 (p. 600 / p. 663) 4. 24.3-8 (p. 601) / 24.3-10
More information1 Dijkstra s Algorithm
Lecture 11 Dijkstra s Algorithm Scribes: Himanshu Bhandoh (2015), Virginia Williams, and Date: November 1, 2017 Anthony Kim (2016), G. Valiant (2017), M. Wootters (2017) (Adapted from Virginia Williams
More informationCS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019
CS 341: Algorithms Douglas R. Stinson David R. Cheriton School of Computer Science University of Waterloo February 26, 2019 D.R. Stinson (SCS) CS 341 February 26, 2019 1 / 296 1 Course Information 2 Introduction
More informationChapter 9 Graph Algorithms
Chapter 9 Graph Algorithms 2 Introduction graph theory useful in practice represent many real-life problems can be if not careful with data structures 3 Definitions an undirected graph G = (V, E) is a
More informationLecture 11: Analysis of Algorithms (CS ) 1
Lecture 11: Analysis of Algorithms (CS583-002) 1 Amarda Shehu November 12, 2014 1 Some material adapted from Kevin Wayne s Algorithm Class @ Princeton 1 2 Dynamic Programming Approach Floyd-Warshall Shortest
More informationTaking Stock. IE170: Algorithms in Systems Engineering: Lecture 20. Example. Shortest Paths Definitions
Taking Stock IE170: Algorithms in Systems Engineering: Lecture 20 Jeff Linderoth Department of Industrial and Systems Engineering Lehigh University March 19, 2007 Last Time Minimum Spanning Trees Strongly
More informationElementary Graph Algorithms
Elementary Graph Algorithms Graphs Graph G = (V, E)» V = set of vertices» E = set of edges (V V) Types of graphs» Undirected: edge (u, v) = (v, u); for all v, (v, v) E (No self loops.)» Directed: (u, v)
More informationCS521 \ Notes for the Final Exam
CS521 \ Notes for final exam 1 Ariel Stolerman Asymptotic Notations: CS521 \ Notes for the Final Exam Notation Definition Limit Big-O ( ) Small-o ( ) Big- ( ) Small- ( ) Big- ( ) Notes: ( ) ( ) ( ) ( )
More informationAlgorithm Design and Analysis
Algorithm Design and Analysis LECTURE 6 Greedy Graph Algorithms Shortest paths Adam Smith 9/8/14 The (Algorithm) Design Process 1. Work out the answer for some examples. Look for a general principle Does
More informationChapter 24. Shortest path problems. Chapter 24. Shortest path problems. 24. Various shortest path problems. Chapter 24. Shortest path problems
Chapter 24. Shortest path problems We are given a directed graph G = (V,E) with each directed edge (u,v) E having a weight, also called a length, w(u,v) that may or may not be negative. A shortest path
More informationContext: Weighted, connected, undirected graph, G = (V, E), with w : E R.
Chapter 23: Minimal Spanning Trees. Context: Weighted, connected, undirected graph, G = (V, E), with w : E R. Definition: A selection of edges from T E such that (V, T ) is a tree is called a spanning
More informationDepth-first Search (DFS)
Depth-first Search (DFS) DFS Strategy: First follow one path all the way to its end, before we step back to follow the next path. (u.d and u.f are start/finish time for vertex processing) CH08-320201:
More informationWeek 5. 1 Analysing BFS. 2 Depth-first search. 3 Analysing DFS. 4 Dags and topological sorting. 5 Detecting cycles. CS 270 Algorithms.
1 2 Week 5 3 4 5 General remarks We finish, by analysing it. Then we consider the second main graph- algorithm, depth-first (). And we consider one application of, of graphs. Reading from CLRS for week
More informationSolution for Homework set 3
TTIC 300 and CMSC 37000 Algorithms Winter 07 Solution for Homework set 3 Question (0 points) We are given a directed graph G = (V, E), with two special vertices s and t, and non-negative integral capacities
More informationGraphs. Graph G = (V, E) Types of graphs E = O( V 2 ) V = set of vertices E = set of edges (V V)
Graph Algorithms Graphs Graph G = (V, E) V = set of vertices E = set of edges (V V) Types of graphs Undirected: edge (u, v) = (v, u); for all v, (v, v) E (No self loops.) Directed: (u, v) is edge from
More informationRepresentations of Graphs
ELEMENTARY GRAPH ALGORITHMS -- CS-5321 Presentation -- I am Nishit Kapadia Representations of Graphs There are two standard ways: A collection of adjacency lists - they provide a compact way to represent
More informationAlgorithm Design and Analysis
Algorithm Design and Analysis LECTURE 7 Greedy Graph Algorithms Topological sort Shortest paths Adam Smith The (Algorithm) Design Process 1. Work out the answer for some examples. Look for a general principle
More informationCIS 121 Data Structures and Algorithms Midterm 3 Review Solution Sketches Fall 2018
CIS 121 Data Structures and Algorithms Midterm 3 Review Solution Sketches Fall 2018 Q1: Prove or disprove: You are given a connected undirected graph G = (V, E) with a weight function w defined over its
More information1. Suppose you are given a magic black box that somehow answers the following decision problem in polynomial time:
1. Suppose you are given a magic black box that somehow answers the following decision problem in polynomial time: Input: A CNF formula ϕ with n variables x 1, x 2,..., x n. Output: True if there is an
More informationWeek 11: Minimum Spanning trees
Week 11: Minimum Spanning trees Agenda: Minimum Spanning Trees Prim s Algorithm Reading: Textbook : 61-7 1 Week 11: Minimum Spanning trees Minimum spanning tree (MST) problem: Input: edge-weighted (simple,
More information(Re)Introduction to Graphs and Some Algorithms
(Re)Introduction to Graphs and Some Algorithms Graph Terminology (I) A graph is defined by a set of vertices V and a set of edges E. The edge set must work over the defined vertices in the vertex set.
More informationIntroduction to Algorithms. Lecture 11
Introduction to Algorithms Lecture 11 Last Time Optimization Problems Greedy Algorithms Graph Representation & Algorithms Minimum Spanning Tree Prim s Algorithm Kruskal s Algorithm 2 Today s Topics Shortest
More informationBasic Graph Definitions
CMSC 341 Graphs Basic Graph Definitions A graph G = (V,E) consists of a finite set of vertices, V, and a finite set of edges, E. Each edge is a pair (v,w) where v, w V. V and E are sets, so each vertex
More informationIntroduction. I Given a weighted, directed graph G =(V, E) with weight function
ntroduction Computer Science & Engineering 2/82 Design and Analysis of Algorithms Lecture 06 Single-Source Shortest Paths (Chapter 2) Stephen Scott (Adapted from Vinodchandran N. Variyam) sscott@cse.unl.edu
More informationData Structures and Algorithms. Werner Nutt
Data Structures and Algorithms Werner Nutt nutt@inf.unibz.it http://www.inf.unibz/it/~nutt Part 9 Academic Year 2011-2012 1 Acknowledgements & Copyright Notice These slides are built on top of slides developed
More informationQuestion 2 (Strongly Connected Components, 15 points). What are the strongly connected components of the graph below?
Question 1 (Huffman Code, 15 points). Consider the following set of letters each occurring with the associated frequencies: A 2, B 3, C 7, D 8, E 10, F 15, G 20, H 40, I 50. Give the tree for the corresponding
More informationData Structures and Algorithms. Chapter 7. Graphs
1 Data Structures and Algorithms Chapter 7 Werner Nutt 2 Acknowledgments The course follows the book Introduction to Algorithms, by Cormen, Leiserson, Rivest and Stein, MIT Press [CLRST]. Many examples
More informationGraph Algorithms. Andreas Klappenecker. [based on slides by Prof. Welch]
Graph Algorithms Andreas Klappenecker [based on slides by Prof. Welch] 1 Directed Graphs Let V be a finite set and E a binary relation on V, that is, E VxV. Then the pair G=(V,E) is called a directed graph.
More informationGraph Algorithms: Chapters Part 1: Introductory graph concepts
UMass Lowell Computer Science 91.503 Algorithms Dr. Haim Levkowitz Fall, 2007 Graph Algorithms: Chapters 22-25 Part 1: Introductory graph concepts 1 91.404 Graph Review Elementary Graph Algorithms Minimum
More informationProblem 1. Which of the following is true of functions =100 +log and = + log? Problem 2. Which of the following is true of functions = 2 and =3?
Multiple-choice Problems: Problem 1. Which of the following is true of functions =100+log and =+log? a) = b) =Ω c) =Θ d) All of the above e) None of the above Problem 2. Which of the following is true
More informationCS 10: Problem solving via Object Oriented Programming Winter 2017
CS 10: Problem solving via Object Oriented Programming Winter 2017 Tim Pierson 260 (255) Sudikoff Day 17 Shortest Path Agenda 1. Shortest- path simulalon 2. Dijkstra s algorithm 3. A* search 4. Implicit
More informationSingle Source Shortest Path (SSSP) Problem
Single Source Shortest Path (SSSP) Problem Single Source Shortest Path Problem Input: A directed graph G = (V, E); an edge weight function w : E R, and a start vertex s V. Find: for each vertex u V, δ(s,
More informationOutline. Graphs. Divide and Conquer.
GRAPHS COMP 321 McGill University These slides are mainly compiled from the following resources. - Professor Jaehyun Park slides CS 97SI - Top-coder tutorials. - Programming Challenges books. Outline Graphs.
More information22 Elementary Graph Algorithms. There are two standard ways to represent a
VI Graph Algorithms Elementary Graph Algorithms Minimum Spanning Trees Single-Source Shortest Paths All-Pairs Shortest Paths 22 Elementary Graph Algorithms There are two standard ways to represent a graph
More informationNotes for Lecture 24
U.C. Berkeley CS170: Intro to CS Theory Handout N24 Professor Luca Trevisan December 4, 2001 Notes for Lecture 24 1 Some NP-complete Numerical Problems 1.1 Subset Sum The Subset Sum problem is defined
More informationThe Shortest Path Problem
The Shortest Path Problem 1 Shortest-Path Algorithms Find the shortest path from point A to point B Shortest in time, distance, cost, Numerous applications Map navigation Flight itineraries Circuit wiring
More informationLecture 3: Graphs and flows
Chapter 3 Lecture 3: Graphs and flows Graphs: a useful combinatorial structure. Definitions: graph, directed and undirected graph, edge as ordered pair, path, cycle, connected graph, strongly connected
More informationIntroduction to Algorithms April 16, 2008 Massachusetts Institute of Technology Spring 2008 Professors Srini Devadas and Erik Demaine Quiz 2
Introduction to Algorithms April 16, 2008 Massachusetts Institute of Technology 6.006 Spring 2008 Professors Srini Devadas and Erik Demaine Quiz 2 Quiz 2 Do not open this quiz booklet until you are directed
More informationcsci 210: Data Structures Graph Traversals
csci 210: Data Structures Graph Traversals Graph traversal (BFS and DFS) G can be undirected or directed We think about coloring each vertex WHITE before we start GRAY after we visit a vertex but before
More informationChapter 9 Graph Algorithms
Introduction graph theory useful in practice represent many real-life problems can be if not careful with data structures Chapter 9 Graph s 2 Definitions Definitions an undirected graph is a finite set
More informationCSE373: Data Structures & Algorithms Lecture 17: Minimum Spanning Trees. Dan Grossman Fall 2013
CSE373: Data Structures & Algorithms Lecture 7: Minimum Spanning Trees Dan Grossman Fall 03 Spanning Trees A simple problem: Given a connected undirected graph G=(V,E), find a minimal subset of edges such
More informationTheory of Computing. Lecture 4/5 MAS 714 Hartmut Klauck
Theory of Computing Lecture 4/5 MAS 714 Hartmut Klauck How fast can we sort? There are deterministic algorithms that sort in worst case time O(n log n) Do better algorithms exist? Example [Andersson et
More informationAll Shortest Paths. Questions from exercises and exams
All Shortest Paths Questions from exercises and exams The Problem: G = (V, E, w) is a weighted directed graph. We want to find the shortest path between any pair of vertices in G. Example: find the distance
More informationQuiz 2 CS 3510 October 22, 2004
Quiz 2 CS 3510 October 22, 2004 NAME : (Remember to fill in your name!) For grading purposes, please leave blank: (1) Short Answer (40 points) (2) Cycle Length (20 points) (3) Bottleneck (20 points) (4)
More informationCS 125 Section #6 Graph Traversal and Linear Programs 10/13/14
CS 125 Section #6 Graph Traversal and Linear Programs 10/13/14 1 Depth first search 1.1 The Algorithm Besides breadth first search, which we saw in class in relation to Dijkstra s algorithm, there is one
More informationModule 6 NP-Complete Problems and Heuristics
Module 6 NP-Complete Problems and Heuristics Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 97 E-mail: natarajan.meghanathan@jsums.edu Optimization vs. Decision
More informationCSE 331: Introduction to Algorithm Analysis and Design Graphs
CSE 331: Introduction to Algorithm Analysis and Design Graphs 1 Graph Definitions Graph: A graph consists of a set of verticies V and a set of edges E such that: G = (V, E) V = {v 0, v 1,..., v n 1 } E
More informationInfo 2950, Lecture 16
Info 2950, Lecture 16 28 Mar 2017 Prob Set 5: due Fri night 31 Mar Breadth first search (BFS) and Depth First Search (DFS) Must have an ordering on the vertices of the graph. In most examples here, the
More information5.4 Shortest Paths. Jacobs University Visualization and Computer Graphics Lab. CH : Algorithms and Data Structures 456
5.4 Shortest Paths CH08-320201: Algorithms and Data Structures 456 Definitions: Path Consider a directed graph G=(V,E), where each edge e є E is assigned a non-negative weight w: E -> R +. A path is a
More informationProblem Set 2 Solutions
Design and Analysis of Algorithms February, 01 Massachusetts Institute of Technology 6.046J/18.410J Profs. Dana Moshkovitz and Bruce Tidor Handout 8 Problem Set Solutions This problem set is due at 9:00pm
More informationLecture 13. Reading: Weiss, Ch. 9, Ch 8 CSE 100, UCSD: LEC 13. Page 1 of 29
Lecture 13 Connectedness in graphs Spanning trees in graphs Finding a minimal spanning tree Time costs of graph problems and NP-completeness Finding a minimal spanning tree: Prim s and Kruskal s algorithms
More informationModule 6 P, NP, NP-Complete Problems and Approximation Algorithms
Module 6 P, NP, NP-Complete Problems and Approximation Algorithms Dr. Natarajan Meghanathan Associate Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu
More informationIntroduction to Algorithms. Lecture 24. Prof. Patrick Jaillet
6.006- Introduction to Algorithms Lecture 24 Prof. Patrick Jaillet Outline Decision vs optimization problems P, NP, co-np Reductions between problems NP-complete problems Beyond NP-completeness Readings
More informationDesign and Analysis of Algorithms
Design and Analysis of Algorithms CSE 5311 Lecture 18 Graph Algorithm Junzhou Huang, Ph.D. Department of Computer Science and Engineering CSE5311 Design and Analysis of Algorithms 1 Graphs Graph G = (V,
More informationGraph Algorithms. Definition
Graph Algorithms Many problems in CS can be modeled as graph problems. Algorithms for solving graph problems are fundamental to the field of algorithm design. Definition A graph G = (V, E) consists of
More informationDirected Graphs. DSA - lecture 5 - T.U.Cluj-Napoca - M. Joldos 1
Directed Graphs Definitions. Representations. ADT s. Single Source Shortest Path Problem (Dijkstra, Bellman-Ford, Floyd-Warshall). Traversals for DGs. Parenthesis Lemma. DAGs. Strong Components. Topological
More informationSingle Source Shortest Paths
Single Source Shortest Paths Given a connected weighted directed graph G(V, E), associated with each edge u, v E, there is a weight w(u, v). The single source shortest paths (SSSP) problem is to find a
More information