Concepts.

167 of 167 ready to play

The playground

Every visualization and simulation on the site. Open one, change the input, break something, and step through what happens.

Foundations

Data Structures & Algorithms

Linear Data Structures

Data Structures & Algorithms

Searching & Sorting

Data Structures & Algorithms

linear-search Live

Linear Search

Scan every element until you find the target: the baseline every search is measured against.

binary-search Live

Binary Search

Halve the search space every step: on sorted arrays, on answers, and on monotonic functions.

sort-bubble Live

Bubble Sort

Repeatedly swap adjacent out-of-order pairs until the largest values bubble to the end.

sort-selection Live

Selection Sort

Select the minimum of the unsorted part and move it to the front, one position at a time.

sort-insertion Live

Insertion Sort

Grow a sorted prefix by inserting each new element into its correct place, like sorting playing cards.

sort-merge Live

Merge Sort

Divide the array in half, sort each half recursively, then merge: guaranteed O(n log n).

sort-quick Live

Quick Sort

Partition around a pivot and recurse: the fastest general-purpose sort in practice.

partition-quickselectIn lesson

Partitioning & Quickselect

in Quick Sort

Run Lomuto and Hoare on the same array (the lesson example is preloaded). Lomuto fixes the pivot at p; Hoare returns a split point j, and the last step compares both schemes' results and swap counts.

partition-quickselect-3wayIn lesson

Three-Way Partition

in Quick Sort

One three-way partition on a duplicate-heavy array: watch lt, i and gt maintain the four regions from the table above, and note that i does not advance after a swap with gt.

partition-quickselect-selectIn lesson

Quickselect

in Quick Sort

Quickselect with Lomuto partitioning, exactly as described above: after each partition the pivot sits at its final index p, and everything on the side without k is discarded. Pick k with the slider and compare the comparison count with a full quick sort; try the Sorted input with pivot a[hi] to see the quadratic worst case. The implementation below uses Hoare partitioning instead, which narrows to [lo, j] or [j+1, hi] and stops when lo == hi.

sort-heap Live

Heap Sort

Build a max-heap, then repeatedly move the maximum to the end: O(n log n) in place.

sort-counting Live

Counting Sort

Beat the O(n log n) comparison bound by counting keys instead of comparing them.

sort-radix Live

Radix Sort

Sort digit by digit with a stable sub-sort, in O(d·(n + k)).

Trees

Data Structures & Algorithms

Graphs

Data Structures & Algorithms

graph-representation Live

Graph Representations

Vertices, edges, directed vs undirected, weighted graphs, and adjacency list vs matrix.

graph-bfs Live

Breadth-First Search

Explore layer by layer with a queue: shortest paths in unweighted graphs.

graph-dfs Live

Depth-First Search

Go deep before going wide: cycles, connectivity, and the backbone of many graph algorithms.

topological-sort Live

Topological Sort

Order the vertices of a DAG so every edge points forward: Kahn's algorithm and DFS ordering.

dijkstra Live

Dijkstra's Algorithm

Single-source shortest paths on non-negative weights with a priority queue.

bellman-ford Live

Bellman-Ford & Floyd-Warshall

Shortest paths with negative edges, negative-cycle detection, and all-pairs shortest paths.

mst Live

Minimum Spanning Trees

Connect every vertex at minimum cost with Kruskal's and Prim's algorithms.

union-find Live

Union-Find

Track connected components with near-constant-time union and find using path compression.

pathfinding Live

Grid Pathfinding

Heuristic-guided shortest paths: how games and maps find routes fast.

scc Live

Strongly Connected Components

Kosaraju's and Tarjan's algorithms, plus finding the critical edges and vertices of a network.

bridges-articulationIn lesson

Bridges and Articulation Points

in SCCs, Bridges & Articulation Points

The DFS from the table above, step by step: badges show disc/low (disc starts at 0), the side table tracks every vertex, and the two tests low[v] > disc[u] and low[v] ≥ disc[u] are checked after each child returns. Try the cycle (no bridges), the bow tie (root rule), parallel edges and a disconnected graph, or type your own edge list.

Problem-Solving Patterns

Data Structures & Algorithms

two-pointers Live

Two Pointers

Walk two indices toward or alongside each other to turn O(n²) scans into O(n).

sliding-window Live

Sliding Window

Maintain a moving window over a sequence for subarray and substring problems.

prefix-sum Live

Prefix Sums & Difference Arrays

Precompute running totals for O(1) range sums, and difference arrays for O(1) range updates.

floyd-cycle Live

Floyd's Cycle Detection

Floyd's tortoise and hare: detect cycles, find midpoints and cycle entrances in O(1) space.

monotonic-stack Live

Monotonic Stack & Queue

Keep a stack or deque sorted to answer next-greater and sliding-maximum queries in O(n).

monotonic-histogramIn lesson

Largest Rectangle in Histogram

in Monotonic Stack & Queue

Each pop measures the popped bar's rectangle between the new stack top and i. The dashed green outline is the best so far, and the sentinel 0 at the end flushes the bars still waiting.

monotonic-histogram-waterIn lesson

Trapping Rain Water (Stack)

in Monotonic Stack & Queue

Each pop adds one horizontal layer of water above the popped bar, capped by the shorter of its two walls. If the stack is empty after a pop, there is no left wall and the water spills.

activity-selection Live

Activity Selection

Make the locally optimal choice at every step, and know when that gives a global optimum.

huffmanIn lesson

Huffman Coding

in Greedy Algorithms

The same example step by step: the queue is drawn sorted, the first node extracted becomes the left (0) child, and ties go to the node that entered the queue first, exactly like the counter in the code below. Pick a text preset or type your own to see it encoded.

n-queens Live

N-Queens

Systematically explore choices and undo them: permutations, subsets, N-Queens and Sudoku.

backtracking-treeIn lesson

Backtracking: State-Space Tree

in Backtracking

The state-space tree grows as the search runs: each choose adds a node, each unchoose climbs back up. Switch to Permutations (the used array) or Combination sum, where sorted candidates let the search break off whole branches.

Dynamic Programming

Data Structures & Algorithms

Advanced Topics

Data Structures & Algorithms

Fundamentals

System Design

Building Blocks

System Design

dns-resolution Live

DNS Resolution

How names become IP addresses: resolvers, root and TLD servers, record types, TTLs and GeoDNS.

load-balancer Live

Load Balancer

Distribute traffic across servers: algorithms, L4 vs L7, health checks and sticky sessions.

api-gateway Live

API Gateway Pipeline

Forward vs reverse proxies, and API gateways for routing, auth, rate limiting and aggregation.

cdn Live

Content Delivery Network

Serve content from the edge: push vs pull CDNs, cache keys, invalidation and edge compute.

cache-strategies Live

Caching Strategies

Cache-aside, write-through, write-back, eviction policies, invalidation and stampede protection.

data-models Live

SQL vs NoSQL Data Models

Relational, key-value, document, wide-column and graph databases, and how to choose.

db-index Live

Database Indexing

B-tree and hash indexes, composite and covering indexes, and LSM trees vs B-trees.

replication Live

Database Replication

Leader-follower, multi-leader and leaderless replication; sync vs async and replication lag.

sharding Live

Sharding & Partitioning

Split data across machines: range, hash and directory partitioning, hot spots and rebalancing.

consistent-hashing Live

Consistent Hashing

Place servers and keys on a ring so adding a node moves only K/N keys; virtual nodes for balance.

message-queue Live

Message Queues & Consumer Groups

Decouple services with queues and logs: Kafka, RabbitMQ, consumer groups and backpressure.

erasure-coding Live

Erasure Coding vs Replication

Store files at scale: S3-style object stores, block vs file vs object storage, and pre-signed URLs.

inverted-index Live

Inverted Index

Inverted indexes, tokenisation, TF-IDF/BM25 ranking and how Elasticsearch scales search.

rate-limiter Live

Rate Limiting Algorithms

Token bucket, leaky bucket, fixed and sliding windows, and distributed rate limiting.

snowflake-id Live

Snowflake IDs

UUIDs, database sequences, ticket servers and Twitter Snowflake IDs.

Distributed Systems

System Design

Architecture Patterns

System Design

Case Studies

System Design

feed-fanout Live

News Feed Fan-out

Twitter/Instagram timelines: fan-out on write vs read, ranking and the celebrity problem.

pagination-feedIn lesson

Offset vs Cursor Pagination

in Design a News Feed

Scroll the feed with both kinds of pagination: new posts land on top between page requests, so the offset client's next page repeats posts it already showed, while the cursor client carries on from its last post. Delete a post to see offset pagination skip one instead.

adaptive-bitrate Live

Adaptive Bitrate Streaming

YouTube/Netflix: upload pipelines, transcoding, adaptive bitrate streaming and CDNs.

geohash Live

Geohash & Quadtree

Uber/Lyft: location updates, geohashes and quadtrees, matching drivers and surge pricing.

delivery-semantics-emailIn lesson

Duplicate Emails: At-Least-Once & Dedup

in Design a Notification System

The notification service publishes to Kafka, and an email worker sends through SES. Here the worker's offset commit is lost, so Kafka redelivers and at-least-once sends the same email twice. Switch to effectively-once: claim(delivery_id) finds the delivery already sent and skips it. Then pick "Worker crashes after sending": SES takes no idempotency key, so a crash between SES accepting the email and mark_sent still sends it twice, the window this section calls unavoidable.

delivery-semantics-retriesIn lesson

Retry Storms: Backoff & Jitter

in Design a Notification System

A provider outage seen from the retry side: 300 sends fail at once and retry with a fixed delay, exponential backoff, or exponential backoff with full jitter. Fixed delays and plain exponential backoff send the retries back in synchronized waves many times the provider's capacity; full jitter spreads them out.

file-chunking Live

Chunking & Deduplication

Google Drive/Dropbox: chunking, deduplication, sync conflicts and metadata databases.

delivery-semantics-idempotentIn lesson

Idempotency Keys & Dedup Tables

in Design a Payment System

The "our service → processor" hop with a crash in the worst place: the worker charges the card, then dies before recording it. The redelivered message misses the dedup table, but the retry carries the same idempotency key, so the processor replays the original charge. Switch the guarantee to at-least-once to see the same fault charge the customer twice.

seat-holds Live

Seat Holds & Double Booking

Ticketmaster/BookMyShow: seat holds, high-contention inventory, virtual waiting rooms.

isolation-levels-lost-updateIn lesson

Lost Update (Double Booking)

in Design a Ticket Booking System

Double booking is a lost update: two transactions both read "available" and both write "held". It opens at Read Committed, where the race gets through. Switch the level to see which ones stop it, and how row locks make the second writer wait.

OOP & Design Principles

Design Patterns

Creational Patterns

Design Patterns

Structural Patterns

Design Patterns

Behavioral Patterns

Design Patterns

pattern-strategy Live

Strategy Pattern

Swap an algorithm at runtime behind one interface instead of a growing if/else chain.

pattern-observer Live

Observer Pattern

Let many objects react when one changes, without the subject knowing who they are.

pattern-command Live

Command Pattern

Turn a request into an object you can queue, log, undo and redo.

pattern-state Live

State Pattern

Let an object change its behavior when its internal state changes, as a clean state machine.

pattern-template-method Live

Template Method Pattern

Fix the skeleton of an algorithm in a base class and let subclasses fill in the steps.

pattern-chain-of-responsibility Live

Chain of Responsibility Pattern

Pass a request along a chain of handlers until one deals with it: middleware and approval flows.

pattern-iterator Live

Iterator Pattern

Walk a collection without exposing how it's stored, and why every language builds it in.

pattern-mediator Live

Mediator Pattern

Route communication through one hub so objects stop talking to each other directly.

pattern-memento Live

Memento Pattern

Capture and restore an object's state without breaking encapsulation: snapshots and undo.

pattern-visitor Live

Visitor Pattern

Add new operations to a class hierarchy without changing the classes: double dispatch explained.

pattern-interpreter Live

Interpreter Pattern

Represent a small language's grammar as classes and evaluate sentences in it.

pattern-null-object Live

Null Object Pattern

Replace null checks with an object that does nothing, safely.

pattern-specification Live

Specification Pattern

Express business rules as small combinable objects: and, or, not.

Concurrency Patterns

Design Patterns

Anti-patterns & Refactoring

Design Patterns