1 of 12

DAG SPT Algorithm

Visit vertices in topological order.

  • When we visit a vertex: relax all of its going edges.

# distTo edgeTo

0 0 -

1 ∞ -

2 ∞ -

3 ∞ -

4 ∞ -

5 ∞ -

1

3

2

4

5

0

s

4

2

6

1

1

2

3

1

Fringe: [0, 3, 1, 2, 4, 5]

0

2 of 12

DAG SPT Algorithm

Visit vertices in topological order.

  • When we visit a vertex: relax all of its going edges.

# distTo edgeTo

0 0 -

1 ∞ -

2 ∞ -

3 ∞ -

4 ∞ -

5 ∞ -

1

3

2

4

5

0

s

4

2

6

1

1

2

3

1

Fringe: [0, 3, 1, 2, 4, 5]

0

3 of 12

DAG SPT Algorithm

Visit vertices in topological order.

  • When we visit a vertex: relax all of its going edges.

# distTo edgeTo

0 0 -

1 2 0

2 ∞ -

3 2 0

4 ∞ -

5 ∞ -

1

3

2

4

5

0

s

4

2

6

1

1

2

3

1

Fringe: [3, 1, 2, 4, 5]

0

2

2

4 of 12

DAG SPT Algorithm

Visit vertices in topological order.

  • When we visit a vertex: relax all of its going edges.

# distTo edgeTo

0 0 -

1 2 0

2 ∞ -

3 2 0

4 ∞ -

5 ∞ -

1

3

2

4

5

0

s

4

2

6

1

1

2

3

1

Fringe: [1, 2, 4, 5]

0

2

2

5 of 12

DAG SPT Algorithm

Visit vertices in topological order.

  • When we visit a vertex: relax all of its going edges.

# distTo edgeTo

0 0 -

1 2 0

2 ∞ -

3 2 0

4 5 3

5 ∞ -

1

3

2

4

5

0

s

4

2

6

1

1

2

3

1

Fringe: [1, 2, 4, 5]

0

2

2

5

6 of 12

DAG SPT Algorithm

Visit vertices in topological order.

  • When we visit a vertex: relax all of its going edges.

# distTo edgeTo

0 0 -

1 2 0

2 ∞ -

3 2 0

4 5 3

5 ∞ -

1

3

2

4

5

0

s

4

2

6

1

1

2

3

1

Fringe: [2, 4, 5]

0

2

2

5

7 of 12

DAG SPT Algorithm

Visit vertices in topological order.

  • When we visit a vertex: relax all of its going edges.

# distTo edgeTo

0 0 -

1 2 0

2 8 1

3 2 0

4 5 3

5 ∞ -

1

3

2

4

5

0

s

4

2

6

1

1

2

3

1

Fringe: [2, 4, 5]

0

2

2

5

8

8 of 12

DAG SPT Algorithm

Visit vertices in topological order.

  • When we visit a vertex: relax all of its going edges.

# distTo edgeTo

0 0 -

1 2 0

2 8 1

3 2 0

4 5 3

5 ∞ -

1

3

2

4

5

0

s

4

2

6

1

1

2

3

1

Fringe: [4, 5]

0

2

2

5

8

9 of 12

DAG SPT Algorithm

Visit vertices in topological order.

  • When we visit a vertex: relax all of its going edges.

# distTo edgeTo

0 0 -

1 2 0

2 8 1

3 2 0

4 5 3

5 9 2

1

3

2

4

5

0

s

4

2

6

1

1

2

3

1

Fringe: [4, 5]

0

2

2

5

8

9

10 of 12

DAG SPT Algorithm

Visit vertices in topological order.

  • When we visit a vertex: relax all of its going edges.

# distTo edgeTo

0 0 -

1 2 0

2 8 1

3 2 0

4 5 3

5 9 2

1

3

2

4

5

0

s

4

2

6

1

1

2

3

1

Fringe: [5]

0

2

2

5

8

9

11 of 12

DAG SPT Algorithm

Visit vertices in topological order.

  • When we visit a vertex: relax all of its going edges.

# distTo edgeTo

0 0 -

1 2 0

2 8 1

3 2 0

4 5 3

5 6 4

1

3

2

4

5

0

s

4

2

6

1

1

2

3

1

Fringe: [5]

0

2

2

5

8

9

6

12 of 12

DAG SPT Algorithm

Visit vertices in topological order.

  • When we visit a vertex: relax all of its going edges.

# distTo edgeTo

0 0 -

1 2 0

2 8 1

3 2 0

4 5 3

5 6 4

1

3

2

4

5

0

s

4

2

6

1

1

2

3

1

Fringe: []

0

2

2

5

8

6