CS 225 Data Structures Dec Decem ember er 2 2 Di Dijkstras Al - - PowerPoint PPT Presentation

cs 225
SMART_READER_LITE
LIVE PREVIEW

CS 225 Data Structures Dec Decem ember er 2 2 Di Dijkstras Al - - PowerPoint PPT Presentation

CS 225 Data Structures Dec Decem ember er 2 2 Di Dijkstras Al Algorihtm G G Carl Evans Gr Grap aphs To study all of these structures: 1. A common vocabulary 2. Graph implementations 3. Graph traversals 4. Graph algorithms


slide-1
SLIDE 1

CS 225

Data Structures

Dec Decem ember er 2 2 – Di Dijkstra’s Al Algorihtm

G G Carl Evans

slide-2
SLIDE 2

Gr Grap aphs

To study all of these structures:

  • 1. A common vocabulary
  • 2. Graph implementations
  • 3. Graph traversals
  • 4. Graph algorithms
slide-3
SLIDE 3

MS MST Algori

  • rithm

m Ru Runtime me:

We know that MSTs are always run on a minimally connected graph: n-1 ≤ m ≤ n(n-1) / 2 O(n) ≤ O(m) ≤ O(n2)

slide-4
SLIDE 4

MS MST Algori

  • rithm

m Ru Runtime me:

  • Kruskal’s Algorithm:

O(n + m lg(n))

Sparse Graph: Dense Graph:

  • Prim’s Algorithm:

O(n lg(n) + m lg(n))

Sparse Graph: Dense Graph:

slide-5
SLIDE 5

Su Suppos

  • se I

I h have a a n new h heap:

PrimMST(G, s): foreach (Vertex v : G): d[v] = +inf p[v] = NULL d[s] = 0 PriorityQueue Q // min distance, defined by d[v] Q.buildHeap(G.vertices()) Graph T // "labeled set" repeat n times: Vertex m = Q.removeMin() T.add(m) foreach (Vertex v : neighbors of m not in T): if cost(v, m) < d[v]: d[v] = cost(v, m) p[v] = m 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

Binary Heap Fibonacci Heap Remove Min O( lg(n) ) O( lg(n) ) Decrease Key O( lg(n) ) O(1)*

What’s the updated running time?

slide-6
SLIDE 6

MS MST Al Algorithm Ru Runtime mes:

  • Kruskal’s Algorithm:

O(m lg(n))

  • Prim’s Algorithm:

O(n lg(n) + m lg(n))

slide-7
SLIDE 7

Final Final Big ig-O O MST Al Algorithm Ru Runtime mes:

  • Kruskal’s Algorithm:

O(m lg(n))

  • Prim’s Algorithm:

O(n lg(n) + m)

slide-8
SLIDE 8

0.00% 10.00% 20.00% 30.00% 40.00% 50.00% 60.00% 70.00% 80.00% 90.00% 100.00% 0.00% 10.00% 20.00% 30.00% 40.00% 50.00% 60.00% 70.00% 80.00% 90.00% 100.00%

Students Course Grade (of 735) w/o EC

Post Break Grade CDF

slide-9
SLIDE 9

MP MP7

Extra Credit: Due Tomorrow! (+7 points!)

slide-10
SLIDE 10

Sh Short

  • rtest P

Path

slide-11
SLIDE 11

Di Dijkstra’ a’s A Algorithm ( (SSSP) P)

A C D E B F G H 7 5 4 10 7 5 3 6 2 5 4 3

DijkstraSSSP(G, s): foreach (Vertex v : G): d[v] = +inf p[v] = NULL d[s] = 0 PriorityQueue Q // min distance, defined by d[v] Q.buildHeap(G.vertices()) Graph T // "labeled set" repeat n times: Vertex u = Q.removeMin() T.add(u) foreach (Vertex v : neighbors of u not in T): if _______________ < d[v]: d[v] = __________________ p[v] = m 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

slide-12
SLIDE 12

Di Dijkstra’ a’s A Algorithm ( (SSSP) P)

A C D E B F G H 7 5 4 10 7

  • 5

3

  • 6

2 5 4 3

What about negative weight cycles?

slide-13
SLIDE 13

Di Dijkstra’ a’s A Algorithm ( (SSSP) P)

A C D E B F G H 7 5 4 10 7 5 3 6

  • 2

2 3 3

What about negative weight edges, without negative weight cycles?

slide-14
SLIDE 14

Di Dijkstra’ a’s A Algorithm ( (SSSP) P)

DijkstraSSSP(G, s): foreach (Vertex v : G): d[v] = +inf p[v] = NULL d[s] = 0 PriorityQueue Q // min distance, defined by d[v] Q.buildHeap(G.vertices()) Graph T // "labeled set" repeat n times: Vertex u = Q.removeMin() T.add(u) foreach (Vertex v : neighbors of u not in T): if _______________ < d[v]: d[v] = __________________ p[v] = m 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

What is the running time?