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).
q.e.d.
I won't deny the performance will be rather lousy, but it's still
O (1). Which proves that bigOh doesn't say everything.
 [1]
 Cormen, Leiserson, and Rivest: Introduction to Algorithms.
MIT Press, 1990. pp 26.
 [2]
 Knuth: The Art of Computer Programming, Volume 1:
Fundamental Algorithms. Third Edition. AddisonWesley, 1997.
pp 107.
 [3]

 Sedgewick, and Flajolet: Analysis of Algorithms.
AddisonWesley, 1996. pp 4.
Abigail
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: 
 &   & 
 <   < 
 >   > 
 [   [ 
 ]   ] 
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.

