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.

Short Answer

Expert verified

(a)The table showing the intermediate distance values is as follows.


(b)The final shortest-path tree is as follows:

Step by step solution

01

Explain Dijkstra’s algorithm

Dijkstra’s shortest-path algorithm marks all the distance of all the vertices as infinity. As the algorithm runs, when each vertex is visited, the distance between the vertices is calculated and the lowest distance values are updated at each iteration.

02

Show a table showing the intermediate distance values of all the nodes.

(a)

Consider the given graph ,

Set A as the starting node.

In the first iteration, set all the vertices values as . At the second iteration, the path from A to B is set to 1. At the third iteration, path from A to C is updated to 3 since it is the shortest path.

At the fourth iteration, path from A to D is set to 4 , that is the total of (1+2+1) . At the fifth iteration A to E is set to 4 , that is the direct path.

At the sixth iteration, A to F is set to 8 , that is the direct path. At the seventh iteration, A to F is set to 7 , since it is comparatively lowest cost path.

At the nineth iteration, A to G is set to 7 at first, then it will be updated to 5 on the next iteration. At the last iteration, A to H is set to 8, and later it will be updated to 6 .

The table that shows the intermediate values is as follows,

Therefore, The table showing the intermediate distance values is obtained.

03

Step 3:Show the final shortest-path tree.

(b)

The final shortest-path tree have the shortest path with lowest distance cost is as follows,

Therefore, the above figure represents the final shortest-path tree.

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.

Shortest path algorithms can be applied in currency trading. Let c1,c2,cn be various currencies; for instance, c1might be dollars, c2pounds, and c3 lire.

For any two currencies ci and cj , there is an exchange rate τi,j; this means that you can purchase τi,j units of currency cj in exchange for one unit of cj. These exchange rates satisfy the condition that rij.rji<1 so that if you start with a unit of currency cj, change it into currency and then convert back to currency localid="1658917254028" ci, you end up with less than one unit of currency ci (the difference is the cost of the transaction).

a. Give an efficient algorithm for the following problem: Given a set of exchange rates rij , and two currencies s and t , find the most advantageous sequence of currency exchanges for converting currency into currency . Toward this goal, you should represent the currencies and rates by a graph whose edge lengths are real numbers.

The exchange rates are updated frequently, rejecting the demand and supply of the various currencies. Occasionally the exchange rates satisfy the following property: there is a sequence of currencies ci1,ci2,.......ciksuch that ri1,ri2.i3,.........ri(k-1),ik,rik+1>1. This means that by starting with a unit of currency ci1and then successively converting it to currencies ci1,ci2.......cik, and finally back to ci1, you would end up with more than one unit of currency ci1 . Such anomalies Last only a fraction of a minute on the currency exchange, but they provide an opportunity for risk-free profits.

b. Give an efficientalgorithm for detecting the presence of such an anomaly. Use the graph representation you found above.

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.

Section 4.5.2 describes a way of storing a complete binary tree of n nodes in an array indexed by 1, 2, K, n .

(a) Consider the node at position j of the array. Show that its parent is at position [j2]and its children are at 2 jand 2 j + 1 (if these numbers are n).

(b) What the corresponding indices when a complete d-ary tree is stored in an array?

Figure 4.16 shows pseudocode for a binary heap, modeled on an exposition by R.E. Tarjan. The heap is stored as an array , which is assumed to support two constant-time operations:

  • |h|, which returns the number of elements currently in the array;
  • h-1, which returns the position of an element within the array.

The latter can always be achieved by maintaining the values of h-1as an auxiliary array.

(c) Show that themakeheapprocedure takesO(n) time when called on a set of elements. What is the worst-case input? (Hint:Start by showing that the running time is at most 1=1nlog(ni)).

(d) What needs to be changed to adapt this pseudocode to d-ary heaps?

Question: Prove that for the array prev computed by Dijkstra's algorithm, the edges {u,prepu}(forallv)form a 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