2

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

Mureinik
  • 297,002
  • 52
  • 306
  • 350
random
  • 21
  • 1
  • I'd start [here](https://en.wikipedia.org/wiki/Breadth-first_search#Analysis) and [here](https://en.wikipedia.org/wiki/Depth-first_search#Complexity) – Mureinik Jun 19 '21 at 09:07
  • Does this answer your question? [Why is the time complexity of both DFS and BFS O( V + E )](https://stackoverflow.com/questions/11468621/why-is-the-time-complexity-of-both-dfs-and-bfs-o-v-e) – VLAZ Jun 19 '21 at 09:07

1 Answers1

1

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.