All the algorithms presented above have theoretically a running time of O(m+n) where m,n are the sizes of the lists.

Not true. Since BrowserUK's algorithm needs to allocate and initialize a string with max(@a, @b) bits, it has O(n + m + max(@a) + max(@b)) run time (you mentioned another problem that arises from large numbers, but not in terms of complexity).

The statement above is actually false. When we say O(n + m) we assume that n and m are the lengths of the input, in this case the number of lists.

OTHO max(@a, @b) is the numerical value, not an input length.

To make the two things comparable, you'd have to settle on a representation, let's say binary. Then you'd say that length(binary($x)) is roughly log(x)/log(2), so that the overall runtime is actually O(m + n + log(max(@a)) + log(max(@b)), now with all factors being in the same units, so-to-say.

(I hope I didn't mess this up entirely, it's late at night here, I'll take another look tomorrow to see if it still makes sense to me)


In reply to Re^2: Fast, Efficient Union and Intersection on arrays by moritz
in thread Fast, Efficient Union and Intersection on arrays by barvin

Title:
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, details, 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, summary, 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.