4

I would like to know some complexities of binary search tree.

I can't find complete information. I want to know complexities for the following operations on a binary search tree

  1. to add/insert an element
  2. to remove an element
  3. to find an element (as I know this one is O(log(n)) )
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
nabroyan
  • 3,225
  • 6
  • 37
  • 56

3 Answers3

10

Insertion, deletion and searching in a binary search tree are:

  • O(N) in the worst case;
  • O(log(N)) in the average case.
md5
  • 23,373
  • 3
  • 44
  • 93
7

If you have balanced binary tree, all three complexities will be of O(log(N)). If you are not balancing the tree, it could be O(N).

Apurv
  • 17,116
  • 8
  • 51
  • 67
0

Search is effective. But unbalanced structure (which is often the case) can lead to O(N) for search/insert/remove operations. That is why binary heap or other kind of balanced trees are preferred with O(log n). .

SChepurin
  • 1,814
  • 25
  • 17