I have a dictionary of type
and for a particular case, I need to do a reverse lookup. So for instance suppose I have this entry <\"S
1) Keys are unique, values are not. For a given value you have a set of keys.
2) Lookup by key is O(log n)
. Iterating with foreach
or LINQ is O(n)
.
So,
Option A: Iterate with LINQ, spend O(n)
per request, no additional memory.
Option B: Maintain Dictionary
, spend O(log n)
per request, use O(n)
additional memory. (There are two suboptions: build this dictionary before a series of look-ups; maintain it all the time)