we consider a graph G= (V, E), with n=|V| and m=|E|.
Describe an O(n+m) time algorithm to find such a vertex w. Hint: a depth-first search from u might be helpful.
A graph G=(V,E), with n=|v| and m=|E|
If the time complexity is O(n+m) then this is depth- first-search because in depth-first-search (DFS)
Recursively explore graph, backtracking as necessary. In DFS stack data structure is used.
therefore, O( summation of |adj [V]|)= O(E)
That's why we can say the time complexity of DFS is O(V+E) or O(m+n)
Get Answers For Free
Most questions answered within 1 hours.