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