Skip to content
Skilled.dev

Big O Notation

Analyze how interview solutions grow with input size. Compare loops, recursion, auxiliary memory, and common complexity classes.

38:23 · Trey Huffine · Published 2020-07-13

Watch on YouTube · Read lesson notes · Open the current lesson

Chapters

  1. 0:00 Introduction (long but it includes memes)
  2. 2:17 How Interview Candidates are Graded (Why Big O)
  3. 5:46 Intuition for How and Why Big O Best Measures Algorithms
  4. 14:22 Big O Terms Defined
  5. 15:44 Why We Care About Large Input
  6. 18:00 Data Structures, Algorithms, and Big O
  7. 20:05 Real-World Big O Example
  8. 21:15 4 Steps for Calculating Big O
  9. 23:24 Step 1: Worst Case
  10. 25:55 Step 2: Drop Constants
  11. 28:06 Step 3: Drop Less Significant Terms
  12. 29:57 Step 4: Account for All Input
  13. 31:18 O(n)
  14. 32:22 O(n^2)
  15. 33:32 O(1)
  16. 34:44 O(log n)
  17. 36:14 O(n log n)
  18. 36:53 O(2^n) and O(n!)
  19. 37:26 Space Complexity

Selected start: 0:00. Press play in the video to watch.

Changes since recording

  • The small values in the time comparison table are microseconds (they were labeled ns), and a few miscalculated cells were corrected.
  • The hidden quadratic example now slices the input array, which is what makes it O(n²).

Use the current lesson code when checking behavior.

Lesson notes

These notes explain the problem and current implementation. They are a reading companion, not a verbatim transcript of the recording.

Big O describes how an algorithm's resource use grows as its input grows. It gives you a way to compare approaches before measuring one particular machine. The recording moves from that intuition to a repeatable analysis process: identify the work, choose a case, remove constant factors, and retain every independent input dimension.

Count operations under a stated model

A loop over n values performs linear work when each iteration does bounded work. Two full nested loops over the same n values perform quadratic work. Two separate loops add to a linear total. Nesting alone is not enough to determine a bound: a pointer that only advances across the input can limit total inner-loop work even when the code contains multiple loops.

Also inspect called operations. Taking a slice copies elements. Looking up a known array index and searching for a value are different costs. An operation that looks like one line can dominate the surrounding loop. The recording's corrected slicing example illustrates why counting lines is an unreliable substitute for counting work.

Name the case and the input dimensions

Worst-case analysis asks for a bound over every permitted input of a given size. Average-case analysis needs assumptions about a distribution. Amortized analysis spreads occasional expensive operations over a sequence. These descriptions answer different questions, so say which one supports your estimate.

If one loop scans a values and another scans b values, the bound is O(a + b). If each of the a values is compared with every b value, it becomes O(a × b). Replacing both dimensions with n can hide an assumption that the inputs grow together. State whether string comparisons, integer arithmetic, or map operations are being treated as bounded work.

Separate auxiliary space from the answer

A result array of n values occupies linear space even when the algorithm needs only a few counters beyond it. Recursive calls also consume stack frames. Discuss peak live storage rather than adding every allocation ever made. Input mutation may save allocation while changing the API's behavior.

Use the complexity practice tool to explain a cost before checking the answer. The Big O visualizer compares modeled growth curves; its numbers describe the model, not elapsed-time benchmarks for your computer.