by bnoordhuis · 15y ago · 0 comments
A quick review of the code makes me think that its worst case is actually on the order of O((s * (s + 1)) / 2), where s = m / 2.
The Achilles heel is the hash function. It's trivial to create collisions and have the insertion time for word w turn from O(1) to O(w).
But - and I don't want to sound pedantic - how is m^2 not exponential growth?
Edit: mea culpa guys, I carelessly translated from Dutch. You're all right: quadratic, not exponential growth.
Using terminology like "exponential" and "quadratic" correctly in a discussion of algorithms is not pedantic...
m^2 is exponential -- in the value 2. But the value 2 doesn't change very rapidly, so we tend to focus on the m component of the expression. :-)
Exponential growth would be 2^m.
Have a look at http://en.wikipedia.org/wiki/Time_complexity , it's pretty comprehensive.