I need to write an algorithm in O(m) time to find the missing two edges of a minimum spanning tree. I am given a graph G(V,E) where m = |E| and n = |V| as an adjacency list, and T, a subset of G, with n-3 edges, representing some minimum spanning tree as a list.
I've tried using standard greedy algorithms but they would require checking for a cycle which makes it larger than O(m). Is there any way to check if a particular edge is the right one without the need of checking for cycles?
There are a few observations one can make:
These observations can be turned into an algorithm:
Since $m\geq (n-1)$, total processing time is $O(m)$.