Breadth First Search and Depth First Search
Greatest problem in Computer Science Has lead to a lot of new ideas and data structures Search engines before Google dawned were very slow. Search engines even took 10 minutes to search.
Trees were created to store data Finding the data requires searching Graph searching and Tree Searching algorithms that we are going to learn today are BFS and DFS.
Breadth First Search b- branching d - depth
Breadth First Search
Breadth First Search
Breadth First Search
Breadth First Search
Breadth First Search
Worst case performance – O(b d ) Worst case space complexity - O(b d ) Implemented using a queue. But you are free to experiment with other data structures
Depth First Search b – branching d - depth
Depth First Search
Depth First Search
Depth First Search
Depth First Search
Depth First Search
Depth First Search
Depth First Search
Can you guess the Time and Space complexity of the DFS?
Yes, Time complexity of DFS is O(b d )
Worst case performance – O(b d ) Worst case space complexity - O(d) Implemented using a queue. But you are free to experiment with other data structures
What will you do if there is a loop in DFS? What are the data structures to use? In order to reduce space complexity in BFS, why don’t we just delete all the nodes that are visited until the previous depth?