Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Unique Binary Search Trees II
Bookmark
Input
Standard
Small
Larger
Custom
n
=
3
unique BSTs for 1..3
1
2
3
0 / 5
root 1
root 2
root 3
pick each value as the root, combine all
left
×
right
subtrees
unique BSTs for 1..3
1
2
3
0 / 5
root 1
root 2
root 3
pick each value as the root, combine all
left
×
right
subtrees
unique BSTs for 1..3
1
2
3
0 / 5
root 1
root 2
root 3
root
1
: left
∅
(1)
× right
[2..3]
(2)
=
2
unique BSTs for 1..3
1
2
3
1 / 5
root 1
root 2
root 3
1
2
3
BST
#1
: root
1
+ left & right subtrees
unique BSTs for 1..3
1
2
3
2 / 5
root 1
root 2
root 3
1
2
3
1
3
2
BST
#2
: root
1
+ left & right subtrees
unique BSTs for 1..3
1
2
3
2 / 5
root 1
root 2
root 3
1
2
3
1
3
2
root
2
: left
[1..1]
(1)
× right
[3..3]
(1)
=
1
unique BSTs for 1..3
1
2
3
3 / 5
root 1
root 2
root 3
1
2
3
1
3
2
2
1
3
BST
#3
: root
2
+ left & right subtrees
unique BSTs for 1..3
1
2
3
3 / 5
root 1
root 2
root 3
1
2
3
1
3
2
2
1
3
root
3
: left
[1..2]
(2)
× right
∅
(1)
=
2
unique BSTs for 1..3
1
2
3
4 / 5
root 1
root 2
root 3
1
2
3
1
3
2
2
1
3
3
1
2
BST
#4
: root
3
+ left & right subtrees
unique BSTs for 1..3
1
2
3
5 / 5
root 1
root 2
root 3
1
2
3
1
3
2
2
1
3
3
1
2
3
2
1
BST
#5
: root
3
+ left & right subtrees
unique BSTs for 1..3
1
2
3
5 / 5
root 1
root 2
root 3
1
2
3
1
3
2
2
1
3
3
1
2
3
2
1
5 unique BSTs for n = 3
algo
master
.
io
Step:
Generate every unique BST holding the values 1..3
0 / 9
Input
Standard
Small
Larger
Custom
n
=
3
0 / 9
algo
master
.
io
Step:
Generate every unique BST holding the values 1..3