Multiple choice

This algorithm _______.

Given below is an algorithm:
if(right[x] != null)
{
x = right[x];
Treemin(x);
}
else
{
y = parent[x];
while(y !=null && x = right[y])
{
 x=y; y=parent[y];
}
return y;
}

  1. finds the successor of key x in the tree

  2. finds the predecessor of key x in the tree

  3. finds the maximum key in the tree

  4. finds the minimum key in the tree

  5. none of the above

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

This is correct. If right[x] != null, then the minimum key in the right sub-tree will be the successor otherwise it will trace its way to the parent node which is greater than key value.