SlideShare uma empresa Scribd logo
1 de 80
CS 332: Algorithms Single-Source Shortest Path
Review: Prim’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Review: Prim’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],14 10 3 6 4 5 2 9 15 8 Run on example graph
Review: Prim’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],        14 10 3 6 4 5 2 9 15 8 Run on example graph
Review: Prim’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],   0     14 10 3 6 4 5 2 9 15 8 Pick a start vertex r r
Review: Prim’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],   0     14 10 3 6 4 5 2 9 15 8 Red vertices have been removed from Q u
Review: Prim’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],   0   3  14 10 3 6 4 5 2 9 15 8 Red arrows indicate parent pointers u
Review: Prim’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],14   0   3  14 10 3 6 4 5 2 9 15 8 u
Review: Prim’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],14   0   3  14 10 3 6 4 5 2 9 15 8 u
Review: Prim’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],14   0 8  3  14 10 3 6 4 5 2 9 15 8 u
Review: Prim’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],10   0 8  3  14 10 3 6 4 5 2 9 15 8 u
Review: Prim’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],10   0 8  3  14 10 3 6 4 5 2 9 15 8 u
Review: Prim’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],10 2  0 8  3  14 10 3 6 4 5 2 9 15 8 u
Review: Prim’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],10 2  0 8 15 3  14 10 3 6 4 5 2 9 15 8 u
Prim’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],10 2  0 8 15 3  14 10 3 6 4 5 2 9 15 8 u
Review: Prim’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],10 2 9 0 8 15 3  14 10 3 6 4 5 2 9 15 8 u
Review: Prim’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],10 2 9 0 8 15 3 4 14 10 3 6 4 5 2 9 15 8 u
Review: Prim’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],5 2 9 0 8 15 3 4 14 10 3 6 4 5 2 9 15 8 u
Review: Prim’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],5 2 9 0 8 15 3 4 14 10 3 6 4 5 2 9 15 8 u
Review: Prim’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],5 2 9 0 8 15 3 4 14 10 3 6 4 5 2 9 15 8 u
Review: Prim’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],5 2 9 0 8 15 3 4 14 10 3 6 4 5 2 9 15 8 u
Review: Prim’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],5 2 9 0 8 15 3 4 14 10 3 6 4 5 2 9 15 8 u
Review: Prim’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],What is the hidden cost in this code?
Review: Prim’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Review: Prim’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],How often is ExtractMin() called? How often is DecreaseKey() called?
Review: Prim’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],What will be the running time? A: Depends on queue   binary heap: O(E lg V)   Fibonacci heap: O(V lg V + E)
Single-Source Shortest Path ,[object Object],[object Object],[object Object],[object Object]
Shortest Path Properties ,[object Object],[object Object],[object Object],[object Object],[object Object]
Shortest Path Properties ,[object Object],[object Object],[object Object],x u v This path is no longer than any other path
Shortest Path Properties ,[object Object],< 0
Relaxation ,[object Object],[object Object],[object Object],[object Object],[object Object],9 5 2 7 5 2 Relax 6 5 2 6 5 2 Relax
Bellman-Ford Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Initialize d[], which will converge to  shortest-path value   Relaxation:  Make |V|-1 passes,  relaxing each edge Test for solution   Under what condition do we get a solution?
Bellman-Ford Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],What will be the  running time?
Bellman-Ford Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],What will be the  running time? A: O(VE)
Bellman-Ford Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],B E D C A -1 2 2 1 -3 5 3 4 Ex: work on board s
Bellman-Ford ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Bellman-Ford ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
DAG Shortest Paths ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Dijkstra’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object]
Dijkstra’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Relaxation Step Note: this is really a  call to Q->DecreaseKey() B C D A 10 4 3 2 1 5 Ex: run the algorithm
Dijkstra’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],How many times is  ExtractMin() called? How many times is  DecraseKey() called? What will be the total running time?
Dijkstra’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],How many times is  ExtractMin() called? How many times is  DecraseKey() called? A: O(E lg V) using binary heap for Q Can acheive O(V lg V + E) with Fibonacci heaps
Dijkstra’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Correctness: we must show that when u is  removed from Q, it has already converged
Correctness Of Dijkstra's Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],s x y u p 2 p 2
Correctness Of Dijkstra's Algorithm ,[object Object],[object Object],[object Object],[object Object],s x y u p 2 p 2
Disjoint-Set Union Problem ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Kruskal’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Kruskal’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2 19 9 1 5 13 17 25 14 8 21 Run the algorithm:
Kruskal’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2 19 9 1 5 13 17 25 14 8 21 Run the algorithm:
Kruskal’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2 19 9 1 5 13 17 25 14 8 21 Run the algorithm:
Kruskal’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2 19 9 1? 5 13 17 25 14 8 21 Run the algorithm:
Kruskal’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2 19 9 1 5 13 17 25 14 8 21 Run the algorithm:
Kruskal’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2? 19 9 1 5 13 17 25 14 8 21 Run the algorithm:
Kruskal’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2 19 9 1 5 13 17 25 14 8 21 Run the algorithm:
Kruskal’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2 19 9 1 5? 13 17 25 14 8 21 Run the algorithm:
Kruskal’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2 19 9 1 5 13 17 25 14 8 21 Run the algorithm:
Kruskal’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2 19 9 1 5 13 17 25 14 8? 21 Run the algorithm:
Kruskal’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2 19 9 1 5 13 17 25 14 8 21 Run the algorithm:
Kruskal’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2 19 9? 1 5 13 17 25 14 8 21 Run the algorithm:
Kruskal’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2 19 9 1 5 13 17 25 14 8 21 Run the algorithm:
Kruskal’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2 19 9 1 5 13? 17 25 14 8 21 Run the algorithm:
Kruskal’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2 19 9 1 5 13 17 25 14 8 21 Run the algorithm:
Kruskal’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2 19 9 1 5 13 17 25 14? 8 21 Run the algorithm:
Kruskal’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2 19 9 1 5 13 17 25 14 8 21 Run the algorithm:
Kruskal’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2 19 9 1 5 13 17? 25 14 8 21 Run the algorithm:
Kruskal’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2 19? 9 1 5 13 17 25 14 8 21 Run the algorithm:
Kruskal’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2 19 9 1 5 13 17 25 14 8 21? Run the algorithm:
Kruskal’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2 19 9 1 5 13 17 25? 14 8 21 Run the algorithm:
Kruskal’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2 19 9 1 5 13 17 25 14 8 21 Run the algorithm:
Kruskal’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2 19 9 1 5 13 17 25 14 8 21 Run the algorithm:
Correctness Of Kruskal’s Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Kruskal’s Algorithm Kruskal() { T =   ; for each v    V MakeSet(v); sort E by increasing edge weight w for each (u,v)    E (in sorted order) if FindSet(u)    FindSet(v) T = T  U  {{u,v}}; Union(FindSet(u), FindSet(v)); } What will affect the running time?
Kruskal’s Algorithm Kruskal() { T =   ; for each v    V MakeSet(v); sort E by increasing edge weight w for each (u,v)    E (in sorted order) if FindSet(u)    FindSet(v) T = T  U  {{u,v}}; Union(FindSet(u), FindSet(v)); } What will affect the running time? 1 Sort O(V) MakeSet() calls O(E) FindSet() calls O(V) Union() calls  ( Exactly how many Union()s? )
Kruskal’s Algorithm: Running Time ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Disjoint Set Union ,[object Object],[object Object],[object Object],[object Object],[object Object]
Disjoint Set Union ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Disjoint Set Union: Analysis ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Amortized Analysis of Disjoint Sets ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Amortized Analysis of Disjoint Sets ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The End

Mais conteúdo relacionado

Mais procurados

Algorithm Design and Complexity - Course 9
Algorithm Design and Complexity - Course 9Algorithm Design and Complexity - Course 9
Algorithm Design and Complexity - Course 9
Traian Rebedea
 
Linear transformations and matrices
Linear transformations and matricesLinear transformations and matrices
Linear transformations and matrices
EasyStudy3
 
Algorithm Design and Complexity - Course 8
Algorithm Design and Complexity - Course 8Algorithm Design and Complexity - Course 8
Algorithm Design and Complexity - Course 8
Traian Rebedea
 

Mais procurados (20)

Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithms
 
Shortest path algorithms
Shortest path algorithmsShortest path algorithms
Shortest path algorithms
 
Prim's algorithm
Prim's algorithmPrim's algorithm
Prim's algorithm
 
Proyecto parcial iii_ proyecciones lineales
Proyecto parcial iii_ proyecciones linealesProyecto parcial iii_ proyecciones lineales
Proyecto parcial iii_ proyecciones lineales
 
Bellman ford algorithm
Bellman ford algorithmBellman ford algorithm
Bellman ford algorithm
 
Minimum spanning tree algorithms by ibrahim_alfayoumi
Minimum spanning tree algorithms by ibrahim_alfayoumiMinimum spanning tree algorithms by ibrahim_alfayoumi
Minimum spanning tree algorithms by ibrahim_alfayoumi
 
Algorithm Design and Complexity - Course 9
Algorithm Design and Complexity - Course 9Algorithm Design and Complexity - Course 9
Algorithm Design and Complexity - Course 9
 
SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS
 
Prims & kruskal algorithms
Prims & kruskal algorithmsPrims & kruskal algorithms
Prims & kruskal algorithms
 
Topological sorting
Topological sortingTopological sorting
Topological sorting
 
Vcla 1
Vcla 1Vcla 1
Vcla 1
 
Shortest Path in Graph
Shortest Path in GraphShortest Path in Graph
Shortest Path in Graph
 
Shortest path
Shortest pathShortest path
Shortest path
 
Single source stortest path bellman ford and dijkstra
Single source stortest path bellman ford and dijkstraSingle source stortest path bellman ford and dijkstra
Single source stortest path bellman ford and dijkstra
 
linear transformation
linear transformationlinear transformation
linear transformation
 
Linear transformations and matrices
Linear transformations and matricesLinear transformations and matrices
Linear transformations and matrices
 
chapter24.ppt
chapter24.pptchapter24.ppt
chapter24.ppt
 
Linear Combination, Span And Linearly Independent, Dependent Set
Linear Combination, Span And Linearly Independent, Dependent SetLinear Combination, Span And Linearly Independent, Dependent Set
Linear Combination, Span And Linearly Independent, Dependent Set
 
Algorithm Design and Complexity - Course 8
Algorithm Design and Complexity - Course 8Algorithm Design and Complexity - Course 8
Algorithm Design and Complexity - Course 8
 
2.3 shortest path dijkstra’s
2.3 shortest path dijkstra’s 2.3 shortest path dijkstra’s
2.3 shortest path dijkstra’s
 

Semelhante a lecture 20 (8)

Graphs > Discrete structures , Data Structures & Algorithums
Graphs > Discrete structures , Data Structures & AlgorithumsGraphs > Discrete structures , Data Structures & Algorithums
Graphs > Discrete structures , Data Structures & Algorithums
 
Unit 5 session 2 MinimumSpanningTrees.ppt
Unit 5 session 2 MinimumSpanningTrees.pptUnit 5 session 2 MinimumSpanningTrees.ppt
Unit 5 session 2 MinimumSpanningTrees.ppt
 
lec6.pptx
lec6.pptxlec6.pptx
lec6.pptx
 
深層生成モデルを用いたマルチモーダルデータの半教師あり学習
深層生成モデルを用いたマルチモーダルデータの半教師あり学習深層生成モデルを用いたマルチモーダルデータの半教師あり学習
深層生成モデルを用いたマルチモーダルデータの半教師あり学習
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
Control as Inference (強化学習とベイズ統計)
Control as Inference (強化学習とベイズ統計)Control as Inference (強化学習とベイズ統計)
Control as Inference (強化学習とベイズ統計)
 
VLSI Sequential Circuits II
VLSI Sequential Circuits IIVLSI Sequential Circuits II
VLSI Sequential Circuits II
 
ゲーム理論NEXT 戦略形協力ゲーム第11回 -寡占市場ゲームにおける結託耐性ナッシュ均衡-
ゲーム理論NEXT 戦略形協力ゲーム第11回 -寡占市場ゲームにおける結託耐性ナッシュ均衡-ゲーム理論NEXT 戦略形協力ゲーム第11回 -寡占市場ゲームにおける結託耐性ナッシュ均衡-
ゲーム理論NEXT 戦略形協力ゲーム第11回 -寡占市場ゲームにおける結託耐性ナッシュ均衡-
 

Mais de sajinsc

lecture 30
lecture 30lecture 30
lecture 30
sajinsc
 
lecture 29
lecture 29lecture 29
lecture 29
sajinsc
 
lecture 28
lecture 28lecture 28
lecture 28
sajinsc
 
lecture 27
lecture 27lecture 27
lecture 27
sajinsc
 
lecture 26
lecture 26lecture 26
lecture 26
sajinsc
 
lecture 25
lecture 25lecture 25
lecture 25
sajinsc
 
lecture 24
lecture 24lecture 24
lecture 24
sajinsc
 
lecture 23
lecture 23lecture 23
lecture 23
sajinsc
 
lecture 19
lecture 19lecture 19
lecture 19
sajinsc
 
lecture 18
lecture 18lecture 18
lecture 18
sajinsc
 
lecture 17
lecture 17lecture 17
lecture 17
sajinsc
 
lecture 16
lecture 16lecture 16
lecture 16
sajinsc
 
lecture 15
lecture 15lecture 15
lecture 15
sajinsc
 
lecture 14
lecture 14lecture 14
lecture 14
sajinsc
 
lecture 13
lecture 13lecture 13
lecture 13
sajinsc
 
lecture 12
lecture 12lecture 12
lecture 12
sajinsc
 
lecture 11
lecture 11lecture 11
lecture 11
sajinsc
 
lecture 10
lecture 10lecture 10
lecture 10
sajinsc
 
lecture 9
lecture 9lecture 9
lecture 9
sajinsc
 
lecture 8
lecture 8lecture 8
lecture 8
sajinsc
 

Mais de sajinsc (20)

lecture 30
lecture 30lecture 30
lecture 30
 
lecture 29
lecture 29lecture 29
lecture 29
 
lecture 28
lecture 28lecture 28
lecture 28
 
lecture 27
lecture 27lecture 27
lecture 27
 
lecture 26
lecture 26lecture 26
lecture 26
 
lecture 25
lecture 25lecture 25
lecture 25
 
lecture 24
lecture 24lecture 24
lecture 24
 
lecture 23
lecture 23lecture 23
lecture 23
 
lecture 19
lecture 19lecture 19
lecture 19
 
lecture 18
lecture 18lecture 18
lecture 18
 
lecture 17
lecture 17lecture 17
lecture 17
 
lecture 16
lecture 16lecture 16
lecture 16
 
lecture 15
lecture 15lecture 15
lecture 15
 
lecture 14
lecture 14lecture 14
lecture 14
 
lecture 13
lecture 13lecture 13
lecture 13
 
lecture 12
lecture 12lecture 12
lecture 12
 
lecture 11
lecture 11lecture 11
lecture 11
 
lecture 10
lecture 10lecture 10
lecture 10
 
lecture 9
lecture 9lecture 9
lecture 9
 
lecture 8
lecture 8lecture 8
lecture 8
 

Último

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Último (20)

Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 

lecture 20

  • 1. CS 332: Algorithms Single-Source Shortest Path
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72. Kruskal’s Algorithm Kruskal() { T =  ; for each v  V MakeSet(v); sort E by increasing edge weight w for each (u,v)  E (in sorted order) if FindSet(u)  FindSet(v) T = T U {{u,v}}; Union(FindSet(u), FindSet(v)); } What will affect the running time?
  • 73. Kruskal’s Algorithm Kruskal() { T =  ; for each v  V MakeSet(v); sort E by increasing edge weight w for each (u,v)  E (in sorted order) if FindSet(u)  FindSet(v) T = T U {{u,v}}; Union(FindSet(u), FindSet(v)); } What will affect the running time? 1 Sort O(V) MakeSet() calls O(E) FindSet() calls O(V) Union() calls ( Exactly how many Union()s? )
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.