Loading content...
Given a positive integer n, determine the total count of structurally unique Binary Search Trees (BSTs) that can be constructed using exactly n nodes, where each node holds a distinct value from the sequence 1 through n.
A Binary Search Tree is a hierarchical data structure where for every node:
Two BSTs are considered structurally different if they have distinct tree shapes, meaning the arrangement of parent-child relationships differs between them. Note that trees with the same structure but different node value assignments that still satisfy BST properties are counted as distinct structures based on which value serves as the root and how subtrees are organized.
Your task is to compute how many such unique tree configurations exist for the given value of n.
n = 35With 3 nodes containing values [1, 2, 3], there are exactly 5 structurally unique BSTs:
Each configuration represents a valid BST with a different tree shape.
n = 11With only one node containing value 1, there is exactly one possible BST: a single root node with no children.
n = 22With 2 nodes containing values [1, 2], there are exactly 2 structurally unique BSTs:
These represent the two possible ways to arrange 2 nodes in a BST.
Constraints