Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For the function</p> <pre><code> _________ 77 if(x&lt;=5) / / foo(x)- \ \_________ foo(x-1) - foo(x-1) if(x&gt;5) let f(x) be time function for foo(x) f(x) = f(x-1) - f(x-1) // 2 (2^1)calls of f(x-2) happened for 1 level depth f(x) = [f(x-2) - f(x-2)] - [ f(x-2) - f(x-2)] (expanding f(x-1)) // 4(2^2) calls of f(x-2) happened for 2nd level depth f(x)={[ f(x-3) - f(x-3)]-[ f(x-3) - f(x-3)]} - {[ f(x-3) - f(x-3)]-[ f(x-3) - f(x-3)]} // 8(2^3) calls of f(x-2) happened for 3rd level depth </code></pre> <p>let i calls has happened to complete program.... </p> <pre><code>but program terminates when x&lt;=5, so program terminates in call f(x-i) when x-i&lt;=5 that means i&gt;=x-5 , at level i there are 2power(i) calls ==&gt; 2^i calls of f(x-i). since f(&lt;=5)=1(1 is unit of measure) for i&gt;=x-5 </code></pre> <p>so f(n) = 2^(x-5)*(1) =>O(2^x) where x is input size . if we replace x with n complexity is O(2^n) .</p> <p>for second question </p> <pre><code> _________ 0 if(b&lt;=0) / / bar(a,b) \ \_________ foo( bar(a,b+1) ,b-1 ) if(b&gt;0) </code></pre> <p>let t(n) be time function for bar(a,b) where n is proportional to b as b is deciding factor for termination .</p> <p>expanding reccurence</p> <pre><code>t(a,b) = t( t(a,b+1), b-1) . first t(a,b+1) is executed it inturn calls t(a,b+2) and so on.... it will be infinite recursion ..... for b &gt; 0 . </code></pre> <p>To my knowledge ,since we don't have limit for infinity(neither lower limit nor upper limit, so no theta notation and no big-oh notation so as omega notation) we cant measure complexity function as well .(Please correct me if i'm wrong) </p> <p>But if b&lt;0 then it will be done in O(1) time...</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. 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