Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Let </p> <p><strong>L3</strong> = log to the base 3 <strong>L2</strong> = Log to the base 2</p> <p>Then the correct answer is <strong>O(L3(L2(n))</strong> and NOT O(L2(L2(n)).</p> <p>Start with <strong>x = x * 2</strong>. x will increase exponentially till it reaches n, thus making the time complexity O(L2(n))</p> <p>Now consider <strong>x = x * x</strong>. x increases faster than the above. In every iteration the value of x jumps to the square of its previous value. Doing some simple math, here is what we get:</p> <p>For x = 2 n = 4, iterations taken = 1 n = 16, iterations taken = 2 n = 256, iterations taken = 3 n = 65536, iterations taken = 4</p> <p>Thus, the time complexity is <strong>O(L2(L2(n))</strong>. You can verify this by putting values above values for n.</p> <p>Now coming to your problem, <strong>x = x * x * x</strong>. This will increase even faster than x = x * x. Here is the table:</p> <p>For x = 2 n = 8, iterations taken = 1 n = 512, iterations taken = 2 n = (512*512*512), iterations taken = 3 and so on</p> <p>If you look at this carefully, this turns out to be <strong>O(L3(L2(n))</strong>. L2(n) will get you the power of two, but since you are taking cube of x in every iteration, you will have to take log to the base 3 of it to find out the correct number of iteration taken.</p> <p>So I think the correct answer is <strong>O(log-to-base-3(log-to-base-2(n))</strong></p> <p>Generalizing this, if <strong>x = x * x * x * x * .. (k times)</strong>, then the time complexity is <strong>O(log-to-base-k(log-to-base-2(n)</strong></p>
    singulars
    1. This table or related slice is empty.
    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. 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