Time Complexity of DFS and BFS

Viewed 245

I'm new to the search strategies. Does anyone know how to analyze the time complexity of the figure below?

Algorithm for DFS and BFS

1 Answers

The best way to analyse time complexity for such problems is to check how many times a vertex and edge is accessed. Since in both BFS and DFS a single node is only visited once we can say it would be O(V + E) where v is the number of vertices and E is the number of edges.

Related