Prims Minimum Spanning Tree Algorithm Neil Tang 412008

  • Slides: 9
Download presentation
Prim’s Minimum Spanning Tree Algorithm Neil Tang 4/1/2008 CS 223 Advanced Data Structures and

Prim’s Minimum Spanning Tree Algorithm Neil Tang 4/1/2008 CS 223 Advanced Data Structures and Algorithms 1

Class Overview Ø The minimum spanning tree problem Ø An application Ø Prim’s algorithm

Class Overview Ø The minimum spanning tree problem Ø An application Ø Prim’s algorithm Ø Implementation and time complexity CS 223 Advanced Data Structures and Algorithms 2

Minimum Spanning Tree Problem Ø The cost of a tree: The sum of the

Minimum Spanning Tree Problem Ø The cost of a tree: The sum of the weights of all links on the tree. Ø The Minimum Spanning Tree (MST) problem: Given a weighted undirected graph G, find a minimum cost tree connecting all the vertices on the graph CS 223 Advanced Data Structures and Algorithms 3

Minimum Spanning Tree Problem CS 223 Advanced Data Structures and Algorithms 4

Minimum Spanning Tree Problem CS 223 Advanced Data Structures and Algorithms 4

An Application Ø Broadcasting problem in Computer Networks: Find the minimum cost route to

An Application Ø Broadcasting problem in Computer Networks: Find the minimum cost route to send a package from a source node to all the other nodes in the network. CS 223 Advanced Data Structures and Algorithms 5

Prim’s Algorithm CS 223 Advanced Data Structures and Algorithms 6

Prim’s Algorithm CS 223 Advanced Data Structures and Algorithms 6

Prim’s Algorithm CS 223 Advanced Data Structures and Algorithms 7

Prim’s Algorithm CS 223 Advanced Data Structures and Algorithms 7

Prim’s Algorithm CS 223 Advanced Data Structures and Algorithms 8

Prim’s Algorithm CS 223 Advanced Data Structures and Algorithms 8

Implementation and Time Complexities Ø Difference between Prim and Dijkstra: 1) Arbitrarily pick a

Implementation and Time Complexities Ø Difference between Prim and Dijkstra: 1) Arbitrarily pick a node to start with; 2) Relaxation dw=min(dw, cw, v) Ø Trivial: O(|V|2 + |E|) = O(|V|2) Ø Heap: delete. Min |V| times + decrease. Key |E| times O(|V|log|V| + |E|log|V|) = O (|E|log|V|) CS 223 Advanced Data Structures and Algorithms 9