retagged by
373 views
2 votes
2 votes

retagged by

1 Answer

0 votes
0 votes
There is the dependency in the 3rd, inner loop to the variable p  so try with the normal approach.

for i = n                                                            | for i =  n / 2                                | ...............

j = 1, 2,3..........n-1                                           | j = 1, 2,..........n/2 -1                   | ............

each time p is incremented so                    | after completion of 2nd loop |....................

after completion of the 2nd loop  p = n     | p = n/2                                        |..................

Now 3rd loop will execute                            |Now 3rd loop will execute        |................

log (n) Base 3 time                                         | log (n/2) Base 3 time                 |..................

so finally if you add all   log(n) + log(n/2) + log(n / (2^2) ) + .....................log (n / (2 ^ log (n) Base 2) )

= O( (log (n) Base 3) * (log (n) Base 2) )

= O(log (n) ^ 2)

Related questions

0 votes
0 votes
1 answer
1
Overflow04 asked Oct 9, 2022
416 views
how O($n^{2}$) in the last.(in the given solution).
0 votes
0 votes
0 answers
2
Overflow04 asked Oct 9, 2022
287 views
Is it really coping operation will take O(n).Does copy is done character by character.means simple code like (in c++) for(int i=0;i<n;i++){s=s;}will take O($n^{2}$)
3 votes
3 votes
1 answer
3
1 votes
1 votes
1 answer
4