Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re^3: A brain twister? (how to make 2 lines->1)by MidLifeXis (Monsignor) |
on Jun 27, 2012 at 13:18 UTC ( [id://978654]=note: print w/replies, xml ) | Need Help?? |
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 * - 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
In Section
Seekers of Perl Wisdom
|
|