Find the shortest path from a to z
- Slides: 20
Find the shortest path from a to z 3 b 3 3 2 g d 2 1 h 6 a 3 z e 6 1 3 c 8 8 f 1 9 i 3
Label all vertices as ∞ and put vertex a in the vertex list. b 3 ∞ ∞ g d 3 2 2 ∞ a 6 8 9 f ∞ Vertex List: 1 ∞ 3 ∞ 1 3 8 1 h e 6 c ∞ 3 i 3 ∞ ∞ a: 0 b: ∞ c: ∞ d: ∞ e: ∞ f: ∞ g: ∞ h: ∞ i: ∞ z
Re-label all vertices that can be reached from a b 3 2(a) ∞ g d 3 2 2 6(a) a 6 8 9 f 3(a) Vertex List: 1 ∞ 3 ∞ 1 3 8 1 h e 6 c ∞ 3 i 3 ∞ ∞ a: 0 b: 2 c: 3 d: ∞ e: 6 f: ∞ g: ∞ h: ∞ i: ∞ z
Choose the unvisited vertex with the smallest label, in this case b. b 3 2(a) ∞ g d 3 2 2 6(a) a 6 8 9 f 3(a) Vertex List: 1 ∞ 3 ∞ 1 3 8 1 h e 6 c ∞ 3 i 3 ∞ ∞ a: 0 b: 2 c: 3 d: ∞ e: 6 f: ∞ g: ∞ h: ∞ i: ∞ z
Re-label all vertices that can be reached from b now. b 3 2(a) 5(a, b) g d 3 2 2 5(a, b) a 6 8 9 f 3(a) Vertex List: 1 ∞ 3 ∞ 1 3 8 1 h e 6 c ∞ 3 i 3 ∞ ∞ a: 0 b: 2 c: 3 d: 5 e: 6 5 f: ∞ g: ∞ h: ∞ i: ∞ z
Choose the unvisited vertex with the smallest label, now c. b 3 2(a) 5(a, b) g d 3 2 2 5(a, b) a 6 8 9 f 3(a) Vertex List: 1 ∞ 3 ∞ 1 3 8 1 h e 6 c ∞ 3 i 3 ∞ ∞ a: 0 b: 2 c: 3 d: 5 e: 5 f: ∞ g: ∞ h: ∞ i: ∞ z
Re-label, now including c b 3 2(a) 5(a, b) g d 3 2 2 5(a, b) a 6 8 9 f 3(a) Vertex List: 1 ∞ 3 ∞ 1 3 8 1 h e 6 c ∞ 3 i 3 4(a, c) ∞ a: 0 b: 2 c: 3 d: 5 e: 5 f: 4 g: ∞ h: ∞ i: ∞ z
Choose the smallest unvisited vertex, f b 3 2(a) 5(a, b) g d 3 2 2 5(a, b) a 6 8 9 f 3(a) Vertex List: 1 ∞ 3 ∞ 1 3 8 1 h e 6 c ∞ 3 i 3 4(a, c) ∞ a: 0 b: 2 c: 3 d: 5 e: 5 f: 4 g: ∞ h: ∞ i: ∞ z
Re-label, now using f b 3 2(a) 5(a, b) g d 3 2 2 5(a, b) a 6 8 9 f 3(a) Vertex List: 1 ∞ 3 12(a, c, f) 1 3 8 1 h e 6 c ∞ 3 i 3 4(a, c) 7(a, c, f) a: 0 b: 2 c: 3 d: 5 e: 5 f: 4 g: ∞ h: 12 i: 7 z: ∞ z
Smallest unvisited vertex is now d (alphabetical tie over e) b 3 2(a) 5(a, b) g d 3 2 2 5(a, b) a 6 8 9 f 3(a) Vertex List: 1 ∞ 3 12(a, c, f) 1 3 8 1 h e 6 c ∞ 3 i 3 4(a, c) 7(a, c, f) a: 0 b: 2 c: 3 d: 5 e: 5 f: 4 g: ∞ h: 12 i: 7 z: ∞ z
Re-label using d b 3 2(a) 5(a, b) g 2 5(a, b) a 6 8 9 f 3(a) Vertex List: 1 ∞ 3 12(a, c, f) 1 3 8 1 h e 6 c 8(a, b, d) d 3 2 3 i 3 4(a, c) 7(a, c, f) a: 0 b: 2 c: 3 d: 5 e: 5 f: 4 g: 8 h: 12 i: 7 z: ∞ z
Smallest unvisited vertex is now e b 3 2(a) 5(a, b) g 2 5(a, b) a 6 8 9 f 3(a) Vertex List: 1 ∞ 3 12(a, c, f) 1 3 8 1 h e 6 c 8(a, b, d) d 3 2 3 i 3 4(a, c) 7(a, c, f) a: 0 b: 2 c: 3 d: 5 e: 5 f: 4 g: 8 h: 12 i: 7 z: ∞ z
Re-label using e, but no vertex gets updated b 3 2(a) 5(a, b) g 2 5(a, b) a 6 8 9 f 3(a) Vertex List: 1 ∞ 3 12(a, c, f) 1 3 8 1 h e 6 c 8(a, b, d) d 3 2 3 i 3 4(a, c) 7(a, c, f) a: 0 b: 2 c: 3 d: 5 e: 5 f: 4 g: 8 h: 12 i: 7 z: ∞ z
Smallest unvisited vertex is i b 3 2(a) 5(a, b) g 2 5(a, b) a 6 8 9 f 3(a) Vertex List: 1 ∞ 3 12(a, c, f) 1 3 8 1 h e 6 c 8(a, b, d) d 3 2 3 i 3 4(a, c) 7(a, c, f) a: 0 b: 2 c: 3 d: 5 e: 5 f: 4 g: 8 h: 12 i: 7 z: ∞ z
Re-label using i b 3 2(a) 5(a, b) g 2 5(a, b) a 6 8 Vertex List: 1 16(a, c, f, i) z 9 f 3(a) 3 12(a, c, f) 1 3 8 1 h e 6 c 8(a, b, d) d 3 2 3 i 3 4(a, c) 7(a, c, f) a: 0 b: 2 c: 3 d: 5 e: 5 f: 4 g: 8 h: 12 i: 7 z: 16
Now, choose g b 3 2(a) 5(a, b) g 2 5(a, b) a 6 8 Vertex List: 1 16(a, c, f, i) z 9 f 3(a) 3 12(a, c, f) 1 3 8 1 h e 6 c 8(a, b, d) d 3 2 3 i 3 4(a, c) 7(a, c, f) a: 0 b: 2 c: 3 d: 5 e: 5 f: 4 g: 8 h: 12 i: 7 z: 16
Re-label, using g b 3 2(a) 5(a, b) g 2 5(a, b) a 6 8 Vertex List: 1 16(a, c, f, i) z 9 f 3(a) 3 9(a, b, d, g) 1 3 8 1 h e 6 c 8(a, b, d) d 3 2 3 i 3 4(a, c) 7(a, c, f) a: 0 b: 2 c: 3 d: 5 f: 4 g: 8 h: 12 9 i: 7 e: 5 z: 16
Now choose h b 3 2(a) 5(a, b) g 2 5(a, b) a 6 8 Vertex List: 1 16(a, c, f, i) z 9 f 3(a) 3 9(a, b, d, g) 1 3 8 1 h e 6 c 8(a, b, d) d 3 2 3 i 3 4(a, c) 7(a, c, f) a: 0 b: 2 c: 3 d: 5 e: 5 f: 4 g: 8 h: 9 i: 7 z: 16
Re-label using h b 3 2(a) 5(a, b) g 2 5(a, b) a 6 8 Vertex List: 1 12(a, b, d, g, h) z 9 f 3(a) 3 9(a, b, d, g) 1 3 8 1 h e 6 c 8(a, b, d) d 3 2 3 i 3 4(a, c) 7(a, c, f) a: 0 b: 2 c: 3 d: 5 e: 5 f: 4 g: 8 h: 9 i: 7 z: 16 12
No vertices left to consider, so we have the shortest path b 3 2(a) 5(a, b) g 2 5(a, b) a 6 8 Vertex List: 1 12(a, b, d, g, h) z 9 f 3(a) 3 9(a, b, d, g) 1 3 8 1 h e 6 c 8(a, b, d) d 3 2 3 i 3 4(a, c) 7(a, c, f) a: 0 b: 2 c: 3 d: 5 e: 5 f: 4 g: 8 h: 9 i: 7 z: 16 12
- Does dijkstra work with negative edges
- Find shortest path
- Dijkstra algorithm discrete mathematics
- What is shortest path algorithm in data structure
- Widest path problem dijkstra
- Successive shortest path algorithm
- Minimum spanning tree shortest path
- Shortest path problem excel
- Shortest path
- Dijkstra's shortest path algorithm pseudocode
- Shortest path
- Shortest path in weighted graph
- Augmenting paths
- Shortest path to get food
- Shortest path formulation
- Spf shortest path first
- Shortest path problem adalah
- Rbs shortest path
- Shortest path from source to destination in weighted graph
- Shortest path algorithm in mapreduce
- Shortest path problem linear programming