Download presentation
Presentation is loading. Please wait.
Published bySheryl Butler Modified over 9 years ago
1
Breadth First Search and Depth First Search
2
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.
3
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.
4
Breadth First Search b- branching d - depth 1 7 5 4 6 3 7 65 2 8 9 10
5
Breadth First Search 1 7 5 4 6 3 7 65 2 8 9 10
6
Breadth First Search 1 7 5 4 6 3 7 65 2 8 9 10
7
Breadth First Search 1 7 5 4 6 3 7 65 2 8 9 10
8
Breadth First Search 1 7 5 4 6 3 7 65 2 8 9 10
9
Breadth First Search 1 7 5 4 6 3 7 65 2 8 9 10
10
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
13
Depth First Search b – branching d - depth 1 7 5 4 6 3 7 65 2 8 9 10
14
Depth First Search 1 7 5 4 6 3 7 65 2 8 9 10
15
Depth First Search 1 7 5 4 6 3 7 65 2 8 9 10
16
Depth First Search 1 7 5 4 6 3 7 65 2 8 9 10
17
Depth First Search 1 7 5 4 6 3 7 65 2 8 9 10
18
Depth First Search 1 7 5 4 6 3 7 65 2 8 9 10
19
Depth First Search 1 7 5 4 6 3 7 65 2 8 9 10
20
Depth First Search 1 7 5 4 6 3 7 65 2 8 9 10
21
Can you guess the Time and Space complexity of the DFS?
22
Yes, Time complexity of DFS is O(b d )
23
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
25
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?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.