CMU 15-251 Graph Algorithms Teachers: Anil Ada Ariel Procaccia (this time)
Depth-First Search β’ For each 7 unexplored π£ β π 6 1 DFS( π» ,u) o DFS(graph π» , π£ β πΉ ) 3 β’ mark π£ as explored 5 2 β’ for each {π£, π€} β πΉ 4 if π€ is o unexplored then DFS( π», v ) π(π + π) 2
Graph Search Problems π» β’ o π‘ π’ π» o π» o β’ 3
Topological Sorting π» β’ π: π β {1, β¦ , π} π£, π€ β πΉ π π£ < π(π€) π π π π π π π π π π 4
Topological Sorting 15 251 21 127 15 15 15 451 112 150 15 122 15 210 5
Topological Sorting β’ π£, π€ β π π£, π€ β πΉ β’ 6
Topological Sorting β’ β’ β’ β’ 7
Proof of Lemma β’ β’ π β 8
NaΓ―ve Algorithm β’ π β π β’ while π β₯ 1 3 If the graph doesnβt o have a sink then 4 5 2 return βnot acyclicβ else find a sink π€ and o 1 remove it from π» π π€ β π o π β π β 1 o 9
Better Algorithm Via DFS β’ π β π β’ For each unexplored π£ β π , DFS( π» ,u) 3 DFS(graph π» , π£ β πΉ ) β’ mark π£ as explored 4 5 2 β’ for each {π£, π€} β πΉ , if π€ is unexplored then DFS( π», v ) 1 β’ π π£ β π β’ π β π β 1 10
Correctness π» π£, π€ β πΉ β’ π π£ < π(π€) β’ π£ π€ o π£, π€ β πΉ π€ (π», π£) π€ π£ o π£ (π», π€) (π», π£) (π», π€) β 11
Weighted Graphs β’ 8 5 o 10 o 2 3 18 16 o 12 30 o 14 β’ 4 26 β’ π: πΉ β β + 12
Minimum Spanning Tree 13
14
Minimum Spanning Tree β’ π» o 8 5 π: πΉ β β + 10 πΉ β² β πΉ o 2 3 π, πΉ β² 18 16 12 30 πβπΉ β² π π 14 4 26 β’ 42 15
16
Number of MSTs β’ β’ π§ π¦ π¨ 17
18
Primβs Algorithm β’ π β² β π£ , πΉ β² β β β’ While π β² β π 8 5 5 o Let (π£, π€) be a 10 minimum cost edge 2 2 3 3 18 16 16 such that π£ β π β² , 12 12 30 π€ β πβ² 14 o πΉ β² β πΉ βͺ 4 4 26 π£, π€ o π β² β π β² βͺ {π€} 19
20
Proof of Correctness π β’ 0 β€ π β€ π π π β’ π = 0) β’ β’ π 21
Proof of Correctness π β² β’ π = {π, π} β’ π π β’ π π π πβ² β’ π a β π π π π β² = (π, π) β’ πβ² 22
Proof of Correctness π β² = π βͺ π β {π β² } β’ π o π β 1 o π β’ πβ² π π π£ β π β π β π€ πβ² πβ² π π π£ β π β π β π β π β π€ π β β’ 23
24
πβ² 25
The MST Cut Property π» β’ π β² β π π πβ² π β πβ² π β’ β’ o o 26
Run-Time Race for MST β’ π π 2 β’ π(π log π) β’ β’ β’ 27
Run Time Race for MST π(π log π) β π(π log β π) 28
Run Time Race for MST π(π log β π) β π(π log(log β π)) 29
Run Time Race for MST π(π log(log β π)) β π(π β π½ π ) π½ β ? 30
Detour: π½(β ) β’ log β π = log 2 β’ log ββ (π) = log * 2 β’ log βββ (π) = log ** 2 β’ log ββ―β π β€ 2 β’ π½ π = 31
Run Time Race for MST β’ β’ 32
Summary β’ o o o β’ o o o β’ o 33
Recommend
More recommend