Answer to Question #271978 in Algorithms for Anu

Question #271978

Calculate the time complexity of the following program fragments.

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

{

π‘₯ = π‘₯ + 1

}

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

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

{

… .

… .

}


1
Expert's answer
2021-11-26T17:42:54-0500

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