CS 225
Data Structures
Dec Decem ember er 2 2 – Di Dijkstra’s Al Algorihtm
G G Carl Evans
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
Data Structures
Dec Decem ember er 2 2 – Di Dijkstra’s Al Algorihtm
G G Carl Evans
To study all of these structures:
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)
O(n + m lg(n))
Sparse Graph: Dense Graph:
O(n lg(n) + m lg(n))
Sparse Graph: Dense Graph:
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?
O(m lg(n))
O(n lg(n) + m lg(n))
O(m lg(n))
O(n lg(n) + m)
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
Extra Credit: Due Tomorrow! (+7 points!)
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
A C D E B F G H 7 5 4 10 7
3
2 5 4 3
What about negative weight cycles?
A C D E B F G H 7 5 4 10 7 5 3 6
2 3 3
What about negative weight edges, without negative weight cycles?
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?