minimum spanning tree (connect all vertices in undirected graphic)
both are greedy algorithm
- kruskal algorithm, O(ElgV)
- make set for each vertex. set only contains one vertex
- sort G.E in non-descending order by weight of edge.
- for each edge(u,v), if they are not in same set, add edge(u,v) to A. and union u and v to one set.
- prime algorithm O(ElgV) ,
- initialise all u.key=infinity max, u.pi = nil
- set root.key = 0
- make all nodes as a priority queue, root is in the first
- take node from the queue and update its key of adjacent nodes to w(u,v)
- repeat last step