Minimum spanning tree Prof Amir Geva Eitan Netzer.

Post on 23-Dec-2015

224 views 3 download

Transcript of Minimum spanning tree Prof Amir Geva Eitan Netzer.

Minimum spanning tree

Prof Amir GevaEitan Netzer

Definition

A sub group of edges from weighted graph G

• Spanning – reach all vertex• Minimal – the sum of its edges is the lowest of all spanning trees

• Uses – connect a network with while spending minimum money• Graph need to be connective

𝑤 (𝑇 )= ∑(𝑢 ,𝑣 )∈𝑇

𝑤 (𝑢 ,𝑣 )

Prim algorithm (1957)

• Greedy algorithm• Start with an empty list of vertex.• Choose starting vertex from G. Randomly or a given choice.• Add edge with minimal weight that not used yet to an un explored

vertex.• Continue until list of vertex contain all vertex in G.

Minimum edge weight data structure Time complexity (total)adjacency matrix, searching O(|V|2)binary heap and adjacency list O((|V| + |E|) log |V|) = O(|E| log |V|)Fibonacci heap and adjacency list O(|E| + |V| log |V|)

Pseudo Code

Kruskal's algorithm (1956)

• Greedy algorithm• Create a “forest” F a set of trees• Create a set S containing all edges of G• While S is not empty and F is not a spanning tree yet• Remove minimum edge from S• If edge connects to trees in F combine them• Else discard edge

Pseudo Code