Unique Binary Search Trees
Let's explore the fascinating world of binary trees! You can imagine binary search trees like those decision trees in your favorite games. Our task is to determine how many unique binary search trees can be formed using a sequence of numbers from 1 to n.
Here's a hint: You'll need to use something called the Catalan number, which helps in determining the number of possible combinations.
Write a function unique_binary_search_trees(n: int) -> int that computes the number of unique binary search trees you can create with numbers ranging from 1 to n.
Example:
unique_binary_search_trees(3) # 5
This means you can arrange 1, 2, and 3 in 5 different unique binary search trees.
Here are a few more examples to guide you:
unique_binary_search_trees(2) # 2 unique_binary_search_trees(1) # 1 unique_binary_search_trees(4) # 14
Each node in the binary search tree should fulfill the condition that the left child is less than the parent and the right child is greater than the parent. With these rules in mind, how many trees can you form? Let's find out!
Inputs
Arg 1:
3Expected Output
5Actual Output