 Graph Algorithms: Minimum Spanning Tree 1 2 3 4 6 5 10 1 5 4 3 2 6 1 1 8 We are given a weighted, undirected graph G = (V, E), with weight function w:

Presentation on theme: "Graph Algorithms: Minimum Spanning Tree 1 2 3 4 6 5 10 1 5 4 3 2 6 1 1 8 We are given a weighted, undirected graph G = (V, E), with weight function w:"— Presentation transcript:

Graph Algorithms: Minimum Spanning Tree 1 2 3 4 6 5 10 1 5 4 3 2 6 1 1 8 We are given a weighted, undirected graph G = (V, E), with weight function w: E  R mapping edges to real valued weights.

Graph Algorithms: Minimum Spanning Tree 1 2 3 4 6 5 10 1 5 4 3 2 6 1 1 8 We are given a weighted, undirected graph G = (V, E), with weight function w: E  R mapping edges to real valued weights. A spanning tree T = (V’, E’) is a subgraph of G such that V’ = V and T is a tree.

Graph Algorithms: Minimum Spanning Tree 1 2 3 4 6 5 10 1 5 4 3 2 6 1 1 8 We are given a weighted, undirected graph G = (V, E), with weight function w: E  R mapping edges to real valued weights. A minimum spanning tree is a spanning tree where the sum of the weights in E’ is minimal. A spanning tree T = (V’, E’) is a subgraph of G such that V’ = V and T is a tree.

Graph Algorithms: Minimum Spanning Tree 1 2 3 4 6 5 10 1 5 4 3 2 6 1 1 8 Prim’s algorithm for finding a minimum spanning tree: 1. Starting from an empty tree, T, pick a vertex, v 0, at random and initialize: V’ = {v 0 } and E’ = {}. v0v0

Graph Algorithms: Minimum Spanning Tree 1 2 3 4 6 5 10 1 5 4 3 2 6 1 1 8 Prim’s algorithm for finding a minimum spanning tree: 1. Starting from an empty tree, T, pick a vertex, v 0, at random and initialize: V’ = {v 0 } and E’ = {}. v0v0 2. Choose a vertex v not in V’ such that edge weight from v to a vertex in V’ is minimal.

Graph Algorithms: Minimum Spanning Tree 1 2 3 4 6 5 10 1 5 4 3 2 6 1 1 8 Prim’s algorithm for finding a minimum spanning tree: 1. Starting from an empty tree, T, pick a vertex, v 0, at random and initialize: V’ = {v 0 } and E’ = {}. v0v0 2. Choose a vertex v not in V’ such that edge weight from v to a vertex in V’ is minimal and no cycle will be created if v and the edge are added to (V’, E’). Add v to V’ and the edge to E’.

Graph Algorithms: Minimum Spanning Tree 1 2 3 4 6 5 10 1 5 4 3 2 6 1 1 8 Prim’s algorithm for finding a minimum spanning tree: 1. Starting from an empty tree, T, pick a vertex, v 0, at random and initialize: V’ = {v 0 } and E’ = {}. v0v0 2. Choose a vertex v not in V’ such that edge weight from v to a vertex in V’ is minimal and no cycle will be created if v and the edge are added to (V’, E’). Add v to V’ and the edge to E’. Repeat until all vertices have been added.

Graph Algorithms: Minimum Spanning Tree 1 2 3 4 6 5 10 1 5 4 3 2 6 1 1 8 Prim’s algorithm for finding a minimum spanning tree: 1. Starting from an empty tree, T, pick a vertex, v 0, at random and initialize: V’ = {v 0 } and E’ = {}. v0v0 2. Choose a vertex v not in V’ such that edge weight from v to a vertex in V’ is minimal and no cycle will be created if v and the edge are added to (V’, E’). Add v to V’ and the edge to E’. Repeat until all vertices have been added.

Graph Algorithms: Minimum Spanning Tree 1 2 3 4 6 5 10 1 5 4 3 2 6 1 1 8 Prim’s algorithm for finding a minimum spanning tree: 1. Starting from an empty tree, T, pick a vertex, v 0, at random and initialize: V’ = {v 0 } and E’ = {}. v0v0 2. Choose a vertex v not in V’ such that edge weight from v to a vertex in V’ is minimal and no cycle will be created if v and the edge are added to (V’, E’). Add v to V’ and the edge to E’. Repeat until all vertices have been added.

Graph Algorithms: Minimum Spanning Tree 1 2 3 4 6 5 10 1 5 4 3 2 6 1 1 8 Prim’s algorithm for finding a minimum spanning tree: 1. Starting from an empty tree, T, pick a vertex, v 0, at random and initialize: V’ = {v 0 } and E’ = {}. v0v0 2. Choose a vertex v not in V’ such that edge weight from v to a vertex in V’ is minimal and no cycle will be created if v and the edge are added to (V’, E’). Add v to V’ and the edge to E’. Repeat until all vertices have been added.

Graph Algorithms: Minimum Spanning Tree 1 2 3 4 6 5 10 1 5 4 3 2 6 1 1 8 Prim’s algorithm for finding a minimum spanning tree: 1. Starting from an empty tree, T, pick a vertex, v 0, at random and initialize: V’ = {v 0 } and E’ = {}. v0v0 2. Choose a vertex v not in V’ such that edge weight from v to a vertex in V’ is minimal and no cycle will be created if v and the edge are added to (V’, E’). Add v to V’ and the edge to E’. Repeat until all vertices have been added. Done! Sum of edge weights: 1 + 3 + 4 + 1 + 1 = 10.

Download ppt "Graph Algorithms: Minimum Spanning Tree 1 2 3 4 6 5 10 1 5 4 3 2 6 1 1 8 We are given a weighted, undirected graph G = (V, E), with weight function w:"

Similar presentations