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

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.

Here's a proposal for how to find the length of the shortest cycle in an undirected graph with unit edge lengths. When a back edge, say (v,w), is encountered during a depth-first search, it forms a cycle with the tree edges from wtov. The length of the cyclelevel[v]-level[w+1] is where the level of a vertex is its distance in the DFS tree from the root vertex. This suggests the following algorithm:

• Do a depth-first search, keeping track of the level of each vertex.

• Each time a back edge is encountered, compute the cycle length and save it if it is smaller than the shortest one previously seen. Show that this strategy does not always work by providing a counterexample as well as a brief (one or two sentence) explanation.

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

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.

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 eEconnects two cities, and you know its length in miles, le. You want to get 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 leL

(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 sto t.

(b) You are now 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 anO[(V+E)log|V|]algorithm to determine this.

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