Practice question · Multiple choice
A binary search tree built from sorted input degrades to a linked list, and the fix, AVL or red-black, adds rotations to every insert. Why accept that overhead?
Hints
- Ask how often real data arrives already sorted.
- The unbalanced tree is fine on random input. What is the cost of being wrong about that assumption?
Show the answer
A. Because it turns an average-case hope into a worst-case guarantee
Why
You are buying a guarantee, not average speed, sorted input is common rather than exotic, and an attacker can supply it deliberately. Paying a constant factor on every insert to remove an O(n) worst case is the same trade as randomised hashing against hash flooding.
Practise Trees and Hierarchical Storage
The app has 5 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.
More questions on Trees and Hierarchical Storage
- A binary search tree has root 5. The root's left child is 3 and its right child is 8; node 3 has left child 2…
- Searching a balanced binary search tree of 1023 nodes takes at most 10 comparisons; scanning a list of the…
- Inserting 1, 2, 3, 4, 5, 6, 7, 8 into an empty binary search tree in that order produces a tree of height 8…
- Select every statement the lesson supports about binary search trees.