Finally understood Big O by timing my own code instead of memorizing the cheat sheet
Spent way too long trying to memorize which operations were O(log n) versus O(n) from a cheat sheet, none of it stuck. Then I just started dropping print statements with counters into my own solutions and running them against increasing input sizes. Watching the number of operations actually double or barely move made the difference between linear and logarithmic click in a way no explanation had. Still slower at spotting it cold in an interview, but at least now I understand what I'm looking at instead of pattern-matching from memory.
1 comment
- 0
AnonymousAnon This is such a better way to build intuition than the cheat sheet. I did something similar plotting runtime against input size in a spreadsheet, seeing the curve shape was way more convincing than any explanation.