- 2075 Bhadra · 8 marks
Dijkstra shortest path (2075 Bhadra)
Short answer
Using Dijkstra's algorithm, the shortest distances from A are: B=10, C=12, D=10, E=11, F=8, G=5, H=8. The paths are A–B, A–H–C, A–G–F–D, A–G–F–E or A–G–F–D–E, A–G–F, A–G, and A–H respectively.
Use Dijkstra's algorithm to find the length of a shortest path from the vertices A to other in the graph below. [Figure: weighted undirected graph on vertices A, B, C, D, E, F, G, H with edges A-B 10, A-G 5, A-H 8, B-C 3, B-H 4, B-D 6, C-H 4, C-D 3, G-H 4, G-F 3, H-F 10, H-E 4, H-D 9, F-D 2, F-E 3, E-D 1; edge readings approximate from scan]
Dijkstra's algorithm (non-negative weights) labels every vertex with the best distance known so far and fixes one vertex at a time:
- Give the source distance 0 and every other vertex ∞. All vertices are temporary.
- Make the temporary vertex with the smallest label permanent.
- For each temporary neighbour v of the new permanent vertex u: if d(u) + w(u,v) < d(v), set d(v) = d(u) + w(u,v) and record u as predecessor.
- Repeat steps 2 and 3 until the target (or all vertices) is permanent.
Graph as read
The figure is read with the edge weights listed below (the scan is approximate). Source is A; distances to all other vertices are required.
Edges: A–B 10, A–G 5, A–H 8, B–C 3, B–H 4, B–D 6, C–H 4, C–D 3, G–H 4, G–F 3, H–F 10, H–E 4, H–D 9, F–D 2, F–E 3, E–D 1.
Trace
Each cell shows label = distance(predecessor). Bold marks the vertex made permanent in that step; ✓ means already permanent.
| Step | Fixed | A | B | C | D | E | F | G | H |
|---|---|---|---|---|---|---|---|---|---|
| 1 | A | 0 | 10(A) | ∞ | ∞ | ∞ | ∞ | 5(A) | 8(A) |
| 2 | G | ✓ | 10(A) | ∞ | ∞ | ∞ | 8(G) | 5(A) | 8(A) |
| 3 | F | ✓ | 10(A) | ∞ | 10(F) | 11(F) | 8(G) | ✓ | 8(A) |
| 4 | H | ✓ | 10(A) | 12(H) | 10(F) | 11(F) | ✓ | ✓ | 8(A) |
| 5 | B | ✓ | 10(A) | 12(H) | 10(F) | 11(F) | ✓ | ✓ | ✓ |
| 6 | D | ✓ | ✓ | 12(H) | 10(F) | 11(F) | ✓ | ✓ | ✓ |
| 7 | E | ✓ | ✓ | 12(H) | ✓ | 11(F) | ✓ | ✓ | ✓ |
| 8 | C | ✓ | ✓ | 12(H) | ✓ | ✓ | ✓ | ✓ | ✓ |
Result
| Vertex | Shortest distance from A | Shortest path |
|---|---|---|
| B | 10 | A–B |
| C | 12 | A–H–C |
| D | 10 | A–G–F–D |
| E | 11 | A–G–F–D–E or A–G–F–E |
| F | 8 | A–G–F |
| G | 5 | A–G |
| H | 8 | A–H |
Answer: shortest distances from A: B = 10, C = 12, D = 10, E = 11, F = 8, G = 5, H = 8. (E has two shortest paths of length 11: A–G–F–E and A–G–F–D–E.)
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Dijkstra shortest path (2074 Bhadra) · Discrete Structure, chapter 4
- Dijkstra shortest path (2068 Bhadra) · Discrete Structure, chapter 4 · asked 4×
- Dijkstra shortest path (2071 Bhadra) · Discrete Structure, chapter 4 · asked 4×
- Dijkstra shortest path (2069 Bhadra) · Discrete Structure, chapter 4 · asked 4×
- Dijkstra shortest path (2070 Magh) · Discrete Structure, chapter 4 · asked 4×
- Dijkstra shortest path (2072 Asoj) · Discrete Structure, chapter 4
- Dijkstra's shortest path algorithm · Data Structure and Algorithm, chapter 10 · asked 2×
- Dijkstra's shortest paths from source F · Data Structure and Algorithm, chapter 10