Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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 scrutinizing the Monastery: (9)
As of 2018-09-24 13:11 GMT
Find Nodes?
    Voting Booth?
    Eventually, "covfefe" will come to mean:

    Results (191 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!