380 likes | 666 Views
Clayton Andrews COT4810 1/31/08. Minimum Spanning Tree. Firstly, a graph. A graph is a series of nodes connected with edges. Types of Graphs. Connected All nodes can be reached by all other nodes by following some series of edges All nodes are reachable from all other nodes Disconnected
E N D
Clayton Andrews COT4810 1/31/08 Minimum Spanning Tree
Firstly, a graph • A graph is a series of nodes connected with edges.
Types of Graphs • Connected • All nodes can be reached by all other nodes by following some series of edges • All nodes are reachable from all other nodes • Disconnected • There exists a node that is not reachable from some other node by any series of edges • One or more nodes are not reachable from one or more other nodes
Types of Edges A B • Undirected • An edge goes to and from a node • An edge can be taken both directions • Edges show connections • Directed • Edges can specifically go to or from nodes • Edges can still be bidirectional • Edges can show a one way trip, visibility, etc.. C A B C
Types of Edges 2 • Unweighted • Edges have no values • Edges just show some sort of connection • These edges can show neighbours, possible paths, etc.. • Weighted • Edges have a value attached to them • These values could be distance, cost, time, etc...
What is a spanning tree? • A spanning tree is a sub-graph of another graph that connects all the nodes of the graph without forming a cycle(a loop) • The graph must be connected and be undirected
What is a minimum spanning tree? • If a graph has weights for its edges, than a minimum spanning tree is the spanning tree that gives the lowest total sum of the edges. • Basically, it connects all of the nodes together for the least total weight
Why should we care? • Why would anyone want to care about these trees that connect a series of nodes together? • A minimum spanning tree can be used for several things: • Identifying Clusters • Determining a central point of operations
For Example: • Determining the location of roads • Where they should be placed • What cities they should pass through
For Example: • Railroad Tracks • Where is a good central hub • What would cost us the least and be the quickest
For Example: • Airports and Flight paths • Where airports should be • What path a flight should take
Finding a minimum spanning tree • There are several ways to find a minimum spanning tree, but I am going to discuss the two most common methods • Prim's algorithmKruskal's algorithm
Prim's Algorithm • Prim's Algorithm starts by making a set with a single node inside • It then looks for the shortest edge that does not form a cycle and adds its node to a set • It keeps going until all nodes are consumed
Prim's Algorithm • Step 1: Pick an arbitrary starting node and put it into an empty set, X • Step 2: Look at the shortest edge coming from the set X • Step 3: Add the edge and add the node to the set • Step 4: Remove all edges that connect the set to itself • Step 5: If all nodes have not been added to set X, then repeat Steps 2 - 4 until all nodes have been added to the set X
The edge to A was the shortestfrom {D} so I added it to the set
The edge to B was the shortest edge from the set {A, D, F} so I added B to the set. The edge BD connects the set to itself, so it was removed
From the set {A, B, D, F} the edge to E is the shortest. E is added to the set and two edges are removed
From the set {A, B, D, E, F} the edge to C is the shortest. So, C is added to the set and an edge is removed
Finally, from the set {A, B, C, D, E, F} the edge to G is the shortest so add G and remove an edge
Now since all nodes are in the set, this is a minimum spanning tree
Kruskal's Algorithm • Kruskal's algorithm works by selecting the shortest edges and adds them if they do not form a cycle • If an edge forms a cycle, it removes it from the list of edges and keeps going • It keeps going as long as all edges have not been considered
Kruskal's Algorithm • Step 1: Put every node into a set by itself • Step 2: Choose the shortest edge that connects two of these sets, and merge these two sets into one • Step 3: Remove all edges that connect the set to itself • Step 4: If all edges have not been removed repeat steps 2 & 3 until there are no more remaining edges
The edge from set {A} to set {D} is tied for shortest with the edge from {C} to {E}, so just choose one, I chose {A} {D} to make {A, D}
Now the edge from {C} to {E} is the shortest, so they combine to become {C, E}
The shortest edge is now from {A, D} to {F} so they combine to become {A, D, F}
The shortest edge is from {A, D, F} to {B} so combine to {A, B, D, F}. The edge from B to D connects the set to itself, it is removed
The shortest edge is from{A, B, D, F} to {C, E} so combine and remove the three edges that connect the new set to itself
Finally, the smallest edge is the edge to G from {A,B,C,D,E,F}, so combine these two sets and remove the edge that connects the new set to itself
Since all edges have been added or removed, there are no more edges to consider, this is a minimum spanning tree.
Both are fine • Both algorithms have the same time complexity, so it is usually up to the programmer to decide • Multiple minimum spanning trees can exist for a given graph, so these algorithms may produce different results for the same graph
Summary • Minimum Spanning Trees are an efficient way to connect all of the nodes of a graph • They have several real world applications • There are 2 very common, very straight-forward solutions
References • Wikipedia(www.wikipedia.com) • All graph images • All minimum spanning tree images • Information related to minimum spanning tree • http://citeseer.ist.psu.edu/nesetril00otakar.html • Information related to algorithms • http://www.mapsofworld.com/ • Map of Florida Railroads • http://www.this-town.com/ • Map of Florida Highways • http://www.airchive.com/ • Map of Airline Flight Paths
Homework • Name 2 algorithms used to find the minimum spanning tree of a graph. • What is another real world example of a use of a minimum spanning tree?