Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

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

11

12

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

24

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?

26


Download ppt "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."

Similar presentations


Ads by Google