Possible Binary Search Trees

Suppose each number in the list [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] [ 1,2,3,4,5,6,7 ] is assigned to each node in the tree above. How many of the possible 5040 trees are binary search trees?


The answer is 1.

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.

1 solution

Eli Ross Staff
Jan 26, 2016

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.

Strictly speaking the assignments in this case are only uniquly determined with respect to fhe ordering function. So there is e.g. another perfectly valid tree if you order descending instead of ascending.

J T - 1 year, 9 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...