Calculate the time complexity of the following program fragments.
(a) πππ (π = 1; π β€ π; π β = 2)
{
π₯ = π₯ + 1
}
(b) πππ (π = 1; π β€ π; π + +)
πππ (π = 1; π β€ π; π = π β 2)
{
β¦ .
β¦ .
}
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"
Comments
Leave a comment