Talk:Equilibrium index

From Rosetta Code
Revision as of 20:21, 7 June 2011 by 128.148.60.130 (talk) (Bogus optimizations?)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Some of the "one pass" solutions, such as in Perl6 and Python examples, are dubious. Both use hash tables to store temp sums ("hash" in Perl, "dict" in Python), so as to save one pass through the input array because the result requires a single dictionary lookup. In reality, however, hash table insertion can be quite expensive, and because all indices are inserted into the hash somewhere, it's almost garanteed to be no smaller than just storing the sums in a flat list. It is probably more efficient, both speed- and space-wise, to just run a second pass through the input list or a stored summation list to pick out the right indices -- it's n array lookup vs n dictionary lookup, generally much faster, without even considering low level things like cache consistency.