Algorithms,
in slow motion
Decision trees expand one frame at a time, DP tables fill in cell by cell, and search ranges shrink step by step. Every chapter follows the same path: the idea in plain words, a visualization you can step through, Java / Python / JavaScript side by side, and worked LeetCode problems. You watch how an algorithm decides instead of memorizing its code.
What is an algorithm, exactly?
One old story about a schoolboy adding numbers contains the whole subject of this course
A story is often told about the mathematician Carl Friedrich Gauss. His teacher, wanting a quiet half hour, asked the class to add up every number from 1 to 100. The other children started adding one number at a time: 1+2=3, 3+3=6, 6+4=10. Gauss handed in an answer within seconds. He had noticed that 1+100=101, 2+99=101, 3+98=101, and so on — 50 pairs, each one adding up to 101, so the total is 50 × 101 = 5050. The details of the story are not reliably documented and versions of it differ. The arithmetic is the part that matters here.
The class was running one algorithm: add the numbers one at a time, so n numbers take n additions. Double the input size and the work doubles — O(n). Gauss was running a different one: pair the numbers up, then do three arithmetic operations. That takes the same time whether n is 100 or a billion — O(1). Same problem, two correct answers, and a whole tier of cost between them.
That is what an algorithm is: a sequence of steps that solves a problem, where every step is unambiguous and the sequence is guaranteed to stop. An algorithm is the recipe, not the meal. One dish can have many recipes. This course teaches you to read the classic recipes and to judge which one is better.
Correct for every input: an empty array, a single element, repeated values, negative numbers, and values at the edge of the integer range. Interview code usually fails on an edge case, not on the main idea.
Big-O measures how the cost grows as the input gets larger. Keep two separate accounts: time and space. The gap between Gauss and the class is the gap between O(1) and O(n).
You have to be able to say why it is correct and why it is fast. A greedy solution needs an exchange argument. A DP solution needs a state definition and a transition. "I have seen this problem before" does not survive a follow-up question.
Where the word algorithm comes from
The word comes from the name of the 9th-century Persian mathematician al-Khwārizmī. His book on the rules for calculating with Indian-Arabic numerals reached Europe, and "calculating in al-Khwārizmī's way" gradually became algorithm. So from the start the word meant following a precise set of steps. It has nothing to do with computers. Computers only made following steps very fast.
How does this course relate to DataData?
A structure is a noun, an algorithm is a verb. Together the two courses cover data structures and algorithms.
The sister course DataData answers the question "how is data stored?": arrays, linked lists, hash tables, trees, heaps, graphs, and what each operation costs on each of them. This course answers "how is a problem solved?": sorting, binary search, backtracking, greedy, dynamic programming — algorithms that do not belong to any one structure.
Some techniques only make sense on one structure: two pointers on an array, a monotonic stack on a stack. DataData already covers those, so this course does not repeat them. It links to them where they come up.
| Technique | Where it is taught | Why |
|---|---|---|
| Two pointers / sliding window | DataData · 01 Array | Both techniques depend on elements being stored next to each other. The array chapter walks through them frame by frame. |
| Monotonic stack / monotonic queue | DataData · 04 Stack · 05 Queue | They are advanced ways of using a stack and a queue, not separate paradigms. |
| Tree DFS / BFS and level-order variants | DataData · 07 Binary Tree | The first place recursion is applied to a real structure. |
| Heaps and Top-K | DataData · 09 Heap | The kth largest element comes back in chapter 1 of this course, solved with Quickselect instead. |
| Topological sort / Dijkstra / union-find | DataData · 11 Union-Find · 12 Graph | Graph algorithms are easiest to learn together with the graph structure itself. |
| Sorting / divide and conquer / binary search on the answer / backtracking / greedy / DP / bit manipulation / math / string algorithms | This course (AlgoAlgo) | Algorithms that do not depend on one particular structure. All of them are here. |
Suggested order
If you have not studied data structures yet, finish the first nine chapters of DataData first (at least through the heap chapter), then start here. This course assumes you already know what an array, a hash table, a tree, and a stack are. If you already know the structures, start with chapter 1 on sorting. This course stands on its own from there.
Recursion: the foundation of everything that follows
Divide and conquer is recursive, backtracking is recursive, and the first version of a DP solution is recursive too. Make this solid first.
Recursion means a function calls itself. It sounds circular: the answer to fact(3) depends on fact(2), which depends on fact(1). But as long as there is someone at the end of the line who knows the answer without asking anyone else, the answers travel back up. That case is called the base case.
Recursion is not magic. It is real pushing and popping on the call stack. Step through the life of fact(3) and watch it happen:
The exit that can be answered without recursing: fact(1) = 1, or an empty array summing to 0. Write it first. A recursion with no exit never stops.
When you write fact(n), assume fact(n−1) already returns the correct answer, and work out only how to build fact(n) from it. Do not try to expand three levels of calls in your head.
Every call must move closer to the base case: n−1, half of the range, one level further down the tree. How it converges is the shape of every algorithm in this course.
RecursionError). For deep recursion, call sys.setrecursionlimit(10**6) or rewrite the function as a loop.A common mistake: expanding the recursion in your head
To check whether a recursion is correct you only need three questions: (1) Is the exit right? (2) Assuming every recursive call returns the correct answer, does this level combine them correctly? (3) Are the arguments converging? If all three hold, the whole recursion is correct. This is mathematical induction. It is not a shortcut; it is the only way of checking that keeps working as the problem grows. Chapter 2 on divide and conquer and chapter 5 on backtracking show it applied to trees and to decision trees.
The four paradigms: the frame of the whole course
Hundreds of problems, four ways of thinking about them, plus a small set of tools
LeetCode has thousands of problems and the labels on them sound endless. But once you set aside the techniques that belong to a particular data structure, there are only four ways of approaching a problem. Get familiar with them here. Every chapter comes back to this set:
Try every possibility, but try it in an organized way: arrange the possibilities as a decision tree, and turn back as soon as a branch cannot lead to an answer (pruning). It is the slowest paradigm, but it is the one that always applies, and you have to understand it before DP makes sense.
Cut a large problem into independent smaller copies of itself, solve each one recursively, then combine the results: merge sort, fast exponentiation, merging k sorted lists. The subproblems do not overlap, and that is what separates this from DP.
Take the best option available right now and never go back. It is very fast, but it only works if you can prove that the local choice does not ruin the global answer. The standard proof is an exchange argument: show that any optimal solution can be rewritten to contain your choice without getting worse. No proof, no greedy.
Two conditions have to hold: the same subproblem keeps coming back during the enumeration, and an optimal answer can be assembled from optimal answers to those subproblems. When both hold, record each subproblem answer once and reuse it. The path is brute-force recursion → memoization → a bottom-up table. Four chapters and a cell-by-cell animation are spent on it.
And a box of tools
Sorting (chapter 1), binary search (chapter 3), bit manipulation (chapter 4), and math (chapter 11) are not separate ways of thinking, but the four paradigms use them constantly. A greedy solution almost always starts by sorting. The check inside binary search on the answer is often greedy. Bitmask DP uses bit operations to pack a whole set into one integer. The tool chapters are short and sit between the longer ones.
Six complexity tiers: the price list for this course
The full Big-O lesson is in the first chapter of DataData. This is only the price list.
| Tier | Name | Where you meet it in this course |
|---|---|---|
| O(1) | Constant | Gauss's formula, bit tricks: a fixed number of operations, whatever the input size. |
| O(log n) | Logarithmic | Binary search and binary search on the answer: each step discards half of the remaining candidates. |
| O(n) | Linear | One pass over the data: greedy, Kadane's algorithm, one-dimensional DP. |
| O(n log n) | Linearithmic | Merge sort, heapsort, quicksort on average. No sort that only compares elements can beat Ω(n log n). |
| O(n²) | Quadratic | Two-dimensional DP tables and plain nested loops. |
| O(2ⁿ) | Exponential | Enumerating every subset; backtracking with no pruning. This is the cost DP exists to remove. |
The story of this course is moving down a tier
Backtracking prunes O(2ⁿ) down. DP turns O(2ⁿ) into O(n²) or O(n). Divide and conquer turns O(n²) into O(n log n). Binary search turns O(n) into O(log n). A closed-form formula takes it all the way to O(1). The turning point of every chapter is one of these drops, and you get to watch it happen.
The map: 13 chapters, easiest first
The bar shows difficulty, the stars show how often the topic appears on LeetCode. Click any chapter to start.
Why this order?
Sorting and divide and conquer lay the foundation: recursion, and splitting a problem into smaller copies of itself. Binary search practises discarding half of the candidates, which needs a yes/no test whose answer flips exactly once across the range — a sorted array is only the simplest case of that. Bit manipulation is a short tool chapter, and it also prepares bitmask DP. Then the main sequence: backtracking draws the recursion tree → greedy teaches the proof you need before you may take the local best → four DP chapters pick up every case where backtracking is too slow and greedy is wrong. Each link rests on the one before it. Math and string algorithms fill the remaining gaps, and the final chapter puts every paradigm into one decision map.
How to use this course
Every chapter follows the same rhythm. Three steps, in order.
The idea in plain words → why brute force is not enough → the core method. Every conclusion comes with a reason. If a part does not make sense, go back one section instead of pushing on.
Every chapter has a visualization you can step through: DP tables filled one cell at a time, decision trees expanded one branch at a time. You have understood it when you can predict the next frame.
Work through the explained problems, then try the problem set — think for 30 seconds before opening a hint. Your checkmarks are stored in this browser and counted in the sidebar. A perfect quiz score lights the chapter green.
A review schedule: day 1, day 7, day 21
After you finish a problem: one day later, say the approach out loud and write the core code from memory; seven days later, redo it completely; twenty-one days later, redo it under time pressure (35 to 45 minutes for a medium problem, including explaining it). Before an interview, pick problems at random by paradigm rather than going through the chapters in order. A real interview will not tell you which chapter a problem belongs to.
About the three languages
The Java / Python / JS switch in the top bar applies everywhere: change it once and every code window on the site follows. The algorithm is the same in all three; what differs is the syntax and the standard library. Each version carries notes about the things that bite in that language, such as integer overflow in Java or the recursion limit in Python.
Quick check: chapter quiz
✎ Chapter quizSeven questions. A perfect score lights the first green mark in the sidebar.
Which statement describes the relationship between data structures and algorithms most accurately?
What does a recursive function need so that it does not call itself forever?
fact(3) calls fact(n−1) at each level, down to fact(1). At most, how many fact frames are on the call stack at the same time?
Adding 1+2+…+n one number at a time is O(n). What is the cost of the formula n(n+1)/2?
Which of these signal-to-paradigm rules are correct? (select all)
You binary search over 1024 candidate answers, discarding half of them at every step. About how many checks does the worst case need? (2¹⁰ = 1024; enter an integer)
In an interview, why is it recommended to describe the brute-force solution first and improve it from there, instead of going straight to the optimal one?
- An algorithm is a sequence of unambiguous steps that is guaranteed to stop. A good one meets three standards: correct (including the edge cases), fast and small (Big-O), and explainable (provable).
- A structure is a noun, an algorithm is a verb. Techniques that only work on one structure are in DataData. The structure-independent algorithms (sorting, binary search, backtracking, greedy, DP, bit manipulation, math, strings) are here.
- Recursion needs three things: a base case, trust in the recursive call, and arguments that converge. Check a recursion with those three questions instead of expanding the call tree in your head.
- The four paradigms in one line each: independent subproblems → divide and conquer; a local choice you can justify with an exchange argument → greedy; overlapping subproblems plus optimal substructure → DP; none of these → backtracking as the fallback.
- The thread running through the course is moving down a complexity tier: O(2ⁿ) → O(n²) → O(n log n) → O(n) → O(log n) → O(1). Each chapter turns on one of those drops.
- Practice routine: think for 30 seconds before opening a hint; review on day 1 out loud, day 7 in full, day 21 under time; before an interview, pick problems by paradigm rather than by chapter.