in Programming in C
1,675 views
3 votes
3 votes

What is the time complexity for insertion in binary tree in worst case?

  1. O(1)
  2. O(log n)
  3. O(n)
  4. O(n log n)
in Programming in C
1.7k views

1 comment

In the Worst case, it may grow left skew binary tree or right skew binary tree.

So, time complexity will be $O(n)$
2
2

4 Answers

2 votes
2 votes

Image result for left skewed binary tree

 

For inserting element as the left child of D(either in a left-skewed binary tree or right skewed binary tree), we have to traverse all elements(i.e. A, B, C, D). Therefore, insertion in the binary tree has worst-case complexity of O(n).

0 votes
0 votes
Worst case scenario when binary tree is skewed therefore O(n).
0 votes
0 votes
In the worst case tree will be skewed therefore complexity will be O(n)
0 votes
0 votes
Either the tree is left skewed or right skewed that's why O(n) is correct option