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)

Short Answer

Expert verified

a)Dijkstra’s algorithm can be made to run in timeO(W|V|+|E|) is proved.

b)Dijkstra’sAlgorithm performsTC=O[(|V|+|E|)logW] time complexity is

Step by step solution

01

Step 1:Dijkstra’s algorithm.

Dijkstra algorithm is an application of single source shortest path.Dijkstra’s algorithm also known as SPF algorithm and is an algorithm for finding the shortest paths between the vertices in a graph. It returns a search tree for all the paths the given node can take. An acyclic graph is a directed graph that has no cycles. Its operation is performed in the minheap.

02

Step 2: Dijkstra’s algorithm can be made to run in time O(W|V|+|E|)a).

Let’s an example for finding the time complexity of the graph. A graph whose edge weights are integers in the range 0,1,........,W, where Wis a relatively small number.The graph G(V,W)where Vare the vertices and Ware the edges. In which Dijkstra algorithm for finding the shortest paths between the vertices in a graph.Evaluate single source shortest path just select any vertex and again select the next vertex as a minimum weight. After applying this process on all the vertex. Add the edges and vertex of each steps. The time complexity can be evaluated.

Fig: Weighted Graph.

By these steps after adding the Vas vertices and Was edgesHence its complexity is:.O(W|V|+|E|)

03

Step 3: Algorithm performs TC=O[(|V|+|E|)logW] time complexity.

b)

Time complexity for the graph G(V,W)where Vare the vertices andWare the edges. The formula for minheap and adjacency list which are used as a data structure. For finding this just take a scenario in which Dijkstra algorithm forfinding the shortest paths between the vertices in a graph.the vertexAis the source vertex. now take a minheap as a data structure for evaluate single source shortest path between the source and the destination. FromAthe distance of is zero and take the distance of vertex from each and every vertex is infinity.Now takeAas the first vertex and evaluate the weight towards each vertex.And choose the next vertex from the vertices which have minimum weight and select that node as the second vertex.Then again evaluate the distance of it from every vertex and as get the minimum weight of the node and consider it as the main node.Through this the series of vertex are arises.whereVare the vertices andWare the edges.

Now the time complexity is given as:

TC=V+VlogV+E+ElogWTC=VlogV+ElogWTC=O[(V+E)logW]

For finding the shortest path adjacent list and minheap both may use. And the mode value represents here the vertex and the edges may oy may not be positive or negative. It works for both when the weighted graph has their edge is of positive or it may be negative weighted graph.

The time complexity is TC=O[(|V|+|E|)log|W|].

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.

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

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.

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.

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