Learn
Practice
Newsletter
Resources
Animations
New
F
Toggle theme
0
F
0
Toggle menu
← Back to All Animations
Subtree of Another Tree
Bookmark
Input
Example 1 (true)
Example 2 (false)
Match Mid-Tree (true)
Custom
tree
=
[3, 4, 5, 1, 2]
,
subTree
=
[4, 1, 2]
root
subRoot
3
4
5
1
2
4
1
2
stack
does
root
contain a copy of
subRoot
?
algo
master
.
io
Step:
Start: does root contain a subtree identical to subRoot?
0 / 12
Input
Example 1 (true)
Example 2 (false)
Match Mid-Tree (true)
Custom
tree
=
[3, 4, 5, 1, 2]
,
subTree
=
[4, 1, 2]
0 / 12
root
subRoot
3
4
5
1
2
4
1
2
stack
does
root
contain a copy of
subRoot
?
algo
master
.
io
Step:
Start: does root contain a subtree identical to subRoot?