Key Takeaways: Algorithms and Problem-Solving Strategies
One-Sentence Summary
Big-O notation tells you how an algorithm's running time grows as input grows — and that growth rate matters far more than how fast it runs today on small data.
The Three Properties of a Good Algorithm
Property
What It Means
How to Verify
Correctness
Right answer for every valid input, including edge cases
Sequential loops add; nested loops multiply. Two back-to-back O(n) loops are still O(n); an O(n) loop inside another O(n) loop is O(n²).
Data structure choice is an algorithm choice. Swapping a list for a set or dict turns an O(n) membership test into O(1) on average.
Pseudocode first, then trace. Walk through a normal case, an edge case, and a boundary case by hand before you code.
Count memory too. Space complexity measures extra memory; faster algorithms often buy their speed with it (the set-based duplicate check uses O(n) extra space).
Measure with time.perf_counter(). Compare how times grow as n grows, not the raw numbers.
Key Distinctions
What Beginners Think
What's Actually True
"My program is fast enough"
What matters is how it scales to 10x or 100x more data
"Nested loops are always O(n²)"
Only if both loops depend on n
"Greedy always works"
Greedy only works for problems with the greedy-choice property
"The fastest algorithm is always best"
Time-space trade-offs mean faster algorithms may use more memory
"Big-O tells you exact run time"
Big-O describes growth shape, not absolute speed
Threshold Concept: Growth Rate Thinking
Before: "It runs in 0.5 seconds, that's fine."
After: "It's O(n²). It runs in 0.5 seconds on 1,000 items. On 1,000,000 items, that's 500,000 seconds — nearly six days."
What's Next
Chapter 18 (Recursion): The technique that makes divide and conquer elegant — functions that call themselves
Chapter 19 (Searching and Sorting): Apply Big-O analysis to classic algorithms: binary search, selection sort, merge sort