🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Binary Search Tree Operations: all 15 questions

Quiz: Binary Search Tree Operations · Question 10 of 15

Why are Java's TreeMap operations guaranteed O(log n) while a plain BST is not?

Why are Java's TreeMap operations guaranteed O(log n) while a plain BST is not?

  1. A.TreeMap uses hashing internally
  2. B.TreeMap stores keys in a sorted array
  3. C.TreeMap is a red-black tree, which rebalances itself to keep the height about log n
  4. D.TreeMap forbids sorted input
Answer & explanation

Correct answer: TreeMap is a red-black tree, which rebalances itself to keep the height about log n

Self-balancing trees perform rotations on insert and delete so that the height never grows like a chain.

Can you get the rest right without peeking?

Take the timed Quiz: Binary Search Tree Operations quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →