Question #197063

Calculate the time complexity of the following program fragments.

(a) 𝑓𝑜𝑟 (𝑖 = 1; 𝑖 ≤ 𝑛; 𝑖 ∗ = 2)

{

𝑥 = 𝑥 + 1

}

(b) 𝑓𝑜𝑟 (𝑖 = 1; 𝑖 ≤ 𝑛; 𝑖 + +)

𝑓𝑜𝑟 (𝑗 = 1; 𝑗 ≤ 𝑛; 𝑗 = 𝑗 ∗ 2)

{

… .

… .

}


1
Expert's answer
2021-05-23T14:37:53-0400

a)

T(n)=log2(n)T(n)=\lfloor log_2(n)\rfloor


b)

T(n)=nlog2(n)T(n)=n\lfloor log_2(n)\rfloor


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
24.05.21, 14:47

Dear greeshma,

You're welcome. We are glad to be helpful. 

If you liked our service please press like-button beside answer field. Thank you!



greeshma
24.05.21, 07:26

Thank you so much

LATEST TUTORIALS
APPROVED BY CLIENTS