[Solved] Analysis complexity, in for inside for, the 2nd for depeneds from the first one [closed]


You will have to use some mathematics here. Lets talk about your 2nd and 3rd loop:

No of iterations in 3rd loop(for c) for each iteration of 2nd loop(for b):

1 = 2^0 ( for b < 1)

2 = 2^1 ( for b < 2)

4 = 2^2 ( for b < 4)

.

.

n = 2^(logn base 2)

sum of above iterations is GP series sum which comes down to :

2((2 ^ logn) -1) / (2-1) which gives n.

now first loop runs n times.

So overall your code runs in order of n^2.

Hope this answers your question.

0

solved Analysis complexity, in for inside for, the 2nd for depeneds from the first one [closed]