Minimum Spanning Tree Spanning Tree Example Example

Document Sample

```					Minimum Spanning Tree                                       Spanning Tree
• Tree:                                      • A spanning tree is a tree that spans all the nodes
– A tree is a graph with the following     • Thus, if there are n nodes in the network, a tree
properties:                                spanning this network will have n-1 arcs that
• The graph is connected (can go from     go through all the nodes
anywhere to anywhere)
• There are no cycles

Example                                   Example

1
Minimum Spanning tree                               Algorithm for a Spanning Tree
• It is the shortest spanning tree (length of a tree   • Two basic algorithms exists
is equal to the sum of the length of the arcs on       – Kruskal (by arc)
the tree).                                             – Prim (by sub-tree)
• Very important                                       • Both are greedy
– Practice (eg. communication)                      • May have different complexity (efﬁciency)
– Theory (eg. basis)                                  depending on the topology (eg. density) of the
– Algorithms (as a sub problem)                       network

Kruskal Algorithm                                        Winston (example 8)
1
• Append new arcs to the tree in increasing order             1                       2
of the arc length (making sure cycles are not                               2
3
2               4
created.                                               6
2
4   5                       3

4                   5

2
1                                                 1
1             1                   2               1                             2
2                                                 2
3 2                               3                                             3
4                             2               4
6                                                  6
2                                                 2
4         5               2           3           4         5                       3
4
4                          5                       4                         5

Prim’s Algorithm                                             Example
1
• Similar, except that we always have a sub-tree                  1             1               2
2
as a partial solution: the new arc we add                                                             3
2 2               4
connects a node in the existing sub-tree to a               6
2
node not yet in the sub-tree.                                   4         5           3           3
4
5
4

3
Comment
1
1                       2             • There are many variations of the MST
2
3       problem,eg.
2               4
6
2
– Additional capacity constraint (ﬂow problems)
4   5                       3           – Degree-constrained problems

5
4

Observation (CS students)
• K’s algorithm may take up to n iterations (n =
number of arcs, m= number of nodes)
• P’s algorithm is O(m2)
• Each iteration requires ﬁnding the shortest arc
• Thus, in general K’s is faster for sparse
available. This can be done in O(log n)
problems.
(appropriate data structure)
• Thus, K’s is an O(n log n) algorithm
• For dense problems n=(m)(m-1)/2, hence K’s
algorithm is O(m2 log n). If the network is sparse
(n=m) the algorithm is O(m log n).

4
Beware of Forests
• If the graph is not connected, there will be
more than one tree
• Both algorithms are capable of identifying such
cases

Example
2                              2
2              5
1                4                         6
1
1                                                      3

4                3
7
3                                      8
4

• This is a forest consisting of 2 trees

5

```
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
 views: 128 posted: 3/27/2010 language: English pages: 5
Description: Minimum Spanning Tree Spanning Tree Example Example