retagged by
477 views
0 votes
0 votes
Consider a binary search tree, while searching the key value 4, key values 1, 2, 3, 6, 8, 9, 10 and 11 are traversed not necessarily in the order given. How many different orders are possible in which these key values can occur on the search path from the root to the node containing value 4?
retagged by

1 Answer

1 votes
1 votes
To find the different orders in which the given key values can occur on the search path from the root to the node containing value 4, we need to construct the binary search tree using the given values and then find all possible paths from the root to the node containing 4.

Since we don't know the exact order in which the values are traversed, we can only rely on the binary search property to construct the tree. That is, for any node with key value k, all nodes in the left subtree have key values less than k, and all nodes in the right subtree have key values greater than k.

Given that the values 1, 2, 3, 6, 8, 9, 10, and 11 are traversed on the search path from the root to the node containing 4, we can use the binary search property to construct the following possible binary search trees:

     6                9                8
   /   \            /   \            /   \
  2     9          6     10         6     10
 / \     \        / \      \       / \     \
1   3     10     2   8      11     2   4     11
        /  \                 \        / \
       8   11                 4      3   5

In each of these trees, the nodes containing values 1, 2, 3, 6, 8, 9, 10, and 11 occur on the search path from the root to the node containing 4, although not necessarily in the order given. For example, in the first tree, the search path from the root to the node containing 4 could be: 6 -> 2 -> 9 -> 4.

To find the different orders in which the given values can occur on the search path from the root to the node containing 4, we need to consider all possible paths from the root to the node containing 4 in each of these trees.

In the first tree, there is only one possible path from the root to the node containing 4, so there is only one order in which the values can occur on this path: 6 -> 2 -> 9 -> 4.

In the second tree, there are two possible paths from the root to the node containing 4: 9 -> 6 -> 10 -> 4 and 9 -> 10 -> 8 -> 4. For the first path, the possible orders of the values are: 9 -> 6 -> 2 -> 4, 9 -> 6 -> 3 -> 4, 9 -> 10 -> 8 -> 4, and 9 -> 10 -> 11 -> 4. For the second path, the possible order of the values is: 9 -> 10 -> 8 -> 4.

In the third tree, there is only one possible path from the root to the node containing 4, so there is only one order in which the values can occur on this path: 8 -> 6 -> 10 -> 4.

Therefore, the total number of different orders in which the given values can occur on the search path from the root to the node containing 4 is 1 + 4 + 1 = 6.

Related questions

0 votes
0 votes
1 answer
1
0 votes
0 votes
0 answers
4
Lakshman Bhaiya asked Oct 27, 2018
603 views
Consider a binary search tree for the following sequence of nodes $a,b,g,f,c,e,d$What is the resultant tree if splaying is done at $'d'.$