Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Consider a directed graph in which the only negative edges are those that leaves; all other edges are positive. Can Dijkstra's algorithm, started at s, fail on such a graph? Prove your answer.

Short Answer

Expert verified

No, Dijkstra’s algorithm works for a directed graph that have negative edges leaving the source vertex only.

Step by step solution

01

Step-1: Define Dijkstra’s Algorithm

Dijkstra’s algorithm is a single-source shortest path problem. It is used in both directed and undirected graph with non negative weight.

Dijkstra's method to find shortest path:

  1. Begin the initialization process at the root node.
  2. Update the cost of the adjacent nodes in the table by identifying the adjacent nodes.
  3. From the table, find the node with the lowest cost and repeat step 2 until all nodes have been traversed.
02

Step-2: Prove that Dijkstra’s algorithm does not fails for a graph containing negative edges at source only

Dijkstra algorithm does not take the negative edges leaving the source node into account while finding the shortest path to another vertices or nodes of the graph. For two nodes, a and b, in the graph, all the edges in the graph are assumed positive when dist[a]>dist[b] is a contradictions. There cannot be a edge with negative weight from ato b.

In directed graphs with source having negative edges, it continues to be a contradiction. Otherwise, there is a negative weight path using negative edge from a to b. And this edge is from source. It means dist[a]>dist[a,s], which is not possible.

Thus, Dijkstra algorithm does not fail, started at s, on a directed graph with negative edges leaving s.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Question: Prove that for the array prev computed by Dijkstra's algorithm, the edges {u,prepu}(forallv)form a tree.

You are given a strongly connected directed graph G=(V,E) with positive edge weights along with a particularv0V . Give an efficient algorithm for finding shortest paths between all pairs of nodes, with the one restriction that these paths must all pass throughv0 .

Suppose Dijkstra’s algorithm is run on the following graph, starting at node A.

a) Draw a table showing the intermediate distance values of all the nodes at each iteration of the algorithm.

b) Show the final shortest-path tree.

Generalized shortest-paths problem.In Internet routing, there are delays on lines but also, more significantly, delays at routers. This motivates a generalized shortest-paths problem.

Suppose that in addition to having edge lengths {Ie:eE} ,a graph also has vertex costs {cV:vV} . Now define the cost of a path to be the sum of its edge lengths, plusthe costs ofall vertices on the path (including the endpoints). Give an efficient algorithm for the followingproblem.

Input:A directed graph G={V,E} positive edge lengths Ie and positive vertex costs cv; a starting vertex sv.

Output:An array cost[.] such that for every vertex u,costu, is the least cost of any path from s to u (i.e., the cost of the cheapest path), under the defnition above.

Notice that cost[s]=c.

Suppose we want to run Dijkstra’s algorithm on a graph whose edge weights are integers in the range 0,1,........,W, where Wis a relatively small number.
(a) Show how Dijkstra’s algorithm can be made to run in time

O(W|V|+|E|)

(b) Show an alternative implementation that takes time just .

O((|V|+|E|)logW)

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free