Multiple choice

After insertion of n keys, worst case running time of the algorithm would be _______________

An iterative algorithm to search for key k in a tree T is given below-
Assume that the tree has n nodes and height h.
search(T,k)
{
x = root(t);
while(x!=null or x!= k)
{
if(x > k) x= left[x];
else x = right[x];
}
return x;
}

  1. O(h)

  2. O(n)

  3. O(nh)

  4. O(n2)

  5. O(h2)

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

 This is correct, as the worst case will comprise of height n-1. So O(n) will be the running and is the specific answer.