Note that there are some explanatory texts on larger screens.

plurals
  1. POcomplexity of a randomized search algorithm
    primarykey
    data
    text
    <p>Consider the following randomized search algorithm on a sorted array <code>a</code> of length <code>n</code> (in increasing order). <code>x</code> can be any element of the array.</p> <pre><code>size_t randomized_search(value_t a[], size_t n, value_t x) size_t l = 0; size_t r = n - 1; while (true) { size_t j = rand_between(l, r); if (a[j] == x) return j; if (a[j] &lt; x) l = j + 1; if (a[j] &gt; x) r = j - 1; } } </code></pre> <p>What is the expectation value of the <a href="http://en.wikipedia.org/wiki/Big_O_notation#Family_of_Bachmann.E2.80.93Landau_notations" rel="noreferrer">Big Theta complexity</a> (bounded both below and above) of this function when <code>x</code> is selected randomly from <code>a</code>?</p> <p>Although this seems to be <code>log(n)</code>, I carried out an experiment with instruction count, and found out that the result grows a little faster than <code>log(n)</code> (according to my data, even <code>(log(n))^1.1</code> better fit the result).</p> <p>Someone told me that this algorithm has an <strong>exact</strong> big theta complexity (so obviously <code>log(n)^1.1</code> is not the answer). So, could you please give the time complexity along with your approach to prove it? Thanks.</p> <hr> <p>Update: the data from my experiment</p> <p><code>log(n)</code> fit result by mathematica:</p> <p><img src="https://i.stack.imgur.com/29oh5.png" alt="log(n)"></p> <p><code>log(n)^1.1</code> fit result:</p> <p><img src="https://i.stack.imgur.com/Zja3X.png" alt="log(n)^1.1"></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.
 

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