Why do binary search trees need to be balanced?

  • A: saves search time
  • B: saves memory
  • C: easier to draw
  • D: unbalanced trees may cause errors
  • E: A, B, and C

    Answer: A

    Balancing of a BST is important to give the desired O(log n) search time. If the tree is unbalanced, search time could be as bad as O(n). While O(n) is not always bad, we expect a lookup table to have a time of O(1) or O(log n) because lookup is done frequently, often in a loop. (Unless the table is known to be small, in which O(n) is okay.)

    Contents    Page-10    Prev    Next    Page+10    Index