Question #197063

Calculate the time complexity of the following program fragments.

(a) š‘“š‘œš‘Ÿ (š‘– = 1; š‘– ≤ š‘›; š‘– āˆ— = 2)

{

š‘„ = š‘„ + 1

}

(b) š‘“š‘œš‘Ÿ (š‘– = 1; š‘– ≤ š‘›; š‘– + +)

š‘“š‘œš‘Ÿ (š‘— = 1; š‘— ≤ š‘›; š‘— = š‘— āˆ— 2)

{

… .

… .

}


Expert's answer

a)

T(n)=⌊log2(n)āŒ‹T(n)=\lfloor log_2(n)\rfloor


b)

T(n)=n⌊log2(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!

LATEST TUTORIALS
APPROVED BY CLIENTS