Big O, what is the complexity of summing a series of n numbers?
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Big O notation is a critical concept in computer science, used to describe the performance or complexity of an algorithm. Specifically, it characterizes how an algorithm's run-time or space requirements grow as the size of the input increases. This article delves into the intricacies of Big O notation, focusing mainly on the complexity of summing a series of `n` numbers.
Understanding Big O Notation
Big O notation provides an upper bound on the growth rate of an algorithm's resource consumption. It is expressed using the O() function, which classifies algorithms according to their upper-bound time or space complexity in the worst-case scenario. In mathematical terms, the complexity of an algorithm can be expressed as:
Where:
- is the function representing the time or space required by an algorithm.
- is a function that describes the upper bound on resource consumption.
Commonly used Big O classifications include:
- O(1): Constant time
- O(log n): Logarithmic time
- O(n): Linear time
- O(n log n): Log-linear time
- O(n^2): Quadratic time
- O(2^n): Exponential time
Each classification provides insight into how the system behaves as `n` (input size) grows.
Complexity of Summing a Series of `n` Numbers
To understand the Big O complexity of summing a series of `n` numbers, consider a simple algorithm:
- Each addition operation is assumed to be a constant-time operation (O(1)).
- Since the loop runs `n` times, the total number of addition operations is `n`, making the complexity O(n).
- The space complexity is O(1) because no additional data structures are used that grow with input size. The storage for `total` is constant regardless of `n`.
- Drop Constants: In Big O, we focus on the growth rate, not constants. Hence, O(2n) is simplified to O(n).
- Asymptotic Dominance: In cases with multiple expressions like O(n + log n), `n` is the dominant factor, making O(n) the simplified notation.
Related reading

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.