← Quiz: Binary Search Tree Operations: all 15 questions
Quiz: Binary Search Tree Operations · Question 15 of 15
Why does inserting already sorted keys into a plain BST make operations slow?
Why does inserting already sorted keys into a plain BST make operations slow?
- A.The keys are stored twice
- B.Sorting the keys takes O(n log n)
- C.The root is deleted every time
- D.Every new key goes to the right, so the tree becomes a chain of height n and search becomes O(n)
Answer & explanation
Correct answer: Every new key goes to the right, so the tree becomes a chain of height n and search becomes O(n)
Self-balancing trees such as red-black trees (used by Java's TreeMap) prevent this.
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 →