Recommended resources
The freely available resources this lesson will direct you to.
In our previous lesson, we established what an algorithm is and, crucially, why its efficiency is a paramount concern in software development. We saw that the difference between a "reasonable" and an "unreasonable" algorithm isn't about raw computer speed, but about how the runtime scales as the input size grows.
Today, we'll give this concept of scaling a formal name and a system for classification. This lesson introduces Big-O notation, the fundamental language used by computer scientists to describe and compare the efficiency of algorithms. By the end of our session, you'll be able to explain what Big-O is and why it's the essential tool for analyzing an algorithm's performance.
1. Why We Need a Better Measure Than Time
Your first instinct when comparing two algorithms might be to time them. You could write two C programs, run them with the same input, and see which one finishes faster. However, this approach has some major flaws.
Let's watch a short segment that explains why measuring time in seconds is unreliable and what we should focus on instead.
Big O Notation, Time Complexity | DSA
This video from the Telusko channel, "Big O Notation, Time Complexity," clearly explains the problem with direct time measurement.
Watch from the beginning to understand why machine-dependent timing isn't a good measure (the problem with time). Then, continue watching as the presenter formally defines time complexity and introduces Big-O notation as the solution (defining time complexity).
As the video explains, we need a more abstract, hardware-independent way to describe efficiency. Time complexity isn't about seconds; it's about the relationship between the input size (n) and the number of operations the algorithm performs. Big-O notation is the way we express this relationship.
2. Understanding Big-O: The Core Idea
Big-O notation describes the rate of growth of an algorithm's runtime. It focuses on how an algorithm behaves when the input becomes very large, which is known as its asymptotic complexity.
Think of it this way: Big-O doesn't tell you the exact runtime. Instead, it tells you the shape of the growth curve. A linear growth curve is fundamentally better than a quadratic one when n gets large, regardless of how fast the computer is.
This next video provides an excellent conceptual overview of what Big-O represents.
The Ultimate Big O Notation Tutorial (Time & Space Complexity For Algorithms)
The video "The Ultimate Big O Notation Tutorial" by Back To Back SWE gets straight to the heart of the matter.
Watch the introduction (What is Big-O?), which explains that Big-O is about how an algorithm's speed scales for very large inputs. The key idea presented here is that Big-O provides an upper bound on the algorithm's performance.
In essence, Big-O answers the question: "As my input data gets bigger, how much slower will my program get?"
3. The Rules of Simplification
To make comparisons useful, Big-O notation follows two simple rules that help us focus on what's most important: the dominant factor in the algorithm's growth.
- Drop Constant Factors: An algorithm that takes
2nsteps and one that takesnsteps are both considered O(n). Why? Because asngrows towards infinity, that constant factor of 2 becomes insignificant compared to the overall linear growth. Both are straight lines on a graph; one is just steeper. - Drop Non-Dominant Terms: If an algorithm takes
n² + nsteps, we simplify it to O(n²). Asnbecomes very large, then²term grows so much faster than thenterm that the contribution ofnbecomes a rounding error. We only care about the term that grows the fastest.
This article from GeeksforGeeks provides a concise summary of these rules.
Big O Notation Tutorial - A Guide to Big O Analysis
This section of the "Big O Notation" article from GeeksforGeeks clearly lays out the simplification process.
Please read the section titled "A Quick Way to find Big O of an Expression". The two examples provided demonstrate exactly how to apply the rules of dropping lower-order terms and ignoring constants to find the final Big-O value.
4. A First Look at Common Complexity Classes
Using these rules, we can classify algorithms into different "complexity classes." In the previous lesson, you saw a graph of these growth curves. Now let's attach the official Big-O labels to some of them.

Let's briefly look at a few of the most fundamental classes.
Constant Time: O(1)
An algorithm is O(1) if its execution time does not change as the input size n increases. Accessing an array element by its index is a classic example—it takes the same amount of time whether the array has 10 elements or 10 million.
The Ultimate Big O Notation Tutorial (Time & Space Complexity For Algorithms)
Let's return to the "Ultimate Big O Notation Tutorial" video for a clear explanation.
Watch the segment on constant time. The key is that the runtime forms a flat line on the graph, regardless of the input size.
Linear Time: O(n)
An algorithm is O(n) if its runtime grows in direct proportion to the input size n. If you double the input size, you roughly double the execution time. A simple for loop that iterates through all elements of an array is a typical example.
The Ultimate Big O Notation Tutorial (Time & Space Complexity For Algorithms)
The same video explains linear time well.
Watch the explanation of linear time. The presenter reinforces the idea of dropping constants, showing why O(2n) or O(3n) are simplified to O(n).
Quadratic Time: O(n²)
An algorithm is O(n²) if its runtime is proportional to the square of the input size. This often occurs when you have nested loops that each iterate over the input. If the input size doubles, the runtime quadruples.
The Ultimate Big O Notation Tutorial (Time & Space Complexity For Algorithms)
Finally, let's look at quadratic time in the same video.
Watch the segment on quadratic time. The explanation of how nested loops lead to n * n operations is a fundamental pattern to recognize.
Conclusion
In this lesson, we demystified the formal language of algorithm analysis. You now have the conceptual tools to understand and discuss algorithmic efficiency like a computer scientist.
Key Takeaways:
- Big-O notation is a hardware-independent way to describe how an algorithm's runtime or space requirements grow as the input size (
n) increases. - It describes the upper bound or worst-case scenario, focusing on the algorithm's behavior with very large inputs (asymptotic analysis).
- To simplify analysis, we drop constant factors (e.g.,
O(2n)becomesO(n)) and non-dominant terms (e.g.,O(n² + n)becomesO(n²)). - Common complexity classes like
O(1),O(n), andO(n²), represent constant, linear, and quadratic growth, respectively.
Preview of the Next Lesson:
We've introduced the "big three" complexity classes today. In our next lesson, we will expand our vocabulary by exploring the other common classes you saw on the graph: O(log n), O(n log n), and O(n²). We'll examine the kinds of algorithms that fall into each category and start learning to identify these patterns in code.