recategorized by
581 views
1 votes
1 votes

Suppose numbers from $1$ to $1000$ are saved in a binary search tree and we want to find $363.$ Which of the following sequences cannot be the order of elements while reaching the searched value?

  1. $925,202,911,240,912,245,363$
  2. $924,220,911,244,898,258,362,363$
  3. $2,252,401,398,330,344,397,363$
  4. $2,399,387,219,266,382,381,278,363$
recategorized by

1 Answer

2 votes
2 votes

Let’s take options

Method 1 :   if we are at any node x then ,by moving  in left sub tree we are fixing upper bound as x and by moving right sub tree we are fixing lower bound as x

For option A   

  1. 925 will be inserted then for 363 we have to move left sub tree so next value should be less than 925 so 202 get inserted
  2. 925,202 then 363 > 202 to move right sub tree value next value must be in [202,925] ,so 911 get inserted
  3. 925,202,911  then 363 < 911 we have to move left sub tree so next value must in [202,911] that is 240 get inserted
  4. 924,202,911,240 then 363 > 240 move to right sub tree so next value must be b/w [240,911] but next value is 912 so fail 

So A is correct

 

Method 2 :

In this method take a sequence and draw BST for the sequence if the resultant BST is Degenerate tree the sequence is correct otherwise not correct 

In method 2 till now I have never find any limitations but I get to know that this method have some limitation 

Answer:

Related questions

1 votes
1 votes
1 answer
2
1 votes
1 votes
2 answers
3
GO Classes asked Mar 26, 2023
720 views
Consider a min-heap with $6$ distinct elements. How many positions can be taken by $3^{\text{rd}}$ minimum element?$2$$3$$4$$5$