English | 简体中文
Try different algorithms for the same problem, from brute force to optimal. Pure concentration, like an espresso.
Every algorithm here is a small file you can read in one sitting, next to the other ways of solving the same problem and a test that checks them against each other. Run one, race it against its neighbours, then read why the faster one is faster.
| Highlight | In short |
|---|---|
| Watch the sorts | Twelve sorts replay every read and write the real code makes, captured with a Proxy. Race two on the same numbers. |
| Race the solutions | Fifteen LeetCode problems race their approaches in your browser, after a check that every approach gives the expected answer to a small example. |
| Sixty LeetCode problems | One file per approach. Each folder's test runs every approach on the same cases, then against a slow but plainly correct reference on random inputs. |
| From brute force to optimal | fib(35) takes 29,860,703 calls by plain recursion and 69 with memoization; coin change, paint house and the longest common subsequence take the same steps. |
| Reading Chinese | Forward maximum matching and jieba's graph with dynamic programming, written out and compared with your browser's Intl.Segmenter. |
| Nothing to install | No dependencies: Node 22.18 or later runs the JavaScript, Python 3.11 and JDK 21 the rest. |
The collection also holds data structures from a stack to a trie, binary search and KMP, and classic problems such as the 0-1 knapsack and the Dutch national flag.
In your browser: open the live site: watch the sorts, race the solutions or find the words in a Chinese sentence.
On your computer:
git clone https://github.com/L-Jovi/espresso-algorithm.git
cd espresso-algorithm
node leetcode/0509-fibonacci-number/recursion.js # 832040, after 2,692,537 calls
npm test # every JavaScript test
npm run serve # the site, at http://127.0.0.1:8080/There is nothing to install. npm run bench races the sorts and npm run bench:leetcode the LeetCode approaches; npm run check also runs the Python and Java checks.
Every section is a folder with a README in English and Chinese, and every file inside is named after its technique: brute-force.js, memoization.js, two-pointers.js. Each file begins with a comment that says what it solves, the idea, why it is correct and what it costs, and ends with an example that node prints when you run the file.
Each README follows the same order:
- Try it: what to run and what you should see.
- What's inside: a table of the algorithms or approaches.
- How it works: the idea in plain words, and the file to start reading.
- Then and now: how this was done before, and what the language offers today.
- Limits: what the small version deliberately leaves out.
- Checks and credits: which tests cover it, and where the ideas came from.
New to algorithms? Start with sorting. Preparing for interviews? Start with LeetCode and its ten progressions.
| Section | What you'll find | Start with |
|---|---|---|
| Sorting | Fourteen sorts from bubble to radix, several with a Python twin, and a bench that races them | bubble sort, then merge sort |
| Searching | Binary search and lower bound in JavaScript and Java, and KMP string search | binary search |
| Data structures | Stacks, queues, a binary heap, linked lists, a set, a hash table, trees, a trie and a graph | the queue that is a ring buffer |
| Classic problems | Adding large numbers, three ways to remove duplicates, the 0-1 knapsack from brute force to a table, and more | the knapsack |
| LeetCode | Sixty problems; ten have a README that walks from brute force to optimal | 509, then 322 |
| Chinese word segmentation | Two segmentation algorithms next to Intl.Segmenter |
the two ambiguous sentences |
| Sort visualizer | How the site replays the real sorts | trace.js |
Most of the code was first written between 2018 and 2022. Since then sorting became stable in every JavaScript engine, Map, BigInt and Proxy replaced old workarounds, and Intl.Segmenter can find Chinese words without a native module. Then and now tells that story, with a source for every date.
An espresso is the concentrated shot that most coffee starts from: a latte or a cappuccino is an espresso with milk. Among the author's coffee-named repositories, algorithms play that part, the small concentrated core the rest is built on.
The rest of the series: latte-web (the web, the everyday blend), roaster-linux (Linux tools, where the beans are roasted), barista-services (services, the barista) and cappuccino-ios (iOS apps, lighter than a latte; retired in 2026).
A personal learning collection maintained by @L-Jovi. It is not a product: there are no releases and no packages. CI checks every change: the JavaScript tests on Node 22.18, 22, 24 and 26, Python 3.11 and 3.14, Java 21 and 25, the repository checks, and the site in Chrome, Firefox and Safari, which is deployed from main once everything passes. What the checks cover, and what they don't.
The repository was reorganized in September 2026. The migration ledger maps every old path to its new home.
Issues and pull requests are welcome. Please read CONTRIBUTING.md and the writing guide first, and report security problems privately as described in SECURITY.md. Everyone taking part follows the code of conduct.
Original code and documentation are MIT. NOTICE.md credits the work this repository learned from.