L16-MST

Case 1 if a e t then the theorem is true already case

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: times: 3 Pick a cut (S, V S ) that respects A 4 Let e be min-weight edge over cut (S, V 5 A ⇥ A ⌅ {e} S) Prim’s algorithm General-MST-Strategy(G = (V, E )) 1 A⇥⇤ 2 repeat V 1 times: 3 Pick a cut (S, V S ) that respects A 4 Let e be min-weight edge over cut (S, V 5 A ⇥ A ⌅ {e} A is a subtree edge e is lightest edge that grows the subtree S) prim b 8 d g 7 10 a 8 3 c 5 e 9 12 2 9 11 3 1 i f 6 h prim b 8 d g 7 10 a 8 3 c 5 e 9 12 2 9 11 3 1 i f 6 h prim b 8 d g 7 10 a 8 3 c 5 e 9 12 2 9 11 3 1 i f 6 h prim b 8 d g 7 10 a 8 3 c 5 e 9 12 2 9 11 3 1 i f 6 h prim b 8 d g 7 10 a 8 3 c 5 e 9 12 2 9 11 3 1 i f 6 h implementation idea: implementation new data structure binary heap full tree, key value <= to key of children binary heap full tree, key value <= to key of children ! "# "" &! $ "! '' % : binary heap full tree, key value <= to key of children ! "# $ "" &! "! '' ( % : binary heap full tree, key value <= to key of children ! "# $ "" &! ( '' "! % : binary heap full tree, key value <= to key of children how to extractmin? ! ( $ "" &! "# '' "! % : binary heap full tree, key value <= to key of children how to extractmin? 24 ( $ "" &! "# '' "! % : binary heap full tree, key value <= to key of children how to extractmin? $ ( 24 "" &! "# '' "! % : binary heap full tree, key value <= to key of children how to extractmin? $ how to decreasekey? ( % "" &! "# ) '' "! 24 : binary heap full tree, key value <= to key of children how to extractmin? $ how to decreasekey? ) % "" &! "# ( '' "! 24 : implementation use a priority queue to keep track of light edges insert: makequeue: extractmin: decreasekey: algorithm implementation prim(G = (V, E )) 1Q ⇧ Q is a Priority Queue 2 Initialize each v ⇤ V with key kv ⇥, v nil 3 Pick a starting node r and set kr 0 4 Insert all nodes into Q with key kv . 5 while Q ⌅= ⇧ 6 do u extract-min(Q) 7 for each v ⇤ Adj (u) 8 do if v ⇤ Q and w(u, v ) < kv 9 then v u 10 decrease-key(Q, v, w(u, v )) Sets kv w(u, v ) prim b 8 d 0 g 7 10 a 8 3 c 5 e 9 12 2...
View Full Document

Ask a homework question - tutors are online