Take the 2-minute tour ×
Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. It's 100% free, no registration required.

Could anyone point me to simple tutorial on greedy algorithm for Minimum Spanning tree - Kruskal's and Prims' Method

I am looking for a tutorial which

  • does not include all the mathematical notation
  • explains algorithm along with the analysis of the running time.
share|improve this question

1 Answer 1

up vote 5 down vote accepted

Here is a simple definition for greedy algorithm.

There are many greedy algorithms for different problems and in order to understand them you must also know well the subject of the problem. This question on stackoverflow gives some examples of greedy algorithms usage.

EDIT : After you made your question more clear I will try to sketch the algorithms by using "minimum mathematical notation". Both the Kruskal's and Prim's algorithms build MST in connected graph.

Let we have graph G with vertices V and edges E.

Prim's algorithm

  1. Select some vertex r from V and add it to the tree. r will be the root of the tree
  2. Until all vertexes V are in the tree :

    Find the shortest edge from E that has one end in the already constructed tree and the other in some of the vertices of the graph that are not in the tree and add the edge and the new vertex to the tree

  3. When the condition in step 2. is not correct you will have the MST constructed

Kruskal's algorithm

  1. Construct forest of trees where each tree is a single vertex from V
  2. Until all trees are connected into single one :

    Find the shortest edge from E that connects two unconnected trees and connect them with it. That step constructs from two trees a new one.

  3. When the condition in step 2. is not correct all the trees will be connected into single one that is the MST

Note: After each iteration we have a tree/trees because there is no way to add a edge that forms a cycle

Note: The tree consists of vertexes and edges (it is kind of graph). When adding a vertex to the tree we add it to the set of vertices and when adding edge - to the set of edges.

Running Time

This part really needs mathematical notation and depends on specifics in the implementation of the algorithms, so I will leave it only with some answers and links to Wikipedia,where there are some general explanations.

Prim's Algorithm = O(E.log E) = O(E. log V)

Kruskal's Algorithm = O(E.log E) = O(E. log V)

Please read the explanations and ask only the things that are unclear to you(maybe in different question if they are related to the asymptotic notations)

"Greedy Part"

The greedy part in both of the algorithms is choosing to add the shortest edge to the tree. The shortest edge is the logically optimal choice when constructing Minimal Spanning Trees.

share|improve this answer
    
Links die. Please update your post with the relevant content. –  The Unfun Cat Nov 12 '12 at 21:06
    
I edited the post to reflect the updated question. –  Anton Nov 13 '12 at 9:08
    
I think the answer will be stronger by including the simple definition in addition to linking to it (always making the locally optimal choice). –  Joe Nov 15 '12 at 4:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.