Sei sulla pagina 1di 6

Search

Responsive Menu
Statistics How To
Statistics for the rest of us!
Statistics How To
Minimum Spanning Tree: Definition, Examples, Prim’s Algorithm
Types of Graphs > Minimum Spanning Tree

Contents:

What is a Minimum Spanning Tree?


Finding Minimum Spanning Trees
Kruskal’s Algorithm
Prim’s algorithm
Boruvka’s algorithm (new window)
Real life applications for MSTs.
What is a Minimum Spanning Tree?
A minimum spanning tree is a special kind of tree that minimizes the lengths (or “weights”) of the
edges of the tree. An example is a cable company wanting to lay line to multiple neighborhoods;
by minimizing the amount of cable laid, the cable company will save money.

A tree has one path joins any two vertices. A spanning tree of a graph is a tree that:

Contains all the original graph’s vertices.


Reaches out to (spans) all vertices.
Is acyclic. In other words, the graph doesn’t have any nodes which loop back to itself.
acyclic

Even the simplest of graphs can contain many spanning trees. For example, the following graph:
minimum spanning tree 2

…has many possibilities for spanning trees, including:


mst1

Finding Minimum Spanning Trees


As you can probably imagine, larger graphs have more nodes and many more possibilities for
subgraphs. The number of subgraphs can quickly reach into the millions, or billions, making it
very difficult (and sometimes impossible) to find the minimum spanning tree. Additionally, the
lengths usually have different weights; one 5m long edge might be given a weight of 5, another of
the same length might be given a weight of 7.

A few popular algorithms for finding this minimum distance include: Kruskal’s algorithm, Prim’s
algorithm and Boruvka’s algorithm. These work for simple spanning trees. For more complex
graphs, you’ll probably need to use software.

Kruskal’s algorithm example


Find the edge with the least weight and highlight it. For this example graph, I’ve highlighted the
top edge (from A to C) in red. It has the lowest weight (of 1):
kruskals-algorithm-1a

Find the next edge with the lowest weight and highlight it:
kruskals-algorithm-2a

Continue selecting the lowest edges until all nodes are in the same tree.
Notes:

If you have more than one edge with the same weight, choose an edge with the lowest weight.
Be careful not to complete a cycle (route one node back to itself). If your choice completes a
cycle, discard your choice and move onto the next largest weight.
The finished minimum spanning tree for this example looks like this:
kruskals-algorithm-3a

What is Prim’s Algorithm?


Prim’s algorithm is one way to find a minimum spanning tree (MST).

prim's algorithm
A minimum spanning tree (shown in red) minimizes the edges (weights) of a tree.

How to Run Prim’s Algorithm


Step 1: Choose a random node and highlight it. For this example, I’m choosing node C.
prim 1a

Step 2: Find all of the edges that go to un-highlighted nodes. For this example, node C has three
edges with weights 1, 2, and 3. Highlight the edge with the lowest weight. For this example, that’s
1.
prim 2a

Step 3: Highlight the node you just reached (in this example, that’s node A).

Step 4: Look at all of the nodes highlighted so far (in this example, that’s A And C). Highlight the
edge with lowest weight (in this example, that’s the edge with weight 2).
prim 3a
Note: if you have have more than one edge with the same weight, pick a random one.

Step 5: Highlight the node you just reached.

Step 6: Highlight the edge with the lowest weight. Choose from all of the edges that:

Come from all of the highlighted nodes.


Reach a node that you haven’t highlighted yet
Step 7: Repeat steps 5 and 6 until you have no more un-highlighted nodes. For this particular
example, the specific steps remaining are:

a. Highlight node E.
b. Highlight edge 3 and then node D.
c. Highlight edge 5 and then node B.
d. Highlight edge 6 and then node F.
e. Highlight edge 9 and then node G.
The finished graph is shown at the bottom right of this image:
prim 4

That’s it!

Real Life Applications


Minimum spanning trees are used for network designs (i.e. telephone or cable networks). They are
also used to find approximate solutions for complex mathematical problems like the Traveling
Salesman Problem. Other, diverse applications include:

Cluster Analysis.
Real-time face tracking and verification (i.e. locating human faces in a video stream).
Protocols in computer science to avoid network cycles.
Entropy based image registration.
Max bottleneck paths.
Dithering (adding white noise to a digital recording in order to reduce distortion).
------------------------------------------------------------------------------

Need help with a homework or test question? With Chegg Study, you can get step-by-step
solutions to your questions from an expert in the field. Your first 30 minutes with a Chegg tutor is
free!

Statistical concepts explained visually - Includes many concepts such as sample size, hypothesis
tests, or logistic regression, explained by Stephanie Glen, founder of StatisticsHowTo.

Comments? Need to post a correction? Please post a comment on our Facebook page.
Check out our updated Privacy policy and Cookie Policy

By Stephanie | January 28, 2016 | Statistics How To |


← Imaginary Numbers: Simple Definition, Real Life UsesDisjoint Events: Definition, Examples

Find an article
Search
Search

Feel like "cheating" at Statistics? Check out the grade-increasing book that's recommended
reading at top universities!

Need help NOW with a homework problem? Click here!

Copyright ©2019 Statistics How To | Theme by: Theme Horse | Powered by: WordPress
We encourage you to view our updated policy on cookies and affiliates. Find out more.
Okay, thanks

Dijkstra's algorithm
Read in another language
Watch
Edit
Not to be confused with Dykstra's projection algorithm.
Dijkstra's algorithm (or Dijkstra's Shortest Path First algorithm, SPF algorithm)[1] is an algorithm
for finding the shortest paths between nodes in a graph, which may represent, for example, road
networks. It was conceived by computer scientist Edsger W. Dijkstra in 1956 and published three
years later.[2][3][4]

Dijkstra's algorithm
Dijkstra Animation.gif
Dijkstra's algorithm to find the shortest path between a and b. It picks the unvisited vertex with the
lowest distance, calculates the distance through it to each unvisited neighbor, and updates the
neighbor's distance if smaller. Mark visited (set to red) when done with neighbors.
Class
Search algorithm
Data structure
Graph
Worst-case performance
{\displaystyle O(|E|+|V|\log |V|)} O(|E|+|V|\log |V|)
The algorithm exists in many variants. Dijkstra's original algorithm found the shortest path
between two given nodes,[4] but a more common variant fixes a single node as the "source" node
and finds shortest paths from the source to all other nodes in the graph, producing a shortest-path
tree.

For a given source node in the graph, the algorithm finds the shortest path between that node and
every other.[5]:196–206 It can also be used for finding the shortest paths from a single node to a
single destination node by stopping the algorithm once the shortest path to the destination node
has been determined. For example, if the nodes of the graph represent cities and edge path costs
represent driving distances between pairs of cities connected by a direct road (for simplicity,
ignore red lights, stop signs, toll roads and other obstructions), Dijkstra's algorithm can be used to
find the shortest route between one city and all other cities. A widely used application of shortest
path algorithm is network routing protocols, most notably IS-IS (Intermediate System to
Intermediate System) and Open Shortest Path First (OSPF). It is also employed as a subroutine in
other algorithms such as Johnson's.

The Dijkstra algorithm uses labels that are positive integers or real numbers, which are totally
ordered. It can be generalized to use any labels that are partially ordered, provided the subsequent
labels (a subsequent label is produced when traversing an edge) are monotonically non-
decreasing. This generalization is called the Generic Dijkstra shortest-path algorithm.[6]

Dijkstra's original algorithm does not use a min-priority queue and runs in time {\displaystyle O(|
V|^{2})} O(|V|^{2}) (where {\displaystyle |V|} |V| is the number of nodes). The idea of this
algorithm is also given in Leyzorek et al. 1957. The implementation based on a min-priority queue
implemented by a Fibonacci heap and running in {\displaystyle O(|E|+|V|\log |V|)} O(|E|+|V|\log |
V|) (where {\displaystyle |E|} |E| is the number of edges) is due to Fredman & Tarjan 1984. This is
asymptotically the fastest known single-source shortest-path algorithm for arbitrary directed
graphs with unbounded non-negative weights. However, specialized cases (such as
bounded/integer weights, directed acyclic graphs etc.) can indeed be improved further as detailed
in Specialized variants.

In some fields, artificial intelligence in particular, Dijkstra's algorithm or a variant of it is known


as uniform cost search and formulated as an instance of the more general idea of best-first search.
[7]

History

Algorithm
Edit

Illustration of Dijkstra's algorithm finding a path from a start node (lower left, red) to a goal node
(upper right, green) in a robot motion planning problem. Open nodes represent the "tentative" set
(aka set of "unvisited" nodes). Filled nodes are visited ones, with color representing the distance:
the greener, the closer. Nodes in all the different directions are explored uniformly, appearing
more-or-less as a circular wavefront as Dijkstra's algorithm uses a heuristic identically equal to 0.
Let the node at which we are starting be called the initial node. Let the distance of node Y be the
distance from the initial node to Y. Dijkstra's algorithm will assign some initial distance values and
will try to improve them step by step.

Mark all nodes unvisited. Create a set of all the unvisited nodes called the unvisited set.
Assign to every node a tentative distance value: set it to zero for our initial node and to infinity for
all other nodes. Set the initial node as current.[13]
For the current node, consider all of its unvisited neighbours and calculate their tentative distances
through the current node. Compare the newly calculated tentative distance to the current assigned
value and assign the smaller one. For example, if the current node A is marked with a distance of
6, and the edge connecting it with a neighbour B has length 2, then the distance to B through A
will be 6 + 2 = 8. If B was previously marked with a distance greater than 8 then change it to 8.
Otherwise, keep the current value.
When we are done considering all of the unvisited neighbours of the current node, mark the
current node as visited and remove it from the unvisited set. A visited node will never be checked
again.
If the destination node has been marked visited (when planning a route between two specific
nodes) or if the smallest tentative distance among the nodes in the unvisited set is infinity (when
planning a complete traversal; occurs when there is no connection between the initial node and
remaining unvisited nodes), then stop. The algorithm has finished.
Otherwise, select the unvisited node that is marked with the smallest tentative distance, set it as
the new "current node", and go back to step 3.
When planning a route, it is actually not necessary to wait until the destination node is "visited" as
above: the algorithm can stop once the destination node has the smallest tentative distance among
all "unvisited" nodes (and thus could be selected as the next "current").

Potrebbero piacerti anche