You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In BFS, at the leaves -> if we have N items stored in the balanced tree, then there will be N/2 leave nodes.
So we have to store O(N) items if we want to traverse a tree that contains N items!!!
In DFS, we ahve to backtrack (pop item from stack): so basically we just have to store as many items n the stack as the height of the tree -> which is log N !!!
so the memory complexity will be O(log N)
That's why depth-first search is preferred most of the times. However, there may be some situations where VFS is better: AI, robot movements,..
Shortest Path Algorithms
Dijkstra Algorithm
Bellman-Ford Algorithm
DAG Shortest Path
FOREX Problem
Longest Path
About
A collection and notes of Data Structure and Algorithm problems written in Java