Computer Science I / Choosing a Data Structure by Workload
Practice question · True or false

A hash table serves a workload of 90% lookups by key and 10% requests for the smallest key well, because the 90% case is O(1).

Hints
  1. How would a hash table find the smallest key?
  2. Weigh the cost of the 10% against the saving on the 90%.
Show the answer

False

Why

False. A hash table has no order, so 'smallest key' is a full O(n) scan, the 10% dominates. A balanced BST gives O(log n) for both operations and wins overall. Choosing by the most frequent operation alone is the trap; the cost of the rare operation has to be weighted in.

Read the lesson: Choosing a Data Structure by Workload →

Practise Choosing a Data Structure by Workload

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 Choosing a Data Structure by Workload