edited by
18,686 views
30 votes
30 votes

Suppose that we have numbers between $1$ and $100$ in a binary search tree and want to search for the number $55$. Which of the following sequences CANNOT be the sequence of nodes examined?

  1. $\{10, 75, 64, 43, 60, 57, 55\}$
  2. $\{90, 12, 68, 34, 62, 45, 55\}$
  3. $\{9, 85, 47, 68, 43, 57, 55\}$
  4. $\{79, 14, 72, 56, 16, 53, 55\}$
edited by

5 Answers

Best answer
49 votes
49 votes

In option C search sequence progress in $...47,68,43,..$

At $47$ we see that search key $55$ is greater and it will be on right side of $47$. so in further comparison a value less than $47$ will not come

Hence, option C is wrong.

edited by
8 votes
8 votes

Although @Sankaranarayanan P.N ji has provided good and quick way to solve this problem. But still mentioning two more ways to solve this problem. 

(1) In Method 1 we are solving problem via maintaining (Min, Max) window. 

(2) For getting some intuition about method 2. Please refer --> https://cs.stackexchange.com/questions/11043/number-of-possible-search-paths-when-searching-in-bst/11048#11048 .

PS: Much explanation is not added because it will help readers in thinking something  different :)

1 votes
1 votes

all answer looks correct but they have asked  “sequence of nodes examined “ 43 in option C will come out of sequence as the validation fails 

Answer:

Related questions

57 votes
57 votes
11 answers
4
Ishrat Jahan asked Oct 31, 2014
26,124 views
In a binary tree, the number of internal nodes of degree $1$ is $5$, and the number of internal nodes of degree $2$ is $10$. The number of leaf nodes in the binary tree i...