Prim and Kruskal's algorithms complexity
问题 Given an undirected connected graph with weights. w:E->{1,2,3,4,5,6,7} - meaning there is only 7 weights possible. I need to find a spanning tree using Prim's algorithm in O(n+m) and Kruskal's algorithm in O( m*a(m,n)). I have no idea how to do this and really need some guidance about how the weights can help me in here. 回答1: You can sort edges weights faster. In Kruskal algorithm you don't need O(M lg M) sort, you just can use count sort (or any other O(M) algorithm). So the final complexity