Practice question · Multiple choice
Searching a balanced binary search tree of 1023 nodes takes at most 10 comparisons; scanning a list of the same values takes up to 1023. Why does the tree save so much, and what does the saving depend on?
Hints
- At the root you compare once. How many nodes have you eliminated from consideration?
- 1023 nodes, 10 comparisons. What is 2 to the power of 10?
Show the answer
B. From discarding half the remaining candidates at every comparison.
Why
One comparison at the root discards half the tree entirely — not examined and rejected, never visited — so the candidate set halves each step: 1023, 511, 255, down to 1 in ten. Cost tracks height, and a balanced tree's height is about log₂ n. Sorted order alone is not the mechanism: a sorted list scanned linearly still takes n steps, and the halving is what saves the work.
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…
- Inserting 1, 2, 3, 4, 5, 6, 7, 8 into an empty binary search tree in that order produces a tree of height 8…
- A binary search tree built from sorted input degrades to a linked list, and the fix, AVL or red-black, adds…
- Select every statement the lesson supports about binary search trees.