Learn
Practice
Newsletter
Resources
Mobile
New
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Binary Tree Postorder Traversal
Bookmark
Input
Small (5 nodes)
Example 1
Complete Tree
Custom
tree
=
[4, 2, 5, 1, 3]
4
2
5
1
3
stack
result
postorder: Left, Right, Root
4
2
5
1
3
stack
result
postorder: Left, Right, Root
4
2
5
1
3
curr
stack
4
2
top
result
push
2
onto stack
4
2
5
1
3
stack
4
2
1
top
result
peek top:
1
4
2
5
1
3
last
stack
4
2
top
result
1
unvisited right child
3
, go right first
4
2
5
1
3
last
stack
4
2
3
top
result
1
peek top:
3
4
2
5
1
3
last
stack
4
2
top
result
1
3
peek top:
2
4
2
5
1
3
last
stack
4
top
result
1
3
2
peek top:
4
4
2
5
1
3
last
stack
4
5
top
result
1
3
2
peek top:
5
4
2
5
1
3
last
stack
4
top
result
1
3
2
5
peek top:
4
4
2
5
1
3
stack
result
1
3
2
5
4
return [1, 3, 2, 5, 4]
algo
master
.
io
Step:
Start: postorder traversal visits Left, then Right, then Root
0 / 38
Input
Small (5 nodes)
Example 1
Complete Tree
Custom
tree
=
[4, 2, 5, 1, 3]
0 / 38
algo
master
.
io
Step:
Start: postorder traversal visits Left, then Right, then Root