Visualized DSA Strategies

Episode 1 Big O

9 min · PHP · Quiz

Episode 1Big O

▶ This video is coming to YouTube soon.

Two solutions both give the right answer. Which one is better? Instead of timing code, we count its steps and watch how that count grows with the input. You'll see why Big O drops constants and keeps only the biggest term, meet the six growth classes from O(1) to O(2ⁿ), learn to read Big O straight from loops, and check whether an idea is fast enough from the problem's constraints, before writing it.

What you'll learn

  • Why we count steps instead of seconds
  • Best case vs worst case, and why Big O uses the worst
  • Drop the constants and keep the biggest term: 3n + 2 → O(n), n² + n → O(n²)
  • The growth ladder: O(1), O(log n), O(n), O(n log n), O(n²), O(2ⁿ)
  • Is it fast enough? About 10⁸ steps per second compiled, 2 × 10⁷ in PHP, and what n ≤ 10⁵ rules out
  • Reading code: loops in a row add, nested loops multiply, halving is O(log n), sorting is O(n log n)
  • Space complexity, and trading memory for time

Chapters

  1. 0:00Intro
  2. 0:16How to judge an algorithm
  3. 0:57Time complexity: count the steps
  4. 1:33Best case, worst case
  5. 2:00Drop the constants
  6. 2:32Keep only the biggest term
  7. 3:02The growth ladder: O(1) to O(2ⁿ)
  8. 3:30Is it fast enough? Reading constraints
  9. 4:21O(1) in code
  10. 4:49Loops in a row add
  11. 5:12Nested loops multiply: O(n²)
  12. 5:39Halving: O(log n)
  13. 6:08Sorting: O(n log n)
  14. 6:37Space complexity
  15. 7:16Time vs space
  16. 7:48Quiz: what's the Big O?
  17. 8:26Recap

Quiz: test yourself

The 4 questions from the end of the episode. Pick an answer to see why it's right.