Pick the fix
You need fast lookups by key and also the smallest key at any time, with inserts and deletes. Which structure fits best?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A A balanced search tree (or a sorted container)
Right: O(log n) lookup, insert, delete and min.
Only an ordered structure keeps every one of those operations logarithmic.
Why not the others?
- B A hash map alone. It gives O(1) lookups but finding the minimum is O(n).
- C A binary heap alone. Finding or deleting an arbitrary key is O(n).