Download presentation

Presentation is loading. Please wait.

Published byWalter Hawkins Modified over 2 years ago

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

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

3
Pseudo-Code for Breadth-First Traversal 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

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

5
Breadth-First Search A BC DEFG Queue: Current: A

6
Breadth-First Search A BC DEFG Queue: Current: A A

7
Breadth-First Search A BC DEFG Queue: Current: A A A

8
Breadth-First Search A BC DEFG Queue: Current: B A A A

9
Breadth-First Search A BC DEFG Queue: Current: CBCB A A A

10
Breadth-First Search A BC DEFG Queue: Current: B A A CBCB

11
Breadth-First Search A BC DEFG Queue: Current: B C A B

12
Breadth-First Search A BC DEFG Queue: Current: DCDC B A B

13
Breadth-First Search A BC DEFG Queue: Current: EDCEDC B A B

14
Breadth-First Search A BC DEFG Queue: Current: C EDCEDC A B

15
Breadth-First Search A BC DEFG Queue: Current: C A B C EDED

16
Breadth-First Search A BC DEFG Queue: Current: C A B C FEDFED

17
Breadth-First Search A BC DEFG Queue: Current: C A B C GFEDGFED

18
Breadth-First Search A BC DEFG Queue: Current: D A B C GFEDGFED

19
A B C D Breadth-First Search A BC DEFG Queue: Current: D GFEGFE

20
Breadth-First Search A BC DEFG A B C D Queue: Current: E GFEGFE

21
Breadth-First Search A BC DEFG Queue: Current: E GFGF A B C D E

22
Breadth-First Search A BC DEFG Queue: Current: F GFGF A B C D E

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

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

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

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

27
Time and Space Complexity for Breadth-First Search Alg. Time Complexity Time Complexity –Consider each node twiceO(n) when put on queue when put on queue when taken from queue when taken from queue

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

Similar presentations

OK

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Moving message display ppt online Ppt on palm island in dubai Lockout tagout ppt online Ppt on statistics and probability questions Ppt on conservation of wildlife and natural vegetation types Ppt on ms project 2010 Ppt on verb forms Ppt on two point perspective definition Ppt on spices and herbs Ppt on automobile related topics on personality