Home
DSA Visualizer
Basics
Big-O Notation
Big-O Notation
Big-O notation is the language used to describe the performance of algorithms: how their cost grows as the input grows.
QUESTION 1 / 4 · SCORE 0
YOUR CALL
for (let i = 0; i < n; i++) {
console.log(i);
}What is the time complexity of this snippet?
Show
Intuition
Imagine you're buying a car. You don't ask "exactly how many milliseconds does it take to go 0-60?". You ask "is it a sports car, a sedan, or a truck?". Big-O is that classification system for algorithms.
Concept
- Upper Bound: Big-O describes the ceiling of growth. It won't get worse than this.
- Asymptotic Analysis: We only care about large inputs (N → ∞).
- Drop Constants: O(2n) is just O(n). O(n² + n) is just O(n²).
How it Works
The Rules:
- Loops: Multiply complexity by N.
- Nested Loops: Multiply inner by outer (N * N = N²).
- Halving: If loop variable is divided/multiplied, it's Logarithmic.
Step-by-Step Breakdown
Play the Quiz Game to practice identifying complexities!
When to Use
- When designing any system to ensure scalability.
- In technical interviews!
When NOT to Use
- When N is guaranteed to be very small (e.g., sorting 5 items).
How to Identify
"Analyze the complexity", "Will this scale?", "Optimize".
Applying for software engineering roles? Free, no sign-up:
