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

Give an O|V|2algorithm for the following task.

Input:An undirected graph G=(V,E); edge lengths Ie>0;an edge eE.

Output:The length of the shortest cycle containing edge e

You are given a directed graph G(V,E)with (possibly negative) weighted edges, along with a specific node sVand a tree T=(V,E'),E'E. Give an algorithm that checks whether T is a shortest-path tree for G with starting point s . Your algorithm should run in linear time.

Give an algorithm that takes as input a directed graph with positive edge lengths, and returns the length of the shortest cycle in the graph (if the graph is acyclic, it should say so). Your algorithm should take time at most O|V3|.

In cases where there are several different shortest paths between two nodes (and edges have varying length),the most convenient of these paths is often the one with fewest edges. Forinstance, if nodes represent cities and edge lengths represent costs of flying between cities, theremight be many ways to get from cityto city t which all have the same cost. The mostconvenientof these alternatives is the one which involves the fewest stopovers. Accordingly, for a specific starting node S , define

bestu=minimum number of edges in a shortest path from S to u .

In the example below, thebestvalues for nodes S,A,B,C,D,E,Fare 0,1,1,1,2,2,3, respectively.

Give an efficient algorithm for the following problem.

Input:Graph G=V,E; positive edge lengths le; starting node sV.

Output: The values of bestu should be set for all nodesuV

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.

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