Start by reading the loop boundaries and how the loop variable changes. The key question is: how many times does the body run as input size grows?
Use the update rule to estimate the number of iterations:
Keep only the dominant term. Ignore constants and lower-order terms. For example, if your count is something like 3n + 7, the complexity is O(n).
Ask whether the loop would clearly take more steps when the input size increases. If doubling the input roughly doubles the work, the answer is likely linear. If the number of steps grows by one each time the input doubles, it is likely logarithmic.
© 2023-2026 AI MATH COACH