Multiple choice

What would come in place of two in the above algorithm?

Here is an algorithm to insert a key k in a binary search tree T.
insert(T,k)
{
int flag = 0;
node x = root[T]; i
if(x == null)
{
root = new node(k);
}
while(x != null)
{
if(x > k)
{
y = x;
x = left[x];
flag = 1;
}
else
{
y = x;
x = right[x];
flag = 2;
}
}
if(flag ==1)
{
k = ?;
}
else
{
k = ?;
}
}

  1. right[x] and left[x] respectively

  2. right[y] and left[y] respectively

  3. left[x] and right[x] respectively

  4. left[y] and right[y] respectively

  5. left[x] and left[y] respectively

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

This is correct,  since y is the parent node to null value, this will designate the new key to correct place.