5.
a.
The source vertex is A.
The Dijkstra algorithm is applied as follows :
Initialization : Let d[v] represent the initial distance which is the shortest from source vertex A. So, initially, d[v] = ∞ for all vertices other than A and d[A] is initially 0.
Initialize a queue that will contain all the vertices along with their distances.
The queue is :
Vertex | A | B | C | D | E | F | G |
Distance | 0 | ∞ | ∞ | ∞ | ∞ | ∞ | ∞ |
Initialize an empty set S.
Step 1 :
Perform relaxation on the edges adjacent to vertex A.
For the edge AB,
d[B] > d[A] + wt[AB] is True.
d[B] = d[A] + wt[AB] = 0 + 12 = 12.
For the edge AC,
d[C] > d[A] + wt[AC] is True.
d[C] = d[A] + wt[AC] = 0 + 9 = 9
For the edge AD,
d[D] > d[A] + wt[AD] is True.
d[D] = d[A] + wt[AD] = 0 + 17 = 17
The queue is updated as :
Vertex | B | C | D | E | F | G | |
Distance | 12 | 9 | 17 | ∞ | ∞ | ∞ |
The table for the algorithm becomes :
Node | Initial Distance | Distance | Predecessor |
A | 0 | 0 | |
B | ∞ | 12 | A |
C | ∞ | 9 | A |
D | ∞ | 17 | A |
E | ∞ | ∞ | |
F | ∞ | ∞ | |
G | ∞ | ∞ |
Step 2 :
Perform relaxation on the edges adjacent to vertex C.
For the edge CD,
d[D] > d[C] + wt[CD] is True.
d[D] = d[C] + wt[CD] = 9 + 7 = 16
For the edge CF,
d[F] > d[C] + wt[CF] is True.
d[F] = d[C] + wt[CF] = 9 + 8 = 17
The queue is updated as :
Vertex | B | D | E | F | G | ||
Distance | 12 | 16 | ∞ | 17 | ∞ |
The table for the algorithm becomes :
Node | Initial Distance | Distance | Predecessor |
A | 0 | 0 | |
B | ∞ | 12 | A |
C | ∞ | 9 | A |
D | ∞ | 16 | C |
E | ∞ | ∞ | |
F | ∞ | 17 | C |
G | ∞ | ∞ |
Step 3 :
Perform relaxation on the edges adjacent to vertex B.
For the edge BD,
d[D] > d[B] + wt[BD] is False.
d[D] = 16
For the edge BE,
d[E] > d[B] + wt[BE] is True.
d[E] = d[B] + wt[BE] = 12 + 10 = 22
The queue is updated as :
Vertex | D | E | F | G | |||
Distance | 16 | 22 | 17 | ∞ |
The table for the algorithm becomes :
Node | Initial Distance | Distance | Predecessor |
A | 0 | 0 | |
B | ∞ | 12 | A |
C | ∞ | 9 | A |
D | ∞ | 16 | C |
E | ∞ | 22 | B |
F | ∞ | 17 | C |
G | ∞ | ∞ |
Step 4 :
Perform relaxation on the edges adjacent to vertex D.
For the edge DE,
d[E] > d[D] + wt[DE] is True.
d[E] = d[D] + wt[DE] = 16 + 2 = 18
For the edge DF,
d[F] > d[D] + wt[DF] is False.
d[F] = 17
The queue is updated as :
Vertex | E | F | G | ||||
Distance | 18 | 17 | ∞ |
The table for the algorithm becomes :
Node | Initial Distance | Distance | Predecessor |
A | 0 | 0 | |
B | ∞ | 12 | A |
C | ∞ | 9 | A |
D | ∞ | 16 | C |
E | ∞ | 18 | D |
F | ∞ | 17 | C |
G | ∞ | ∞ |
Step 5 :
Perform relaxation on the edges adjacent to vertex F.
For the edge FG,
d[G] > d[F] + wt[FG] is True.
d[G] = 17 + 3 = 20.
The queue is updated as :
Vertex | E | G | |||||
Distance | 18 | 20 |
The table for the algorithm becomes :
Node | Initial Distance | Distance | Predecessor |
A | 0 | 0 | |
B | ∞ | 12 | A |
C | ∞ | 9 | A |
D | ∞ | 16 | C |
E | ∞ | 18 | D |
F | ∞ | 17 | C |
G | ∞ | 20 | F |
Step 6 :
Perform relaxation on the edges adjacent to vertex E.
For the edge EG,
d[G] > d[E] + wt[EG] is False.
d[G] = 20
The queue is updated as :
Vertex | G | ||||||
Distance | 20 |
The table for the algorithm becomes :
Node | Initial Distance | Distance | Predecessor |
A | 0 | 0 | |
B | ∞ | 12 | A |
C | ∞ | 9 | A |
D | ∞ | 16 | C |
E | ∞ | 18 | D |
F | ∞ | 17 | C |
G | ∞ | 20 | F |
Step 7 :
But vertex G has no such adjacent edges such that the the other vertex is unvisited.
The queue is updated as :
Vertex | |||||||
Distance |
The table for the algorithm becomes :
Node | Initial Distance | Distance | Predecessor |
A | 0 | 0 | |
B | ∞ | 12 | A |
C | ∞ | 9 | A |
D | ∞ | 16 | C |
E | ∞ | 18 | D |
F | ∞ | 17 | C |
G | ∞ | 20 | F |
So, the final completed table for the single source shortest path algorithm using Dijkstra algorithm is :
Node | Initial Distance | Distance | Predecessor |
A | 0 | 0 | |
B | ∞ | 12 | A |
C | ∞ | 9 | A |
D | ∞ | 16 | C |
E | ∞ | 18 | D |
F | ∞ | 17 | C |
G | ∞ | 20 | F |
b.
The shortest path from A to E is :
A ------> C ---------> D ----------> E
The length of the path is 18.
c.
The shortest path from A to F is :
A -------> C --------> F
The length of the path is 17.
d.
The shortest path from A to G is :
A -------> C --------> F ---------> G
The length of the path is 20.
5. Apply Dijkstra's algorithm as discussed in class to solve the single-source shortest-paths problem for the...
Apply Dijkstra's algorithm as discussed in class to solve the single-source shortest-paths problem for the following graph. Consider node A to be the source. (20 points) a. Show the completed table. b. State the shortest path from A to E and state its length. State the shortest path from A to F A 9 and state its length. d. State the shortest path from A to G 17 and state its length. 7 C. 12 B 8 10 D 8...
2. Apply Dijkstra’s algorithm as discussed in class to solve the single-source shortest-paths problem for the following graph. Consider node a to be the source. (10 points) a. Show the completed table. b. State the shortest path from A to J and state its length. c. State the shortest path from A to K and state its length. d. State the shortest path from A to L and state its length. 3 5 6 4 3 2 1 2. d...
Consider the problem of finding the shortest paths in a weighted directed graph using Dijkstra's algorithm. Denote the set of vertices as V, the number of vertices as |V|, the set of edges as E, and the number of edges as |E|. Answer the following questions.Below is a pseudo-code of the algorithm that computes the length c[v] of the shortest path from the start node s to each node v. Answer code to fill in the blank _______ .
show that the single-source shortest paths constructed by dijkstra's algorithm on a connected undirected graph from a spinning tree
5. How would you adapt Dijkstra’s algorithm to solve the single-destination shortest paths problem? In other words, find the shortest path from each node to a single destination node. Consider this question for both (a) undirected and (b) directed graphs.
Consider the network shown below. Use Dijkstra's algorithm to find the shortest paths from node a to all other nodes. Enter your answers in the a shortest path answers in the following format: node-node-node. For example, if the ssignment link. Enter the shortest path from a to c is through node b, you would enter the answer as: a-b-c 3 5 6 6
2. (a) (2 points - Completeness) Dijkstra's Walk-through Dijkstra's algorithm to compute the shortest paths from A to every other node in the given graph Show your steps in the table below. Do this by crossing out old values and writing in new ones as the algorithm proceeds 25 9 7 (D-G) 19 14 (B-E) 4 (A-C) 2 2 (G-H) Vertex Visited Cost Previous (b) (6 points-Correctness) All Vertices, in Order Visited: Visited-= Found the Shortest Path to) (c) (2...
Dijkstra's Algorithm: Perform Dijkstra's on the following graph a. You must start at a - since this is a single source shortest path algorithm b. You must show the state of the priority queue before each addition to the path c. Indicate on the graph the paths (circle edges part of a path)
Algorithm Question 5. Below is a graph with edge lengths. Apply Dijkstra's algorithm to find the shortest paths, starting at vertex A, to all other vertices. Write down the sequence in which the edges are chosen, breaking ties by using vertices at the same length in alphabetic orde. 3 Ga 2 5. Below is a graph with edge lengths. Apply Dijkstra's algorithm to find the shortest paths, starting at vertex A, to all other vertices. Write down the sequence in...
Question 5 (5 points) Apply Dijkstra's Algorithm to the following graph, computing the shortest path for al vertices from vertex A. Present the results after each vertex has been processed 3 20 B 47 20 You may wish to present the results in the format of the following table: Stage Current Vertex Labels and Distances A 0 A 0 D 231 A 213 E 4 F21 A 90 Each row states (a) the current stage, (b) the vertex just added...