http://qs1969.pair.com?node_id=193457


in reply to Re: best data structure
in thread best data structure

While this too is an option to solve the problem at hand, you will find that over time and with larger sets of data, that this method will prove to be substantially slower. This is due to the fact that a grep or loop over all set elements will, in a worst-case scenario, occur with O(n) execution - In contrast, a hash-lookup operates with O(1) execution.

As such this approach, particularly with larger data sets, can be justified, trading memory space for execution speed.