Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
You obviously don't understand what O(1) means.
Let's see. The definition of big O is:
f(n) = O (g (n)) iff there are a M > 0 and a c > 0 such that for all m > M, 0 <= f(m) <= c * g (m). [1] [ +2] [3]
I don't have any problem understanding with it. In layman terms, it means that a function f of n is in the order of g of n, if, and only if, there's a constant, such that if n gets large enough, the value of f is at most the value of g times said constant.
Search from beginning to end, going thru each element one by one, until hit what you are searching for. In the worst case (the element is at the end of the array), you have to hit 1 billion elements, but according to you, that's O(1). I say it is O(n). We never put a restriction saying that an array can at most contain 1 billion elements (so the size of an array in general is not a constant, although it is a constant for a given array at one given observation point.)
Hello? We never put a restriction on the size? Come again. What do you call:
And still O(1) is not reachable, unless each element resolve a unique key ;-)
That's a restriction of 1. You started out by putting restrictions on it, claiming that only if there's a restriction of a size of 1, the search algorithm is O (1). I on the other hand pointed out that as long as there is a restriction on the limit of the chain, it doesn't matter what the restriction is, 1, 14 (for 5.8.2), or a billion. If there's a restriction on the size, even with a linear search it's O (1). Here's a proof:
Suppose the chain is limited to length K, where K is a constant, independent of the amount of keys in the hash. Searching for a key is a two step process: first we need to find the bucket the key hashes to, then we need to find the key in the associated chain. Finding the right bucket takes constant time. Traversing the chain takes at most K * e time, for some constant e. So, searching for the element takes at most:
                               e * K + O (1),  e >= 0
     {definition of O()}  <=   e * K + d * 1,  e >= 0, d >= 0
     {arithmetic}         ==  (e * K + d) * 1, e >= 0, d >= 0
     {c == e * K + d}     ==   c * 1
     {c > 0}              ==   O (1).
I won't deny the performance will be rather lousy, but it's still O (1). Which proves that big-Oh doesn't say everything.
Cormen, Leiserson, and Rivest: Introduction to Algorithms. MIT Press, 1990. pp 26.
Knuth: The Art of Computer Programming, Volume 1: Fundamental Algorithms. Third Edition. Addison-Wesley, 1997. pp 107.
Sedgewick, and Flajolet: Analysis of Algorithms. Addison-Wesley, 1996. pp 4.


In reply to Re: A short meditation about hash search performance by Abigail-II
in thread A short meditation about hash search performance by pg

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (6)
    As of 2019-04-26 13:44 GMT
    Find Nodes?
      Voting Booth?
      I am most likely to install a new module from CPAN if:

      Results (129 votes). Check out past polls.

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