0% found this document useful (0 votes)
21 views2 pages

Dijkstra Solution

The document outlines the steps to find the shortest path from Node 1 to Node 4 using Dijkstra's Algorithm on a graph with 7 nodes and weighted edges. It details the initialization of distances, the iterative processing of nodes, and updates to the distance table. The shortest path identified is 1 -> 2 -> 3 -> 4 with a total distance of 32.

Uploaded by

t3948162
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

Dijkstra Solution

The document outlines the steps to find the shortest path from Node 1 to Node 4 using Dijkstra's Algorithm on a graph with 7 nodes and weighted edges. It details the initialization of distances, the iterative processing of nodes, and updates to the distance table. The shortest path identified is 1 -> 2 -> 3 -> 4 with a total distance of 32.

Uploaded by

t3948162
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Dijkstra's Algorithm - Shortest Path Solution

Find the shortest path from Node 1 to Node 4 using Dijkstra's Algorithm.

Step 1: Graph Representation


The graph consists of 7 nodes with the following weighted edges:

(1 -> 2) = 7, (1 -> 3) = 12, (2 -> 3) = 14, (2 -> 7) = 10, (3 -> 5) = 1,


(3 -> 4) = 5, (4 -> 5) = 2, (5 -> 6) = 4, (6 -> 7) = 12, (7 -> 1) = 8, (7 -> 6) = 6

Step 2: Initialization
- Set the distance of Node 1 to 0 (starting point).
- Set the distance of all other nodes to INF (infinity).

Initial Distance Table:


Node Distance from Node 1 Previous Node
1 0 -
2 INF -
3 INF -
4 INF -
5 INF -
6 INF -
7 INF -

Step 3: Processing Nodes Using Dijkstra's Algorithm

Iteration 1: Process Node 1


- Update neighbors:
- Node 2: Distance = min(INF, 0+7) = 7
- Node 3: Distance = min(INF, 0+12) = 12

Iteration 2: Process Node 2 (smallest distance: 7)


- Update neighbors:
- Node 3: Distance remains 12 (no update)
- Node 7: Distance = min(INF, 7+10) = 17

Iteration 3: Process Node 3 (smallest distance: 12)


- Update neighbors:
- Node 5: Distance = min(INF, 12+1) = 13
- Node 4: Distance = min(INF, 12+5) = 17

Iteration 4: Process Node 5 (smallest distance: 13)


- Update neighbors:
- Node 6: Distance = min(INF, 13+4) = 17
Iteration 5: Process Node 4 (smallest distance: 17)
- No further updates required.

Final Distance Table:


Node Distance from Node 1
1 0
2 7
3 12
4 32
5 13
6 17
7 17

Shortest path from Node 1 to Node 4: 1 -> 2 -> 3 -> 4 with total distance = 32

You might also like