This was a question from a data structures course at my university. I don’t understand what the question means. Can anybody elaborate me on the question, and the answer for it.
Suppose we insert all the numbers between 1 and 15 into an initially
empty binary search tree; all permutations of these keys are equally
likely to be the insertion order. Compute the probability of the
resulting tree having 10 as its root, 7 as the left child of the root
and 15 as the right child of the root.
In order for “
10 as its root, 7 as the left child of the root and 15 as the right child of the root.” to happen, the insertion order for the tree must be either:10first, then7, then15, then the other 12 numbers in some order.10first, then15, then7, then the other 12 numbers in some order.Now consider: how many ways that can happen?
So that’s
(12! * 2)ways to end up with that particular arrangement.Now, the set of all possible insertion orders is the permutation of 15 numbers, which is
15!(factorial)Note that the question says “
all permutations of these keys are equally likely to be the insertion order“, so it’s concerned with the number of possible ways to construct the tree, not the actual number of distinct resultant trees (there is a difference, because different insertion orders may yet end up building the same tree (e.g. the 2 cases above minus the 12 other numbers would build the same tree despite different insertion orders)Probability is: (The number of ways to build the arrangement specified by the question) divided by (the total number of possible ways to build the tree):
So
(12! * 2) / (15!)is the probability you want.