Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
INTRODUCTION
The standard application of minimum spanning tree is to
solve a problem like phone network design.
If we have a business with several offices; we 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.
We want a set of lines that connects all our offices with a
minimum total cost. It should be a minimum spanning tree,
since if a network isn't a tree we can always remove some
edges and save money.
SPANNING TREES
A spanning tree of a graph is any tree that includes every
vertex in the graph.
More formally, a spanning tree of a graph G is a subgraph of
G that is a tree and contains all the vertices of G.
We construct spanning tree whenever we want to find a
simple, cheap and efficient way to connect a set of terminals
There are two algorithms: the Kruskals algorithm and the prims
algorithm to find the minimum spanning tree of an undirected
weighted graph. These algorithms use similar approaches, but
work in very different ways.
KRUSKALS ALGORITHM FOR MST
Kruskals algorithm is a greedy algorithm. A greedy
algorithm chooses some local optimum (i.e. picking an edge
with the least weight in a MST).
It builds the MST in forest. Initially, each vertex is in its own
tree in forest. Then, algorithm considers each edge in turn,
ordered by increasing weight.
UNION (u, v): Unites the dynamic sets that contain u and v
into a new set that is union of these two sets.
Analysis:
Let V be the number of vertices and E be the number of edges
and we assume that E V 1.
It takes (E log E) time to sort the edges. The for loop
iterates E number of times, and each iteration involves a
constant number of accesses to the Union-Find disjoint set
data structure on the collection of V items.
Thus each access takes (log V) time, which gives a total of
(E log V) times.
Thus the total running time for the algorithm is evaluated by
adding up all these, which is ((V +E) log V). Since V is not
asymptotically larger than E, the running time can be
expressed as (E log V).
Example: Find the MST of the following given graph using kruskals algorithm.
Solution:
Prim's algorithm has the property that the edges in the set A
always form a single tree. We begin with some vertex u in a
given graph G = (V, E), defining the initial set of vertices A.
In each iteration, we choose a minimum-weight edge (u, v),
connecting a vertex u in the set A to the vertex v outside of
set A. Then vertex v is brought in to A.
This process is repeated until a spanning tree is formed. Like
Kruskal's algorithm, the important fact about MSTs is that we
always choose the smallest-weight edge joining a vertex
inside set A to the one outside the set A. Prim is slightly more
efficient than Kruskal.
How it works
9
10
Analysis:
11
Solution:
12
13
Example: Find the MST of the following given graph using Prims algorithm.
14
15