Whats the best data-structure for storing 2-tuple (a, b) which support adding, deleting tuples and c

Posted by bhups on Stack Overflow See other posts from Stack Overflow or by bhups
Published on 2010-04-15T07:39:39Z Indexed on 2010/04/15 7:43 UTC
Read the original article Hit count: 230

Hi
So here is my problem. I want to store 2-tuple (key, val) and want to perform following operations:
- keys are strings and values are Integers
- multiple keys can have same value - adding new tuples
- updating any key with new value (any new value or updated value is greater than the previous one, like timestamps)
- fetching all the keys with values less than or greater than given value
- deleting tuples.
Hash seems to be the obvious choice for updating the key's value but then lookups via values will be going to take longer (O(n)). The other option is balanced binary search tree with key and value switched. So now lookups via values will be fast (O(lg(n))) but updating a key will take (O(n)). So is there any data-structure which can be used to address these issues?
Thanks.

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about complexity