The answer
Because the variable grows exponentially, it reaches N in far fewer steps. Mathematically, it takes log2(N) steps, hence O(log N).
Because the variable grows exponentially, it reaches N in far fewer steps. Mathematically, it takes log2(N) steps, hence O(log N).
If the loop iterates from 0 to N incrementing by 1, the time complexity is strictly O(N) Linear Time.
No. Big O measures the worst-case scenario. Even if you break early in the best case, the worst case still requires checking all N elements, so it remains O(N).
O(N) + O(N) = O(2N). However, in Big O notation, we drop constants, so the final time complexity is still O(N).
Browse all our FAQs or reach out to our support team
Your learning library
Find your next course. Build something great.