Given a connected undirected graph $G=(V,E)$ and a weight function $w: E to {1,2}$, suggest an efficient algorithm that finds an MST of the graph.
After a few clarifications, the algorithm should run in time $O(|V|+|E|)$. I believe we can do this because of the fact that there are two types of weight of edges. I tried the following idea, which did not work (I had a contradicting example):
Run BFS on the graph, and output the BFS tree.
I thought that shortest paths in this case would also mean easiest trees, but this is not the case. I also tried to make each edge $e$ such that $w(e)=2$ into two edges of weight $1$ but my friend also gave a contradicting example. Can you help please? This is not a homework question, this is a previous exam question as I am studying for my algorithms exam which is soon.
Asked By : TheNotMe
Answered By : lPlant
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/28635