Algorithms Every Programmer Should Know
by Aniket Wattamwar
12 cardsManning MEAP early access (6 of 14 chapters): algorithms as plain-language thinking tools for matching, searching, and deciding.
Everything you optimize costs you something else
Before you chase "better," name what you are giving up to get it. Speed costs money. Thoroughness costs time. Reach costs attention. Optimize the thing you can least afford to lose, and accept the trade you did not choose.
— In our words · Source: Algorithms Every Programmer Should Know (Aniket Wattamwar)
Design for the worst day, not the average one
When you plan a system, a launch, or a budget, design for the worst realistic case, because that is exactly where things break. The average case is the pleasant lie; the edge case is where the damage lives.
— In our words · Source: Algorithms Every Programmer Should Know (Aniket Wattamwar)
Get a working answer before you get a clever one
Do the crude version first, the one that just works, then improve it once you can see the real bottleneck. Optimizing before you have a working baseline means you are polishing a guess.
— In our words · Source: Algorithms Every Programmer Should Know (Aniket Wattamwar)
Your process is only as fast as what you built it on
Before you improve a process, check the structure underneath it. If you are storing or organizing things the wrong way, no amount of hard work inside the process will fix it. Fix the container, then the process.
— In our words · Source: Algorithms Every Programmer Should Know (Aniket Wattamwar)
The one who asks first gets the better outcome
If you want the better outcome in a two-sided arrangement, hiring, partnerships, admissions, dating, be the side that proposes. The accepting side can only say yes or no to what shows up; the proposing side controls the options it presents.
— In our words · Source: Algorithms Every Programmer Should Know (Aniket Wattamwar)
Subtract the unavoidable cost; what is left is the decision
When comparing options, first subtract the cost you will pay no matter what. What is left is the actual difference you are deciding about. The unavoidable part is not the decision; the remainder is.
— In our words · Source: Algorithms Every Programmer Should Know (Aniket Wattamwar)
Do not fix one part by breaking the whole
When you optimize, check the whole board, not just the square in front of you. A change that makes one person, team, or route better often makes the total worse. Optimize globally, then let the local wins follow.
— In our words · Source: Algorithms Every Programmer Should Know (Aniket Wattamwar)
Screen with a cheap test, verify only the near-misses
When you have to check many things against many things, use a fast, cheap screen to rule out almost everything, then spend real effort only on the few that pass. Fingerprint first, inspect second.
— In our words · Source: Algorithms Every Programmer Should Know (Aniket Wattamwar)
Do not recompute from scratch; update the part that changed
When a small piece of the picture changes, do not rebuild the whole picture. Subtract what left and add what arrived. Most 'rework' is really 'recompute everything,' and it is almost always avoidable.
— In our words · Source: Algorithms Every Programmer Should Know (Aniket Wattamwar)
When you fail partway, the failure tells you where to resume
When something fails partway through, do not restart from zero. The point where it broke tells you exactly how far you had gotten and where to resume. Failures carry information; the wasteful move is discarding it.
— In our words · Source: Algorithms Every Programmer Should Know (Aniket Wattamwar)
Look at the one thing that rules out the most, first
Before you inspect something fully, check the single most informative fact first, the one that, if wrong, rules the whole thing out. When that fact clears, skip. The more specific your target, the faster you can eliminate.
— In our words · Source: Algorithms Every Programmer Should Know (Aniket Wattamwar)
Pick your search style: go deep on one path, or wide across all
When exploring options, know which you need: depth (commit to one path, follow it to the end, backtrack only if it dies) or breadth (survey all options at this level before going deeper). Depth risks missing alternatives; breadth risks never finishing any.
— In our words · Source: Algorithms Every Programmer Should Know (Aniket Wattamwar)