What is the Big O of finding an item in a balanced BST?

  • A: O(1)
  • B: O(log n)
  • C: O(n)
  • D: O(n log n)
  • E: O(n2)

    Answer: B

    A BST, or Binary Search Tree, is ordered so that all descendants to the left of a node have a key value that is less, and all descendants to the right of a node have a key value that is greater. Thus, a search can discard half the tree at each step, giving a O(log n) search time.

    Contents    Page-10    Prev    Next    Page+10    Index