breadth first search l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Breadth-First Search PowerPoint Presentation
Download Presentation
Breadth-First Search

Loading in 2 Seconds...

play fullscreen
1 / 24
belle

Breadth-First Search - PowerPoint PPT Presentation

129 Views
Download Presentation
Breadth-First Search
An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Breadth-First Search Text • Read Weiss, § 9.3 (pp. 299-304) Breadth-First Search Algorithms

  2. Requirements • Can be used to attempt to visit all nodes of a graph in a systematic manner • Works with directed and undirected graphs • Works with weighted and unweighted graphs

  3. Overview Breadth-first search starts with given node F C A B D H 0 G E Task: Conduct a breadth-first search of the graph starting with node D

  4. Overview Breadth-first search starts with given node Then visits nodes adjacent in some specified order (e.g., alphabetical) Like ripples in a pond F C A B D H 0 G E 1 Nodes visited: D

  5. Overview Breadth-first search starts with given node Then visits nodes adjacent in some specified order (e.g., alphabetical) Like ripples in a pond F C A B D H 0 G E 1 Nodes visited: D, C

  6. Overview Breadth-first search starts with given node Then visits nodes adjacent in some specified order (e.g., alphabetical) Like ripples in a pond F C A B D H 0 G E 1 Nodes visited: D, C, E

  7. Overview Breadth-first search starts with given node Then visits nodes adjacent in some specified order (e.g., alphabetical) Like ripples in a pond F C A B D H 0 G E 1 Nodes visited: D, C, E, F

  8. Overview When all nodes in ripple are visited, visit nodes in next ripples F C A B D H 0 G E 1 2 Nodes visited: D, C, E, F, G

  9. Overview When all nodes in ripple are visited, visit nodes in next ripples F C A B D H 0 3 G E 1 2 Nodes visited: D, C, E, F, G, H

  10. Overview When all nodes in ripple are visited, visit nodes in next ripples 4 F C A B D H 0 3 G E 1 2 Nodes visited: D, C, E, F, G, H, A

  11. Overview When all nodes in ripple are visited, visit nodes in next ripples 4 F C A B D H 0 3 G E 1 2 Nodes visited: D, C, E, F, G, H, A, B

  12. Walk-Through Enqueued Array F C A Q  B D H G E How is this accomplished? Simply replace the stack with a queue! Rules: (1) Maintain an enqueued array. (2) Visit node when dequeued.

  13. Walk-Through Enqueued Array F C A Q  D B D H G E Nodes visited: Enqueue D. Notice, D not yet visited.

  14. Walk-Through Enqueued Array F C A Q  C  E  F B D H G E Nodes visited: D Dequeue D. Visit D. Enqueue unenqueued nodes adjacent to D.

  15. Walk-Through Enqueued Array F C A Q  E  F B D H G E Nodes visited: D, C Dequeue C. Visit C. Enqueue unenqueued nodes adjacent to C.

  16. Walk-Through Enqueued Array F C A Q  F  G B D H G E Nodes visited: D, C, E Dequeue E. Visit E. Enqueue unenqueued nodes adjacent to E.

  17. Walk-Through Enqueued Array F C A Q  G B D H G E Nodes visited: D, C, E, F Dequeue F. Visit F. Enqueue unenqueued nodes adjacent to F.

  18. Walk-Through Enqueued Array F C A Q  H B D H G E Nodes visited: D, C, E, F, G Dequeue G. Visit G. Enqueue unenqueued nodes adjacent to G.

  19. Walk-Through Enqueued Array F C A Q  A  B B D H G E Nodes visited: D, C, E, F, G, H Dequeue H. Visit H. Enqueue unenqueued nodes adjacent to H.

  20. Walk-Through Enqueued Array F C A Q  B B D H G E Nodes visited: D, C, E, F, G, H, A Dequeue A. Visit A. Enqueue unenqueued nodes adjacent to A.

  21. Walk-Through Enqueued Array F C A Q empty B D H G E Nodes visited: D, C, E, F, G, H, A, B Dequeue B. Visit B. Enqueue unenqueued nodes adjacent to B.

  22. Walk-Through Enqueued Array F C A Q empty B D H G E Nodes visited: D, C, E, F, G, H, A, B Q empty. Algorithm done.

  23. Consider Trees • What do we call a breadth-first traversal on trees?