breadth first search and depth first search. greatest problem in computer science has lead to a lot...

26
Breadth First Search and Depth First Search Searching Algorithms

Upload: sheryl-butler

Post on 17-Jan-2018

231 views

Category:

Documents


0 download

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.

TRANSCRIPT

Page 1: 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

Breadth First Search and Depth First Search

Searching Algorithms

Page 2: 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

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?

Page 3: 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

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.

Page 4: 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

Breadth First Searchb- branchingd - depth

1

75

4

6

3

765

2

89

10

Page 5: 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

Breadth First Search 1

75

4

6

3

765

2

89

10

Page 6: 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

Breadth First Search 1

75

4

6

3

765

2

89

10

Page 7: 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

Breadth First Search 1

75

4

6

3

765

2

89

10

Page 8: 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

Breadth First Search 1

75

4

6

3

765

2

89

10

Page 9: 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

Breadth First Search 1

75

4

6

3

765

2

89

10

Page 10: 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

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

Page 11: 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

Assignment:

Page 12: 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

Depth First Search

Page 13: 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

Depth First Searchb – branchingd - depth

1

75

4

6

3

765

2

89

10

Page 14: 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

Depth First Search 1

75

4

6

3

765

2

89

10

Page 15: 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

Depth First Search 1

75

4

6

3

765

2

89

10

Page 16: 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

Depth First Search 1

75

4

6

3

765

2

89

10

Page 17: 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

Depth First Search 1

75

4

6

3

765

2

89

10

Page 18: 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

Depth First Search 1

75

4

6

3

765

2

89

10

Page 19: 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

Depth First Search 1

75

4

6

3

765

2

89

10

Page 20: 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

Depth First Search 1

75

4

6

3

765

2

89

10

Page 21: 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

Can you guess the Time and Space complexity of the DFS?

Page 22: 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

Can you guess the Time and Space complexity of the DFS?

Yes, Time complexity of DFS is O(bd)

Page 23: 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

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

Page 24: 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

Answer for Breadth First Assignment

Page 25: 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

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?

Page 26: 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

THANK YOU!!- Mino De Raj