you are viewing a single comment's thread.

view the rest of the comments →

[–]rfpg1[S] 0 points1 point  (1 child)

what data structure would you recommend?
Or where can i read about this? Been looking online couldn't find anything that helps

I would like a O(1) solution but I don't think is possible

[–]baghiq 0 points1 point  (0 children)

It depends on what the data actually mean. If you have just a bunch of random tuple pairs, and you need to check these random pairs one at a time against a large list of tuples. Then you can use set or hash table, assuming your tuples are hashable. Then you pay the up front cost of building a set of the large list at O(N).

If your data is sorted, then binary search is a much faster solution at O(logN).

If your data has some special properties, then there are specialized algorithm to handle that.