AlgoHay
The Journal
Two Pointers and Sliding Window: From O(n^2) to O(n)
Many array and string problems that look like they need every pair of positions can be solved in one pass with two indexes. Here are the patterns, the condition each depends on, and a random test against brute force.
Common Bugs in Algorithm Code and How to Catch Them
Most bugs in algorithm code come from a short list of mistakes. Here are the common ones in Python, each with a run that shows it, and a testing habit that catches the rest: compare against a slow, obviously correct version on random inputs.
Recurrence Relations and the Recursion Tree Method
A recurrence describes a recursive algorithm's cost in terms of smaller calls. Draw it as a tree, sum each level, and the shape of the tree gives you the bound.
Binary Trees and Binary Search Trees: Traversals and O(h)
A binary search tree finds a key in time proportional to its height. That is O(log n) when the tree is balanced and O(n) when it degrades into a chain.
Backtracking: Subsets, Permutations and N-Queens in Python
Backtracking builds candidate solutions one choice at a time and undoes each choice after exploring it. Here is the template, applied to subsets, permutations and N-Queens, with what pruning does and does not change about the running time.
Recursion Explained: Base Cases, the Call Stack and Limits
A recursive function calls itself on a smaller input until it reaches a base case. Trace calls on the stack, see why Python raises RecursionError, and learn when to use a loop instead.
How to Approach a Coding Interview Problem, Step by Step
A repeatable way to work through an algorithm problem under time pressure, from clarifying questions to a brute force, a faster idea chosen from the input limits, clean code and tests said out loud.
Time and Space Complexity: Steps, Memory and the Trade-Off
Time complexity counts steps and space complexity counts memory. See auxiliary versus total space, why recursion costs stack space, and how a set trades memory for speed.
P vs NP and NP-Completeness, Explained Plainly
NP does not mean "not polynomial". Learn what P, NP, NP-hard and NP-complete really mean, why P vs NP is still open, and how programmers handle NP-hard problems.
Amortized Analysis: Aggregate, Accounting and Potential Methods
An append that sometimes copies the whole array is still O(1) amortized. See why with the aggregate, accounting and potential methods, checked against a small Python simulator.
The Master Theorem: Three Cases, Worked Examples and Limits
The master theorem solves divide-and-conquer recurrences by comparing log_b a with d. Work through binary search, merge sort and more, and learn which recurrences fall outside it.
Best, Average and Worst Case Analysis, With Examples
Best, average and worst case each turn "it depends on the input" into one function of n. See them on linear search, insertion sort and quicksort, and why a case is not the same as a bound.