Explanation of some questions

Please explain ques 2,5,11,14.
in ques 14,ans should beO(logn+logn) but its not there in option

hello @KetanPandey
pls share the screen of the question in which u have doubt. ( i dont have questions in sequence)

    void function(int n)         {           int count = 0;            for (int i=0; i<n; i++)           for (int j=i; j< i*i; j++)               if (j%i == 0)               {                  for (int k=0; k<j; k++)                       printf("*");                }          }

Find the Complexity of the given code. int gcd(int n, int m) { if (n%m ==0) return m; if (n < m) swap(n, m); while (m > 0) { n = n%m; swap(n, m); } return n; }

ques 11:::lg (n!) = ………………

Q14. 5. TIme and Space Find the time complexity of the given code. void pat(){ for (int i = 2; i <=n; i = pow(i, c)) { print("") } //Here fun is sqrt or cuberoot or any other constant root for (int i = n; i > 1; i = fun(i)) { print("") } }

There is no optn to share screenshot,please adjust with this

log(N!)= log(N * (N-1) * (N-2) * (N-3) * (N-4). . . . . . . . . . . . . . . . . . . . . . . . .3 * 2 * 1 )
by using log property i,e log(a * b) => log(a) + log(b)

Log(N!)= log(N)+log(N-1) +log(N-2) +log(N-3) +log(N-4) … … … … . .

now let say N is very big number such that N-1 ==N-2== N-3 ==N-4 ==N-K == N

log(N!)= log(N)+ Log(N)+log(N)+log(N)+log(N) … (total N terms will be there)
log(N!)=N*log(N)

image

refer this -> https://codility.com/media/train/10-Gcd.pdf

void function(int n)
{
int count = 0;

// executes n times 
for (int i=0; i<n; i++) 

    // executes O(n*n) times. 
    for (int j=i; j< i*i; j++) 
        if (j%i == 0) 
        { 
            // executes j times = O(n*n) times 
            for (int k=0; k<j; k++) 
                printf("*"); 
        } 

}
Therefor time Complexity of the above function O(n^5)