Calculate the time complexity of the following program fragments.
(a) 𝑓𝑜𝑟 (𝑖 = 1; 𝑖 ≤ 𝑛; 𝑖 ∗ = 2)
{
𝑥 = 𝑥 + 1
}
(b) 𝑓𝑜𝑟 (𝑖 = 1; 𝑖 ≤ 𝑛; 𝑖 + +)
𝑓𝑜𝑟 (𝑗 = 1; 𝑗 ≤ 𝑛; 𝑗 = 𝑗 ∗ 2)
… .
a)
T(n)=⌊log2(n)⌋T(n)=\lfloor log_2(n)\rfloorT(n)=⌊log2(n)⌋
b)
T(n)=n⌊log2(n)⌋T(n)=n\lfloor log_2(n)\rfloorT(n)=n⌊log2(n)⌋
Need a fast expert's response?
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
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!
Thank you so much
Comments
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!
Thank you so much