Upload
sheryl-butler
View
231
Download
0
Embed Size (px)
DESCRIPTION
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.
Citation preview
Breadth First Search and Depth First Search
Searching Algorithms
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.
Why 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 Searchb- branchingd - depth
1
75
4
6
3
765
2
89
10
Breadth First Search 1
75
4
6
3
765
2
89
10
Breadth First Search 1
75
4
6
3
765
2
89
10
Breadth First Search 1
75
4
6
3
765
2
89
10
Breadth First Search 1
75
4
6
3
765
2
89
10
Breadth First Search 1
75
4
6
3
765
2
89
10
Worst case performance – O(bd)Worst case space complexity - O(bd)Implemented using a queue. But you are free
to experiment with other data structures
Properties of BFS
Assignment:
Depth First Search
Depth First Searchb – branchingd - depth
1
75
4
6
3
765
2
89
10
Depth First Search 1
75
4
6
3
765
2
89
10
Depth First Search 1
75
4
6
3
765
2
89
10
Depth First Search 1
75
4
6
3
765
2
89
10
Depth First Search 1
75
4
6
3
765
2
89
10
Depth First Search 1
75
4
6
3
765
2
89
10
Depth First Search 1
75
4
6
3
765
2
89
10
Depth First Search 1
75
4
6
3
765
2
89
10
Can you guess the Time and Space complexity of the DFS?
Can you guess the Time and Space complexity of the DFS?
Yes, Time complexity of DFS is O(bd)
Worst case performance – O(bd)Worst case space complexity - O(d)Implemented using a queue. But you are free
to experiment with other data structures
Properties of DFS
Answer for Breadth First Assignment
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?
Are you sure you know BFS and DFS?
THANK YOU!!- Mino De Raj