Download presentation
Presentation is loading. Please wait.
Published byAdrienne Wyand Modified over 10 years ago
1
Alyce Brady CS 470: Data Structures CS 510: Computer Algorithms Post-order Traversal: Left Child - Right Child - Root Depth-First Search
2
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root
3
A BC DEFG HIJKLMNO
4
A BC DEFG HIJKLMNO
5
A BC DEFG HIJKLMNO H H
6
A BC DEFG HIJKLMNO H H
7
A BC DEFG HIJKLMNO H H
8
A BC DEFG HIJKLMNO H I
9
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I
10
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D
11
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D
12
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D
13
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D
14
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J
15
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J
16
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J
17
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K
18
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K
19
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E
20
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E
21
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B
22
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B
23
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B
24
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B
25
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B
26
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L
27
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L
28
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L
29
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M
30
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M
31
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M F
32
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M F
33
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M F
34
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M F
35
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M F N
36
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M F N
37
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M F N
38
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M F N O
39
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M F N O
40
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M F N O G
41
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M F N O G
42
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M F N O G C
43
A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M F N O G C
44
Post-order Traversal: Left Child - Right Child - Root A BC DEFG HIJKLMNO H I D J K E B L M F N O G C A
45
Post-order Traversal: Left Child - Right Child - Root A BC DEFG HIJKLMNO H I D J K E B L M F N O G C A
46
Pseudo-Code for Post-order Traversal post-traverse post-traverse left subtree post-traverse right subtree visit current node e.g., print value
47
Time and Space Complexity for Depth-First Search Algs. Time Complexity Time Complexity –Visit each node three timesO(n) first arrival first arrival return from left child return from left child return from right child return from right child
48
Space Complexity Space Complexity –Stack to handle recursion Stack length = depth of tree Stack length = depth of tree best case: lg n best case: lg n worst case: n O(n) worst case: n O(n) Time and Space Complexity for Depth-First Search Algs.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.