09 B: Graph Algorithms II CS1102S: Data Structures and Algorithms - - PowerPoint PPT Presentation

09 b graph algorithms ii
SMART_READER_LITE
LIVE PREVIEW

09 B: Graph Algorithms II CS1102S: Data Structures and Algorithms - - PowerPoint PPT Presentation

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstras Algorithm Correctness and Complexity of Dijkstras Algorithm 09 B: Graph Algorithms II CS1102S: Data Structures and Algorithms Martin Henz March 19, 2010 Generated on


slide-1
SLIDE 1

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

09 B: Graph Algorithms II

CS1102S: Data Structures and Algorithms

Martin Henz

March 19, 2010

Generated on Thursday 18th March, 2010, 00:21 CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 1

slide-2
SLIDE 2

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

1

Review: Graphs, Shortest Path

2

Unweighted Shortest Paths

3

Dijkstra’s Algorithm

4

Correctness and Complexity of Dijkstra’s Algorithm

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 2

slide-3
SLIDE 3

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

1

Review: Graphs, Shortest Path

2

Unweighted Shortest Paths

3

Dijkstra’s Algorithm

4

Correctness and Complexity of Dijkstra’s Algorithm

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 3

slide-4
SLIDE 4

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

Graph, Vertices, Edges

Graph A graph G = (V, E) consists of a set of vertices, V, and a set of edges, E.

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 4

slide-5
SLIDE 5

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

Graph, Vertices, Edges

Graph A graph G = (V, E) consists of a set of vertices, V, and a set of edges, E. Edge Each edge is a pair (v, w), where v, w ∈ V.

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 5

slide-6
SLIDE 6

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

Graph, Vertices, Edges

Graph A graph G = (V, E) consists of a set of vertices, V, and a set of edges, E. Edge Each edge is a pair (v, w), where v, w ∈ V. Directed graph If the pairs are ordered, then the graph is directed.

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 6

slide-7
SLIDE 7

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

Graph, Vertices, Edges

Graph A graph G = (V, E) consists of a set of vertices, V, and a set of edges, E. Edge Each edge is a pair (v, w), where v, w ∈ V. Directed graph If the pairs are ordered, then the graph is directed. Weight Sometimes the edges have a third component, knows as either a weight or a cost. Such graphs are called weighted graphs.

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 7

slide-8
SLIDE 8

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

Paths

Path A path in a graph is a sequence of vertices w1, w2, w3, . . . , wN such that (wi, wi+1) ∈ E for 1 ≤ i < N. It is said to lead from w1

  • t wN.

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 8

slide-9
SLIDE 9

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

The Shortest Path Problem

Input Weighted graph: associated with each edge (vi, vj) is a cost ci,j to traverse the edge.

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 9

slide-10
SLIDE 10

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

The Shortest Path Problem

Input Weighted graph: associated with each edge (vi, vj) is a cost ci,j to traverse the edge. Weighted path length Cost of path v1v2 · · · vN is N−1

i=1 ci,i+1.

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 10

slide-11
SLIDE 11

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

Single-Source Shortest-Path Problem

Problem Given as input a weighted graph, G = (V, E), and a distinguished vertex, s, find the shortest weighted path from s to every other vertex in G.

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 11

slide-12
SLIDE 12

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

Example

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 12

slide-13
SLIDE 13

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

Example

Shortest path from v1 to v6

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 13

slide-14
SLIDE 14

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

Example

Shortest path from v1 to v6 has a cost of 6 and goes from v1 to v4 to v7 to v6.

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 14

slide-15
SLIDE 15

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

Unweighted Shortest Paths: Example

Find the shortest path from v3 to all other vertices

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 15

slide-16
SLIDE 16

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

Idea

Level-order traversal Start with s (distance 0) and proceed in phases currDist, each time going through all vertices. If vertex is “known” and has distance currDist, set the distance of its neighbors to currDist+1.

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 16

slide-17
SLIDE 17

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

Implementation

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 17

slide-18
SLIDE 18

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

Inefficiency

Careless loop In each phase, we go through all vertices. We can remember the “known” vertices in a data structure.

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 18

slide-19
SLIDE 19

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

Inefficiency

Careless loop In each phase, we go through all vertices. We can remember the “known” vertices in a data structure. Suitable data structure Queue: will contain the vertices in order of increasing distance

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 19

slide-20
SLIDE 20

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

Implementation

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 20

slide-21
SLIDE 21

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

Dijkstra’s Algorithm: Idea

Idea Treat nodes in the order of shortest distance

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 21

slide-22
SLIDE 22

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

Dijkstra’s Algorithm: Idea

Idea Treat nodes in the order of shortest distance

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 22

slide-23
SLIDE 23

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

Example

Initial configuration:

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 23

slide-24
SLIDE 24

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

Example

After v1 is declared known:

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 24

slide-25
SLIDE 25

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

Example

After v4 is declared known:

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 25

slide-26
SLIDE 26

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

Example

After v2 is declared known:

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 26

slide-27
SLIDE 27

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

Example

After v5 and then v3 are declared known:

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 27

slide-28
SLIDE 28

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

Example

After v7 is declared known:

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 28

slide-29
SLIDE 29

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

Example

After v6 is declared known:

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 29

slide-30
SLIDE 30

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm

Pseudocode for Dijkstra’s Algorithm

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 30

slide-31
SLIDE 31

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

Shortest Subpath

Lemma Any subpath of a shortest path must also be a shortest path.

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 31

slide-32
SLIDE 32

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

Shortest Subpath

Lemma Any subpath of a shortest path must also be a shortest path. Proof By contradiction: Assume that a subpath p = vi · · · vj of the shortest path q = v1 · · · p · · · vk is not a shortest path. Then there is a shorter path p′ from vi to vj. Plug p′ into q to get q′ = v1 · · · p′ · · · vk shorter than q!

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 32

slide-33
SLIDE 33

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

Definition of Shortest Distance

Notation We use the notation δ(v, w) to denote the length of the shortest path from v to w.

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 33

slide-34
SLIDE 34

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

Definition of Shortest Distance

Notation We use the notation δ(v, w) to denote the length of the shortest path from v to w. Distance We call δ(v, w) the distance between v and w.

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 34

slide-35
SLIDE 35

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

dist is a Relaxation

Lemma At any point in time and for any vertex v, we have v . dist ≥ δ(s, v)

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 35

slide-36
SLIDE 36

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

dist is a Relaxation

Lemma At any point in time and for any vertex v, we have v . dist ≥ δ(s, v) Proof Idea We show this by proving that whenever we set v . dist to a finite value, there exists a path of that length.

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 36

slide-37
SLIDE 37

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

dist is a Relaxation

Lemma At any point in time and for any vertex v, we have v . dist ≥ δ(s, v)

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 37

slide-38
SLIDE 38

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

dist is a Relaxation

Lemma At any point in time and for any vertex v, we have v . dist ≥ δ(s, v) Proof By induction over the number of iterations of outer loop.

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 38

slide-39
SLIDE 39

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

dist is a Relaxation

Lemma At any point in time and for any vertex v, we have v . dist ≥ δ(s, v) Proof By induction over the number of iterations of outer loop. Start: claim holds for s (distance 0) and all other vertices (distance ∞)

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 39

slide-40
SLIDE 40

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

dist is a Relaxation

Lemma At any point in time and for any vertex v, we have v . dist ≥ δ(s, v) Proof By induction over the number of iterations of outer loop. Start: claim holds for s (distance 0) and all other vertices (distance ∞) Hypothesis: claim holds for previous iterations.

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 40

slide-41
SLIDE 41

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

dist is a Relaxation

Lemma At any point in time and for any vertex v, we have v . dist ≥ δ(s, v) Proof By induction over the number of iterations of outer loop. Start: claim holds for s (distance 0) and all other vertices (distance ∞) Hypothesis: claim holds for previous iterations. Induction step: Updates are done such that an edge weight is added to a previously computed dist value

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 41

slide-42
SLIDE 42

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

Order of Adding Vertices

Observation Vertices are becoming known in order of increasing dist values.

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 42

slide-43
SLIDE 43

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

Order of Adding Vertices

Observation Vertices are becoming known in order of increasing dist values. Observation Once a vertex becomes known, its dist value does not change.

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 43

slide-44
SLIDE 44

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

Correctness of Dijkstra’s Algorithm

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 44

slide-45
SLIDE 45

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

Main Correctness Lemma

Lemma When we set v.known = true then v. dist= δ(s, v).

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 45

slide-46
SLIDE 46

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

Main Correctness Lemma

Lemma When we set v.known = true then v. dist= δ(s, v). Correctness of Dijkstra’s algorithm Each iteration through the outer loop makes one vertex known. At the end every vertex v is known and thus, according to the lemma, its dist value is δ(s, v).

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 46

slide-47
SLIDE 47

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

Proving the Main Lemma

Proof by contradiction Assume that there is a vertex v for which the claim does not hold.

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 47

slide-48
SLIDE 48

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

Proving the Main Lemma

Proof by contradiction Assume that there is a vertex v for which the claim does not hold. Therefore, using relaxation property, when we set v .known = true then v . dist > δ(s, v).

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 48

slide-49
SLIDE 49

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

Proving the Main Lemma

Proof by contradiction Assume that there is a vertex v for which the claim does not hold. Therefore, using relaxation property, when we set v .known = true then v . dist > δ(s, v). Then, there must be a vertex u for which this is the case for the first time in the algorithm.

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 49

slide-50
SLIDE 50

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

Situation

Analysis Situation just before u.known = true: The value u. dist reflects the length of the path given by u.path.

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 50

slide-51
SLIDE 51

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

Situation

Analysis Situation just before u.known = true: The value u. dist reflects the length of the path given by u.path. The real shortest path The real shortest path from s to u is shorter than u. dist. Consider the real shortest path s · · · u.

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 51

slide-52
SLIDE 52

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

Situation

Jumping into “unknown” Since u.known still false, and s.known=true, there must be a pair of two neighboring vertices r and t in the real shortest path such that r .known=true and t .known=false. First pair There must be a first pair x and y where this is the case.

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 52

slide-53
SLIDE 53

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

Analysis of x and y

Processing of x We have processed x, but not yet y. Since y’s dist value is decreased by decrease(...), we know that y . dist ≤ x . dist+cx,y

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 53

slide-54
SLIDE 54

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

Analysis of x and y

Processing of x We have processed x, but not yet y. Since y’s dist value is decreased by decrease(...), we know that y . dist ≤ x . dist+cx,y Using hypothesis Since x becomes known earlier than u, we have x . dist= δ(s, x)

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 54

slide-55
SLIDE 55

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

Analysis of x and y

Processing of x We have processed x, but not yet y. Since y’s dist value is decreased by decrease(...), we know that y . dist ≤ x . dist+cx,y Using hypothesis Since x becomes known earlier than u, we have x . dist= δ(s, x) Shortest subpath s · · · xy is subpath of shortest path, thus δ(s, y) = δ(s, x) + cx,y = x . dist+cx,y

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 55

slide-56
SLIDE 56

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

Recap

We have y . dist ≤ x . dist+cx,y and δ(s, y) = δ(s, x) + cx,y = x . dist+cx,y

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 56

slide-57
SLIDE 57

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

Recap

We have y . dist ≤ x . dist+cx,y and δ(s, y) = δ(s, x) + cx,y = x . dist+cx,y and thus: y . dist ≤ δ(s, y)

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 57

slide-58
SLIDE 58

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

Recap

We have y . dist ≤ x . dist+cx,y and δ(s, y) = δ(s, x) + cx,y = x . dist+cx,y and thus: y . dist ≤ δ(s, y) and therefore y . dist = δ(s, y)

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 58

slide-59
SLIDE 59

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

Finale

Since y . dist = δ(s, y), we have y = u.

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 59

slide-60
SLIDE 60

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

Finale

Since y . dist = δ(s, y), we have y = u. Edge costs between y and u are non-negative, thus δ(s, y) ≤ δ(s, u) and thus y . dist= δ(s, y) ≤ δ(s, u) < u. dist

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 60

slide-61
SLIDE 61

Review: Graphs, Shortest Path Unweighted Shortest Paths Dijkstra’s Algorithm Correctness and Complexity of Dijkstra’s Algorithm Correctness of Dijkstra’s Algorithm

Finale

Since y . dist = δ(s, y), we have y = u. Edge costs between y and u are non-negative, thus δ(s, y) ≤ δ(s, u) and thus y . dist= δ(s, y) ≤ δ(s, u) < u. dist If y . dist< u. dist, and since vertices become known in order of increasing distance, y would have become known before u, which contradicts the assumption that u is next vertex to become known!

CS1102S: Data Structures and Algorithms 09 B: Graph Algorithms II 61