🖨️ Printing Instructions: Press Ctrl/Cmd + P and select "Save as PDF".
1

Dijkstra's Algorithm

2

Learning Goals

3

The Shortest Path Problem

4

Goal

5

Shortest Path Variants

6

Optimal Substructure

7

Relaxation

8

Interactive Demo

9

The Core Operation

10

Relax(u, v, w)

if d[v] > d[u] + w(u, v)
  d[v] = d[u] + w(u, v)
  pi[v] = u
11

Properties of Relaxation

12

Dijkstra's Algorithm

13

Interactive Demo

14

Greedy Strategy

15

Dijkstra(G, s)

Init-Single-Source(G, s) // d[s]=0, others inf
S = empty
Q = V // Min-Priority Queue keyed by d[]
while Q not empty
  u = Extract-Min(Q)
  S = S U {u}
  for each v in Adj[u]
    Relax(u, v, w)
16

Example Trace

17

Similarity to Prim's MST

18

Analysis

19

Complexity

20

Correctness Proof

21

Theorem

22

Proof Sketch (Loop Invariant)

23

Limitations & Negative Edges

24

Interactive Demo

25

Why Dijkstra Fails with Negatives

26

Negative Cycles

27

Path Reconstruction

28

Building the Actual Path

29

Common Pitfalls

30

Watch Out For...

31

All Interactive Demos

32

Lecture Summary

33

Supplementary Resources