
























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
Material Type: Notes; Class: Combinatorial Computing; Subject: Mathematics; University: Eastern Illinois University; Term: Spring 2009;
Typology: Study notes
1 / 32
This page cannot be seen from the preview
Don't miss anything!

























I (^) A spanning tree of a graph G is a subgraph of G that is a tree containing all vertices of G.
I (^) A minimal spanning tree is a spanning tree whose sum of the edge weights (lengths) is as small as possible.
I (^) Problem Statement : Given a graph G = (V, E) with positive edge weights (cost: E → <+), nd the cheapest connected spanning subgraph H of G.
I (^) Note : If H = (V, EH ), then cost(H) =
e∈E (H ) cost(e), i.e., cost of subgraph is sum of costs of edges in subgraph.
I (^) H must be a tree (if H exists). Why?
I (^) If G has n vertices (jV j = n), then any minimal spanning tree of G has N 1 edges.
I (^) A graph with no cycles is called a forest
I (^) A connected forest is called a tree
Procedure Prim (G): H // PRE: G is connected // POST: H is an MST of G
begin pick an arbitrary vertex x in the vertices of G, and add it to VH, the vertices in H from among the edges incident to x, select the cheapest and add it to EH, the edges in H while |EH| < |VG| - 1 find the cheapest edge <a, b> where a is in VH, and b is in VG - VH add <a, b> to EH, add b to VH end
I (^) We need to be able to ( quickly ) nd the next cheapest edge
I (^) Using a min-heap vs sorted list
I (^) Heap is better since not every edge may be examined / removed
I (^) But, what's a heap?
Heaps can be efciently implemented with arrays, which form an implicit (vs explicit) representation of a tree. For example:
i = 1 2 3 4 5 6 7 8 9 10 11 12 L 20 10 15 8 7 14 3 5 6 4 2 1
Where Children of L[i] are in positions 2i and 2i+1.
20
14
10 15
8 7
5 6 4 2 1
3
An array L[k..n] has the Minñheap property if
∀ i 3 k i < n 2
; L [i ] L [ 2 i ] and L [i ] L [ 2 i + 1 ]
if n is even, then L [ n 2 ] L [n]
In other words: Parents are smaller than their children , or child in the case n is even.
20
14
10 15
8 7
5 6 4 2 1
3
max is deleted, last child is moved up, and trickled down
1
14
10 15
8 7
5 6 4 2
3
I (^) Increment heap size
I (^) Put new value (x) in L[size]
I (^) While x is smaller (bigger) than its parent, swap them (aka percolateñ or bubbleñup)
10 14
8 7
5 6 4 2
3
17
1
15
What if we merely kept an unordered list?
I (^) Delete: nd, delete item, and ll in I (^) array: O (n) + O ( 1 ) + O ( 1 ) = O (n) I (^) linked list: O (n) + O ( 1 ) = O (n)
I (^) Insert: array / linked list: O ( 1 )
An ordered list?
I (^) Delete: nd, delete item, and ll in I (^) array: O ( 1 ) + O ( 1 ) + O (n) = O (n) I (^) linked list: O ( 1 ) + O ( 1 ) = O ( 1 )
I (^) Insert: nd position, insert (move) I (^) array: O (log n) + O (n) = O (n) I (^) linked list: O (n) + O ( 1 ) = O (n)
I (^) An array, L, can be sorted as follows:
I (^) How fast is this sort? I (^) Step 2 takes time:
log (n) + log (n 1 ) + + log ( 1 ) =
∑
i = 1 ::n
log i ∈ O (n log n)
I (^) Step 1? It depends...