

















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
This lecture is part of lecture series for Design and Analysis of Algorithms course. This course was taught by Dr. Bhaskar Sanyal at Maulana Azad National Institute of Technology. It includes: Minimum, Spanning, Tree, Greedy, Vhoices, Sequence, Short-term, Optimal, Actions, Solution, Substructure, Dynamic
Typology: Slides
1 / 25
This page cannot be seen from the preview
Don't miss anything!
Docsity.com
» Each individual choice is best according to some limited “short- term” criterion, that is not too expensive to evaluate » Once a choice is made, it cannot be undone! Even if it becomes evident later that it was a poor choice Sometimes life is like that
» take a sequence of locally optimal actions, hoping to yield a globally optimal solution.
Docsity.com
Minimum Spanning Tree (MST)
A spanning tree for a connected, undirected graph, G =( V , E ) is
In a weighted graph G =( V , E , W ),
A minimum spanning tree (MST) for a weighted graph is
Docsity.com
Docsity.com
Docsity.com
Docsity.com
Prime’s Algorithm
(High-Level Pseudocode)
Prime(G) //Input: A weighted connected graph G = <V, E> //Output: ET --- the set of edges composing MST of G VT = {v 0 } ET = for i = 1 to |V| - 1 do find a minimum-weight edge e* = (u, v) among all the edges (u, v) such that u is in VT and v is in V-VT VT = VT {v} ET = ET {e} return ET
Docsity.com
Prime’s Algorithm
(High-Level Pseudocode)
Prime(G) //Input: A weighted connected graph G = <V, E> //Output: ET --- the set of edges composing MST of G VT = {v 0 } ET = for i = 1 to |V| - 1 do find a minimum-weight edge e* = (u, v) among all the edges (u, v) such that u is in VT and v is in V-VT VT = VT {v} ET = ET {e} return ET
(^14 )
3
6 4 5
2
9
15
(^8) Docsity.com
MST-Prim(G, w, r) Q = V[G]; for each u Q key[u] = ; key[r] = 0; p[r] = NULL; while (Q not empty) u = ExtractMin(Q); for each v Adj[ u ] if (v Q and w( u,v ) < key[ v ]) p[v] = u; key[v] = w(u,v);
Docsity.com
MST-Prim(G, w, r) Q = V[G]; for each u Q key[u] = ; key[r] = 0; p[r] = NULL; while (Q not empty) u = ExtractMin(Q); for each v Adj[ u ] if (v Q and w( u,v ) < key[ v ]) p[v] = u; key[v] = w(u,v);
14 10
3
6 4 5
2
9
15
8
Run on example graph
Docsity.com
MST-Prim(G, w, r) Q = V[G]; for each u Q key[u] = ; key[r] = 0; p[r] = NULL; while (Q not empty) u = ExtractMin(Q); for each v Adj[ u ] if (v Q and w( u,v ) < key[ v ]) p[v] = u; key[v] = w(u,v);
14 10
3
6 4 5
2
9
15
8
Pick a start vertex r
r
Docsity.com
MST-Prim(G, w, r) Q = V[G]; for each u Q key[u] = ; key[r] = 0; p[r] = NULL; while (Q not empty) u = ExtractMin(Q); for each v Adj[ u ] if (v Q and w( u,v ) < key[ v ]) p[v] = u; key[v] = w(u,v);
14 10
3
6 4 5
2
9
15
8
Red vertices have been removed from Q
u
Docsity.com
MST-Prim(G, w, r) Q = V[G]; for each u Q key[u] = ; key[r] = 0; p[r] = NULL; while (Q not empty) u = ExtractMin(Q); for each v Adj[ u ] if (v Q and w( u,v ) < key[ v ]) p[v] = u; key[v] = w(u,v);
14 10
3
6 4 5
2
9
15
8
u
Docsity.com
MST-Prim(G, w, r) Q = V[G]; for each u Q key[u] = ; key[r] = 0; p[r] = NULL; while (Q not empty) u = ExtractMin(Q); for each v Adj[ u ] if (v Q and w( u,v ) < key[ v ]) p[v] = u; key[v] = w(u,v);
14 10
3
6 4 5
2
9
15
8 u
Docsity.com