110 likes | 235 Views
Problems from Graphs. Question 1: Given a directed weighted graph. You are also given the shortest path from a source vertex ‘s’ to a destination vertex ‘t’. If weight of every edge is increased by 10 units, does the shortest path remain same in the modified graph ? 65 55 45 35.
E N D
Question 1: Given a directed weighted graph. You are also given the shortest path from a source vertex ‘s’ to a destination vertex ‘t’. If weight of every edge is increased by 10 units, does the shortest path remain same in the modified graph? • 65 • 55 • 45 • 35
Question 2: This is similar to above question. Does the shortest path change when weights of all edges are multiplied by 10? • Yes • No • Sometimes for some graphs but not for all.
Question 3: Given a directed graph where every edge has weight as either 1 or 2, find the shortest path from a given source vertex ‘s’ to a given destination vertex ‘t’. Expected time complexity is O(V+E). • O(E) • O(V) • O(V+E) • O(E*E)
Question 4: Given a directed acyclic weighted graph, how to find the shortest path from a source s to a destination t in O(V+E) time?
Does Dijkstra's algorithm work with negative weights? • Yes • No • Yes and No
http://algs4.cs.princeton.edu/44sp/ • There are two shortest paths algorithms known as Dijkstra's algorithm, depending on whether a vertex can be enqueued on the priority queue more than once. When the weights are nonnegative, the two versions coincide (as no vertex will be enqueued more than once). The version implemented inDijkstraSP.java (which allows a vertex to be enqueued more than once) is correct in the presence of negative edge weights (but no negative cycles) but its running time is exponential in the worst case. (We note that DijkstraSP.java throws an exception if the edge-weighted digraph has an edge with a negative weight, so that a programmer is not surprised by this exponential behavior.) If we modify DijkstraSP.java so that a vertex cannot be enqueued more than once (e.g., using a marked[] array to mark those vertices that have been relaxed), then the algorithm is guaranteed to run in E log V time but it may yield incorrect results when there are edges with negative weights.
Adding a constant to every edge weight does not change the solution to the single-source shortest-paths problem. • True • False • True for some graphs and False for some others.
Every subpath on a shortest path from v to w is also a shortest path between the two endpoints. • True • False • Can’t say. Sometimes true sometimes false.
Suppose that there is a unique shortest path from s to every other vertex. Is the shortest path tree unique? • Yes • No • Unique for some graphs. Not unique for others.