1
$\begingroup$

What would be a good way representing: i. Given a key, return all the data values associated with that key AND ii. Given a data value, return all the keys that are associated with that data.

So far, all I can think of is to maintain all keys in a sorted linked list where each "key" node has a key value and a vector of pointers to data nodes (in addition to linked list bookkeeping). Likewise, maintain all data values in a sorted linked list and each "data" node has a data value and a vector of pointers to the relevant keys.

Could you please offer me a hint for a more appropriate solution to this problem?

Raphael
73.4k31 gold badges184 silver badges406 bronze badges
asked Jun 4, 2015 at 21:47
$\endgroup$
1
  • $\begingroup$ Use two dictionaries. $\endgroup$ Commented Jun 5, 2015 at 5:52

1 Answer 1

2
$\begingroup$

Use two indices: the first index allows you to map a key value to the corresponding tuples that contain that key value; the second index allows you to map a data value to the tuples that contain that data value. Each index can be implemented as a hash table, binary tree, or any other data structure you like that provides fast lookups.

For instance, databases implement ideas like this to enable fast lookups and searches.

answered Jun 5, 2015 at 0:49
$\endgroup$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.