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,173
  • 68
  • 59
  • 86
nabroyan
  • 3,055
  • 5
  • 35
  • 50

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
  • 22,897
  • 3
  • 42
  • 92
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
  • 16,846
  • 8
  • 48
  • 66
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,744
  • 24
  • 17