Learn
Practice
Newsletter
Resources
Mobile
New
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Binary Tree Inorder Traversal
Bookmark
Input
Small (5 nodes)
Example 1
Complete Tree
Custom
tree
=
[4, 2, 5, 1, 3]
4
2
5
1
3
stack
result
inorder: left, then root, then right
4
2
5
1
3
stack
result
inorder: left, then root, then right
4
2
curr
5
1
3
stack
4
top
result
current = current.left =
2
4
2
5
1
curr
3
stack
4
2
1
top
result
stack.push(
1
)
4
2
5
1
#1
curr
3
stack
4
2
top
result
1
result +=
1
4
2
#2
curr
5
1
#1
3
stack
4
top
result
1
2
result +=
2
4
2
#2
5
1
#1
3
stack
4
3
top
result
1
2
no left child:
current = null
4
2
#2
5
1
#1
3
#3
stack
4
top
result
1
2
3
no right child:
current = null
4
#4
2
#2
5
curr
1
#1
3
#3
stack
result
1
2
3
4
current = current.right =
5
4
#4
2
#2
5
curr
1
#1
3
#3
stack
result
1
2
3
4
current = stack.pop() =
5
4
#4
2
#2
5
#5
1
#1
3
#3
stack
result
1
2
3
4
5
return [1, 2, 3, 4, 5]
algo
master
.
io
Step:
Start: inorder traversal visits Left -> Root -> Right
0 / 27
Input
Small (5 nodes)
Example 1
Complete Tree
Custom
tree
=
[4, 2, 5, 1, 3]
0 / 27
algo
master
.
io
Step:
Start: inorder traversal visits Left -> Root -> Right