26
Breadth First Search and Depth First Search Searching Algorithms

Searching Algorithms

  • Upload
    eunice

  • View
    70

  • Download
    3

Embed Size (px)

DESCRIPTION

Searching Algorithms. Breadth First Search and Depth First Search. Why Search?. Greatest problem in Computer Science Has lead to a lot of new ideas and data structures Search engines before G oogle dawned were very slow. Search engines even took 10 minutes to search. - PowerPoint PPT Presentation

Citation preview

Page 1: Searching Algorithms

Breadth First Search and Depth First Search

Searching Algorithms

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

Page 3: Searching Algorithms

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: Searching Algorithms

Breadth First Searchb- branchingd - depth

1

75

4

6

3

765

2

89

10

Page 5: Searching Algorithms

Breadth First Search 1

75

4

6

3

765

2

89

10

Page 6: Searching Algorithms

Breadth First Search 1

75

4

6

3

765

2

89

10

Page 7: Searching Algorithms

Breadth First Search 1

75

4

6

3

765

2

89

10

Page 8: Searching Algorithms

Breadth First Search 1

75

4

6

3

765

2

89

10

Page 9: Searching Algorithms

Breadth First Search 1

75

4

6

3

765

2

89

10

Page 10: Searching Algorithms

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: Searching Algorithms

Assignment:

Page 12: Searching Algorithms

Depth First Search

Page 13: Searching Algorithms

Depth First Searchb – branchingd - depth

1

75

4

6

3

765

2

89

10

Page 14: Searching Algorithms

Depth First Search 1

75

4

6

3

765

2

89

10

Page 15: Searching Algorithms

Depth First Search 1

75

4

6

3

765

2

89

10

Page 16: Searching Algorithms

Depth First Search 1

75

4

6

3

765

2

89

10

Page 17: Searching Algorithms

Depth First Search 1

75

4

6

3

765

2

89

10

Page 18: Searching Algorithms

Depth First Search 1

75

4

6

3

765

2

89

10

Page 19: Searching Algorithms

Depth First Search 1

75

4

6

3

765

2

89

10

Page 20: Searching Algorithms

Depth First Search 1

75

4

6

3

765

2

89

10

Page 21: Searching Algorithms

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

Page 22: Searching Algorithms

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

Yes, Time complexity of DFS is O(bd)

Page 23: Searching Algorithms

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: Searching Algorithms

Answer for Breadth First Assignment

Page 25: Searching Algorithms

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: Searching Algorithms

THANK YOU!!- Mino De Raj