0% found this document useful (0 votes)
81 views4 pages

Spanning Trees: Spanning Trees: A Subgraph T of A Undirected Graph G (V, E) Is A Spanning Tree of G If It Is A

Spanning trees are subgraphs of graphs that connect all vertices without cycles. Minimum spanning trees are spanning trees with the minimum total edge weight. They are useful for problems like designing phone networks with minimum cost. Two common algorithms for finding minimum spanning trees are Prim's algorithm and Kruskal's algorithm. Prim's algorithm builds the tree vertex by vertex, always adding the lowest weight edge connecting two parts. Kruskal's algorithm sorts the edges by weight and adds them one by one, skipping edges that would create cycles.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views4 pages

Spanning Trees: Spanning Trees: A Subgraph T of A Undirected Graph G (V, E) Is A Spanning Tree of G If It Is A

Spanning trees are subgraphs of graphs that connect all vertices without cycles. Minimum spanning trees are spanning trees with the minimum total edge weight. They are useful for problems like designing phone networks with minimum cost. Two common algorithms for finding minimum spanning trees are Prim's algorithm and Kruskal's algorithm. Prim's algorithm builds the tree vertex by vertex, always adding the lowest weight edge connecting two parts. Kruskal's algorithm sorts the edges by weight and adds them one by one, skipping edges that would create cycles.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Spanning Trees

Spanning Trees: A subgraph T of a undirected graph G(V,E) is a spanning tree of G if it is a


tree and contains every vertex of G.
(note: a graph is said tree if it has no cycle)

Minimum Spanning Trees


A Minimum Spanning Tree in an undirected connected weighted graph is a
spanning tree of minimum weight (among all spanning trees).
Remark: The minimum spanning tree may not be unique. However, if the weights
of all the edges are pairwise distinct, it is indeed unique

Why minimum spanning trees?


The standard application is to a problem like phone network design. You have a business with
several offices; you want to lease phone lines to connect them up with each other; and the phone
company charges different amounts of money to connect different pairs of cities. You want a set
of lines that connects all your offices with a minimum total cost. It should be a spanning tree,
since if a network isn't a tree you can always remove some edges and save money.

How to find minimum spanning tree?


We read two algorithm to find minimum spanning tree
i) Prims Algorithm
ii) Kruskal's Algorithm

i) Prim's algorithm
Rather than build a subgraph one edge at a time, Prim's algorithm builds a tree one vertex at a
time.
Prim's algorithm:
let T be a single vertex x
while (T has fewer than n vertices)
{
find the smallest edge connecting T to G-T
add it to T
}
Since each edge added is the smallest connecting T to G-T, we only add edges that should be
part of the MST.

Again, it looks like the loop has a slow step in it. But again, some data structures can be used
to speed this up. The idea is to use a heap to remember, for each vertex, the smallest edge
connecting T with that vertex.

Prim with heaps:


make a heap of values (vertex,edge,weight(edge))
initially (v,-,infinity) for each vertex
let tree T be empty
while (T has fewer than n vertices)
{
let (v,e,weight(e)) have the smallest weight in the heap
remove (v,e,weight(e)) from the heap
add v and e to T
for each edge f=(u,v)
if u is not already in T
find value (u,g,weight(g)) in heap
if weight(f) < weight(g)
replace (u,g,weight(g)) with (u,f,weight(f))
}
Analysis: We perform n steps in which we remove the smallest element in the heap, and at
most 2m steps in which we examine an edge f=(u,v). For each of those steps, we might replace
a value on the heap, reducing it's weight. (You also have to find the right value on the heap,
but that can be done easily enough by keeping a pointer from the vertices to the corresponding
values.) I haven't described how to reduce the weight of an element of a binary heap, but it's
easy to do in O(log n) time. Alternately by using a more complicated data structure known as
a Fibonacci heap, you can reduce the weight of an element in constant time. The result is a
total time bound of O(m + n log n).

ii) Kruskal's algorithm:

sort the edges of G in increasing order by length


keep a subgraph S of G, initially empty
for each edge e in sorted order
if the endpoints of e are disconnected in S
add e to S
return S
Note that, whenever you add an edge (u,v), it's always the smallest connecting the part of S
reachable from u with the rest of G.

This algorithm is known as a greedy algorithm, because it chooses at each step the cheapest
edge to add to S. You should be very careful when trying to use greedy algorithms to solve
other problems, since it usually doesn't work. E.g. if you want to find a shortest path from a
to b, it might be a bad idea to keep taking the shortest edges.

You might also like