I\'ve been presented the following problem in University:
Let G = (V, E) be an (undirected) graph with costs ce >= 0 on the edges e<
You've got the right idea, though you can do better than BFS for the shortest-path search if you store the tree the right way.
Say one node r in T is the root (you can pick any node and BFS from there to generate this structure if you have marked the tree edges in a matrix or adjacency-list graph structure), and each other node has a parent pointer and a depth count. To find the shortest path between a and b in T:
Proof of the validity of this algorithm is left as an exercise to the reader. This is O(|V|) like BFS, but will also generally be faster. Only a few MST configurations would actually require O(|V|) time in practice. Of course, generating the parent-link tree takes O(|V|) time to begin with, so this only help in some circumstances, such as if you use an MST-building algorithm that naturally creates this structure in the process of determining the MST.
As another commenter said, note that if there is a MST for a graph it is connected, so |V| <= |E| and thus O(|V|) < O(|E|).
Also, to fix the tree in O(|V|) time, if needed, simply find the longest edge on the cycle and remove it, replacing it with the new edge. Doing this efficiently with a parent-link MST is also an exercise for the reader.
I think a BFS would suffice. And it's complexity is O(|V| + |E|) but in a tree |E| is less than |V| so it's O(2|V|) that is O(|V|)
I believe your step Find in T the shortest path from a to b
is an order E operation.