1,400 views

1 Answer

3 3 votes

This question can be solved by taking first some initial values of k={1,2,3,4,5.....} and then using the coming relation find out the relationship between k and n.

for k=1 ,n will be 4 so i will iterate for 4 times(ie..,n times) and j=2 and each time incrementing in terms of square(j). so j will be 2 and 4 i.e., pf will be printing 2 times for each i thus it will be printed total of n*2.

for k=2 ,n will be 16 so i will iterate for 16 times(ie.. n times) and j=2 and each time incrementing in terms of square(j). so j will be 2 and 4 and 16 i.e., pf will be printing 3 times for each i thus it will be printed total of n*3.

 

for k=3 ,n will be 256 so i will iterate for 256 times(ie.. n times) and j=2 and each time incrementing in terms of square(j). so j will be 2 and 4 and 16, and 256 i.e., pf will be printing 4 times for each i thus it will be printed total of n*4 or(n*(3+1)).

.

.

.

.

.

 

for k=k times , it wil be executing n*(k+1) times

 

n= square(square(k))

log n= square(k) (base 2)

or k= log log (n).

 

time complexity will be O(log log (n)) for each n and thus printing will be done =n *(K+1)=O(n*k) =O(n*log*log (n))

  

Position:
Show:

Related questions

0 0 votes
2 answers 2 answers
880
880 views
omveer asked Sep 5, 2016
880 views
While(n>1){n=n/20;n=n/10;}Find time complexity.
1 1 vote
2 answers 2 answers
3.7k
3.7k views
APOORV PANSE asked Jun 1, 2016
3,696 views
Consider the following c fragment : void DAA(n) { int i,j,k,x=0; for (i=1 ; i <=n ; i++) for (j=1 ; j <= i * i ; j++) { if ( j mod i == 0 ) for ( k = 1 ; k <= j ; k++) x=...
2 2 votes
1 1 answer
1.6k
1.6k views
aka 53 asked Nov 22, 2017
1,593 views
for i < - 1 to n for j < 1 to n/2 X = X + 1(i and j both are incrementing by 1)Outer runs for n times and inner for n/2 So will it be n(n...
2 2 votes
3 answers 3 answers
2.0k
2.0k views
admin asked Oct 8, 2015
1,950 views
int Test(int n) { if (n<=0) return 0; else { int i = random(n-1); return Test(i) + Test(n-1-i); } }Suppose the function $\text{random}()$ takes constant time, then what ...