Computer Science, Playable
Data structures and algorithms you operate rather than read about — build the tree, break it, and watch what it costs.
- Array or Linked List? Score the Workload, Not the TableEveryone memorises the table - arrays index fast, linked lists insert fast - and still cannot pick one. Run both structures against the same operations here and watch the totals swap places depending only on what the code actually does.✓ numbers produced by the code on this page
- Appending Is O(1) on Average, and the Average Hides the Interesting PartMost appends to a list write one slot. Occasionally one copies the entire array. Change the growth strategy here and watch the spikes move - growing by a fixed amount stays quadratic however large the amount is.✓ numbers produced by the code on this page
- Stacks and Queues, Shown Doing the Jobs They Exist ForKnowing that a stack is last-in-first-out explains nothing about why anyone wanted one. Here a stack matches brackets and catches the error a counter would miss, and a queue runs a ring buffer whose values never move at all.✓ numbers produced by the code on this page
- More Buckets Will Not Save a Bad Hash FunctionHash tables are called O(1) so often that the condition gets dropped. Change the hash function here, drag the table from 4 buckets to 16, and watch the longest chain refuse to move - because memory cannot fix a hash that ignores its input.✓ numbers produced by the code on this page
- The Same Seven Numbers, Two Trees: Why Insert Order Decides Lookup CostInsert seven numbers into a binary search tree in sorted order and you get a seven-level chain. Insert the same seven in a different order and you get three levels. Build both here, and watch what the shape costs on every lookup afterwards.✓ numbers produced by the code on this page
- A Rotation Is Just Re-Hanging Three Subtrees, and the Order Never ChangesSelf-balancing trees are usually taught as four case names before anyone says what a rotation does. Insert the same values with rebalancing on and off here, and watch a tree that would be seven levels deep stay at three.✓ numbers produced by the code on this page
- Why Databases Use B-Trees: Fewer Levels Beats Fewer ComparisonsA balanced binary tree of a billion keys is thirty levels deep. If every level is a disk read, that is thirty reads for one lookup. Drag the branching factor here and watch the same keys collapse from a tall thin tree into a short wide one.✓ numbers produced by the code on this page
- A Heap Is a Tree You Can Store in a Flat ArrayHeaps are taught as trees and implemented as arrays, and the join between the two is usually three index formulas nobody explains. Watch a value sift up and down here, moving in the tree and the array at the same time, one swap per click.✓ numbers produced by the code on this page
- In a Trie, Lookup Cost Depends on the Word, Not on How Many WordsA trie stores words letter by letter, sharing every common prefix. Walk one here by clicking letters, and watch the reachable set shrink - that walk is exactly what an autocomplete box does while you type.✓ numbers produced by the code on this page
- Breadth-First and Depth-First Are the Same Loop, One Line ApartBFS and DFS get taught as two algorithms because one is usually written with a queue and the other with recursion. Run both here from one shared loop, changing only which end of the frontier the next node comes from, and watch the paths diverge.✓ numbers produced by the code on this page
- List or Matrix? Guess Before You Look, and Watch the Answer FlipLists for sparse graphs, matrices for dense ones is true enough to repeat and too vague to use. Predict the winner here on two dials - density and question mix - and find out how often the rule of thumb is wrong.✓ numbers produced by the code on this page
- Union-Find Has Two Optimisations Because It Has Two Different FailuresUnion by size and path compression are usually presented as one improvement after another. They rescue unrelated cases - and each is useless against the other's. Toggle them independently here and watch which merge order defeats which.✓ numbers produced by the code on this page
- Play the Cache: Why LRU Sometimes Scores ZeroA cache has to decide what to throw away before it knows what will be asked for next. Take the eviction decision yourself here, scored live against LRU and against the best any policy could possibly do.✓ numbers produced by the code on this page
- No Sorting Algorithm Wins. Look at Your Data First.Insertion sort is not slow and quicksort is not fast - each is the cheapest choice for some shape of input and the dearest for another. Predict the winner across five shapes here and watch a single favourite fail.✓ numbers produced by the code on this page
- Find the Wasted Calls: the Skill Behind Every MemoisationMemoisation is easy to explain and hard to apply, because the difficult part is noticing that a subproblem repeats at all. Here the recursion tree is drawn and you have to find the repeats yourself, scored, with wrong clicks counted.✓ numbers produced by the code on this page