Answer to Question #203701 in Algorithms for Atirah

Question #203701

Calculate the time complexity of the following program fragments.

(a) π‘“π‘œπ‘Ÿ (𝑖 = 1; 𝑖 ≀ 𝑛; 𝑖 βˆ— = 2)

{ π‘₯=π‘₯+1 }

(b) π‘“π‘œπ‘Ÿ (𝑖 = 1; 𝑖 ≀ 𝑛; 𝑖 + +)

π‘“π‘œπ‘Ÿ (𝑗 = 1; 𝑗 ≀ 𝑛; 𝑗 = 𝑗 βˆ— 2) {

....

....

}


1
Expert's answer
2021-06-06T08:54:30-0400

a)

It is executed, for "i=1,2,4,8,...,2^n"

The time complexity:

"T(n)=\\lfloor log_2n\\rfloor"


b)

It is executed, n times for "j=1,2,4,8,...,2^n"

The time complexity:

"T(n)=n\\lfloor log_2n\\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

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS