Calculate the time complexity of the following program fragments.
(a) 𝑓𝑜𝑟 (𝑖 = 1; 𝑖 ≤ 𝑛; 𝑖 ∗ = 2)
{ 𝑥=𝑥+1 }
(b) 𝑓𝑜𝑟 (𝑖 = 1; 𝑖 ≤ 𝑛; 𝑖 + +)
𝑓𝑜𝑟 (𝑗 = 1; 𝑗 ≤ 𝑛; 𝑗 = 𝑗 ∗ 2) {
....
....
}
a)
It is executed, for
The time complexity:
b)
It is executed, n times for
The time complexity:
Comments