1 / 28

Alyce Brady CS 470: Data Structures CS 510: Computer Algorithms

Breadth-First Binary Tree Traversal Algorithm. Alyce Brady CS 470: Data Structures CS 510: Computer Algorithms. Reminder: Breadth-First Traversal. A. B. C. D. E. F. G. A B C D E F G. breadth-first-traversal put root node onto a queue while the queue is not empty

corine
Download Presentation

Alyce Brady CS 470: Data Structures CS 510: Computer Algorithms

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Breadth-First Binary Tree Traversal Algorithm Alyce Brady CS 470: Data Structures CS 510: Computer Algorithms

  2. Reminder:Breadth-First Traversal A B C D E F G A B C D E F G

  3. breadth-first-traversal put root node onto a queue while the queue is not empty dequeue the next node visit the node e.g., print value enqueue the left child node enqueue the right child node Pseudo-Code forBreadth-First Traversal

  4. Breadth-First Search Queue: A B C Current: D E F G A B C D E F G

  5. Breadth-First Search Queue: A A B C Current: D E F G

  6. Breadth-First Search Queue: A A B C Current: D E F G A

  7. Breadth-First Search Queue: A B C Current: D E F G A A

  8. Breadth-First Search Queue: B A B C Current: D E F G A A

  9. Breadth-First Search Queue: C B A B C Current: D E F G A A

  10. Breadth-First Search Queue: C B A B C Current: D E F G B A

  11. Breadth-First Search Queue: C A B C Current: D E F G B A B

  12. Breadth-First Search Queue: D C A B C Current: D E F G B A B

  13. Breadth-First Search Queue: E D C A B C Current: D E F G B A B

  14. Breadth-First Search Queue: E D C A B C Current: D E F G C A B

  15. Breadth-First Search Queue: E D A B C Current: D E F G C A B C

  16. Breadth-First Search Queue: F E D A B C Current: D E F G C A B C

  17. Breadth-First Search Queue: G F E D A B C D E F G Current: C A B C

  18. Breadth-First Search Queue: G F E D A B C D E F G Current: D A B C

  19. Breadth-First Search Queue: G F E A B C D E F G Current: D A B C D

  20. Breadth-First Search Queue: G F E A B C D E F G Current: E A B C D

  21. Breadth-First Search Queue: G F A B C D E F G Current: E A B C D E

  22. Breadth-First Search Queue: G F A B C D E F G Current: F A B C D E

  23. Breadth-First Search Queue: G A B C D E F G Current: F A B C D E F

  24. Breadth-First Search Queue: G A B C D E F G Current: G A B C D E F

  25. Breadth-First Search Queue: A B C D E F G Current: G A B C D E F G

  26. Breadth-First Search A B C D E F G A B C D E F G

  27. Time Complexity Consider each node twice O(n) when put on queue when taken from queue Time and Space Complexityfor Breadth-First Search Alg.

  28. Space Complexity Queue to handle unexplored nodes Queue length = width of lowest level (n/2) O(n) Time and Space Complexityfor Breadth-First Search Alg.

More Related