Question 2,6,11,14 not clear

Please explain ques 2,6,11,14
i have read the solutions but need extra explanation with more details and clarity

@Garvit012 post the question with options and correct answer here please cant see which question you are asking for


image

@Garvit012 first one
i loops n times
---- j loops nxn times
------- k loops nxn times
so complexity n pow 5
second one
yes its true for most of the times except recursive code where memory space also depends on stack calls. in this case ans is true as if declared an array of size n space is o(n)
third one
lg(n fact) = lg( n * n-1 * n-2 …) is approx lg (n^n) = nlgn (property of log)
fourth one
well i is every time becoming sqrt(i) so loop will run logn times also the fun() takes logn time to calculate root so total complexity log(logn)
dont forget to hit like and mark resolved if cleared @Garvit012 :smiley:

1 Like

for the third one
Log(n!)=log(n)+log(n-1)+log(n-2)+…which will be total n terms

and in 2nd ques how does k loop n*n times??

j runs nn and k runs from start to j so k also nn
yes third one can be visualised like what you said too

for third one with my method TC will be O(n)
since there are n terms and log(n) can be calculated in O(1) time

with the log function

@Garvit012 logn takes logn time

how does c++ calculated logN?

@Garvit012 log is inbuilt in c++ you can refer its documentation c++ reference site

1 Like

okay thanks a lot for your help and sorry for the trouble

you are welcome :smiley: