Multiple choice

What would come in place of y and z respectively in the above algorithm?

An iterative algorithm to search for key k in a tree T is given below-
 search(T,k)
{
x = root(T);
while(x!=null or x!= k)
{
if(x < k) x= right[x];
else y
}
return z; 
}

  1. x = left[x] and x respectively

  2. x = k and x respectively

  3. x = right[x] and x respectively

  4. x = left[right[x]] and k respectively

  5. x != right[x] & x respectively

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

This is correct, as in the else part the condition which holds is if(x > k) then the next x should be left[x]. Again,  since at the end x only contains the node where the key is present, so x should be returned