Say you have a lot of (key, value) objects to keep track of, with many insertions as well as deletions.
You need to satisfy 3 requirements:
- get the maximum key in constant time at any point
- look up the value of any key in logarithmic time.
- insertions and deletes take logarithmic time.
Is there a data structure that can do this?
My thoughts:
priority queues can get max in constant time, but i can't lookup values. binary search trees (2-3 trees) can lookup in logarithmic time, but max takes O(lgN) as well. if i try to keep track of the max in a BST, it takes O(lgN) when I have to delete the max and find the second greatest.