Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For a space efficient method and all values are distinct you can do it in space <code>O( k )</code> and time <code>O( k*log(N)*N )</code>. It's space efficient and there's no data moving and all operations are elementary (adding subtracting).</p> <ol> <li>set <code>U = N; L=0</code></li> <li>First partition the number space in <code>k</code> regions. Like this: <ul> <li><code>0-&gt;(1/k)*(U-L) + L</code>, <code>0-&gt;(2/k)*(U-L) + L</code>, <code>0-&gt;(3/k)*(U-L) + L</code> ... <code>0-&gt;(U-L) + L</code></li> </ul></li> <li>Find how many numbers (<code>count{i}</code>) are in each region. (<code>N*k</code> steps)</li> <li>Find the first region (<code>h</code>) that isn't full. That means <code>count{h} &lt; upper_limit{h}</code>. (<code>k</code> steps)</li> <li>if <code>h - count{h-1} = 1</code> you've got your answer</li> <li>set <code>U = count{h}; L = count{h-1}</code></li> <li>goto 2</li> </ol> <p>this can be improved using hashing (thanks for Nic this idea).</p> <ol> <li>same</li> <li>First partition the number space in <code>k</code> regions. Like this: <ul> <li>`L + (i/k)->L + (i+1/k)*(U-L)'</li> </ul></li> <li><code>inc count{j}</code> using <code>j = (number - L)/k</code> <code>(if L &lt; number &lt; U)</code></li> <li>find first region (<code>h</code>) that doesn't have k elements in it</li> <li>if <code>count{h} = 1</code> h is your answer</li> <li>set <code>U = maximum value in region h</code> <code>L = minimum value in region h</code></li> </ol> <p>This will run in <code>O(log(N)*N)</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload