Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dijkstra’s Algorithm

Chen
November 17, 2022

Dijkstra’s Algorithm

Chen

November 17, 2022
Tweet

More Decks by Chen

Other Decks in Science

Transcript

  1. Dijkstra’s Algorithm Do Dijkstra’s on this graph, starting from A.

    Best distance to A: 0 All other nodes: 1 (so far, unreachable) 52 / 71
  2. Dijkstra’s Algorithm A is done. Choose shortest total distance (B

    at distance 3) From B, find a better path to C (3+3=6) Path to A is worse (3+3, worse than 0) 53 / 71
  3. Dijkstra’s Algorithm B is done. Choose shortest total distance (F

    at distance 4) Better path to E (4+5=9) Worse paths to A (4+4 vs 0) and D (4+2=6 vs 5) 54 / 71
  4. Dijkstra’s Algorithm F is done. Choose shortest total distance (D

    at distance 5) Better path for E (5+3 = 8 vs 9) Worse paths for other nodes 55 / 71
  5. Dijkstra’s Algorithm D is done. Choose shortest total distance (C

    at distance 6) Better path to E (6+1 = 7 vs 8) Worse paths to B and D 56 / 71
  6. Dijkstra’s Algorithm C is done. Choose shortest total distance (E

    at distance 7) Worse paths everywhere 57 / 71
  7. Dijkstra’s Algorithm All nodes are done. Note we could have

    recorded paths in table Also could stop early if we only wanted a single destination. 58 / 71