Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: A short meditation about hash search performance

by Jenda (Abbot)
on Sep 10, 2007 at 16:16 UTC ( #638109=note: print w/replies, xml ) Need Help??

in reply to A short meditation about hash search performance

I believe you mean "the number of buckets" not the number of valid hash keys ... there is a catch though ... the m usually depends on n! How exactly, depends, but I beleive in the Perl builtin implementation its 2*n rounded to the nearest power of 2. Which means your o(n/2m) becomes o(n/4n) wich becomes o(1/4) and ... well ... constants are irrelevant in the o() notation thus it's o(1). QED.

The average case of hash lookup even with the naive implementation is o(1), the worst case is O(n) for the naive implementation, but there are ways around that. They make the implementation more complex and insertion more costly, but they are possible. You can rehash once the list in a bucket gets too long or you can use binary trees instead of lists in the buckets.

  • Comment on Re: A short meditation about hash search performance

Replies are listed 'Best First'.
Re^2: A short meditation about hash search performance
by BrowserUk (Pope) on Sep 10, 2007 at 16:40 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://638109]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2016-10-23 09:24 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (300 votes). Check out past polls.