Calculate Time Complexity of following
(i)
F𝑜𝑟 (𝑖 = 1;𝑖 ≤ 𝑛; 𝑖 ∗ = 2)
{
𝑥 = 𝑥 + 1
}
(ii)
𝑓𝑜𝑟 (𝑖 = 1;𝑖 ≤ 𝑛; 𝑖 + +)
𝑓𝑜𝑟 (𝑗 = 1;𝑗 ≤ 𝑛;𝑗 = 𝑗 ∗ 2)
{
… .
… .
}
(i)
Logarithmic time – O (log n)
The algorithm reduces the size of the input data in each step.
(ii)
Logarithmic time – O (log n)
Comments
Leave a comment