1 / 11

Problems from Graphs.

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.

minda
Download Presentation

Problems from Graphs.

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Problems from Graphs.

  2. 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

  3. 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.

  4. 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)

  5. 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?

  6. Does Dijkstra's algorithm work with negative weights? • Yes • No • Yes and No

  7. 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.

  8. 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.

  9. 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.

  10. 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.

More Related