Can a for-loop be O(log N)?
Yes, if the loop's update step multiplies or divides the counter (e.g., i *= 2 or i /= 2) instead of adding or subtracting.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in O(log N) Logarithmic Time: How Halving Speeds Up Code
It means the algorithm's execution time grows very slowly because it eliminates half of the remaining data on every single step of the process.
Because computers operate in binary (base 2), and most logarithmic algorithms (like Binary Search or Tree traversal) divide the data exactly in half.
Yes, drastically faster. As data scales into the millions, an O(N) algorithm takes millions of steps, while an O(log N) algorithm takes around 20 steps.
Still have questions?
Browse all our FAQs or reach out to our support team
