in reply to Re^2: A brain twister? (how to make 2 lines->1)
in thread A brain twister? (how to make 2 lines->1)
Hash lookups, if done right, are O(1) algorithms (see hash_table - thanks Ransom and possibly perldata (unverified) - thanks moritz). Since you are just looping through the list of keys (O(n)), looking up the hash table entry for that key (O(1)), and generating a string from the two values (O(1)), the order of the map should be O(n)*.
Performance is another issue entirely, but unless you are profiling the two implementations, and the speed performance boost is appreciable and worth the additional complexity, go with the implementation that is simpler to understand.
* - assuming that I am remembering my undergrad coursework properly.
Update: used performance instead of speed since you may not be optimizing for speed, but some other metric.
--MidLifeXis
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: A brain twister? (how to make 2 lines->1)
by perl-diddler (Chaplain) on Jun 27, 2012 at 23:30 UTC |