Computer Science I / Trees and Hierarchical Storage
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
  1. Ask how often real data arrives already sorted.
  2. 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.

Read the lesson: Trees and Hierarchical Storage →

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