Suppose each number in the list is assigned to each node in the tree above. How many of the possible 5040 trees are binary search trees?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
In a BST, all elements in any left sub-tree must be smaller than the root, and all elements in any right sub-tree must be larger.
Since there are 3 elements in the left and right trees, this means that 4 has to be the root of the tree. In the left sub-tree, using a similar argument, 2 has to be the root with 1 and 3 as the leaves. On the right sub-tree, 6 has to be the root, with 5 and 7 as the leaves. This gives only 1 valid BST.