AlgoPlusAlgoPlus
← All modules

Data Structures & Algorithms

Sorting, searching, trees, graphs, dynamic programming, and the design techniques behind them. · 57 topics

Sorting
Bubble Sort
Swap adjacent out-of-order pairs.
Selection Sort
Pick the minimum, place it at the front.
Insertion Sort
Slide each key into the sorted prefix.
Quick Sort
Partition around a pivot, recurse.
Merge Sort
Split, sort halves, merge with a buffer.
Heap Sort
Build a max-heap, extract repeatedly.
Counting Sort
Non-comparison sort by tallying counts.
Radix Sort
Sort digit by digit with stable passes.
Shell Sort
Gapped insertion sort.
Bucket Sort
Scatter values into buckets, sort each, then concatenate.
Searching
Linear Search
Scan left to right until found.
Binary Search
Halve a sorted range each step.
Jump Search
Jump in blocks, then scan.
Exponential Search
Double the bound, then binary search.
Interpolation Search
Probe by value distribution.
Linear Structures
Stack
LIFO — push, pop, peek.
Queue
FIFO — enqueue, dequeue, front.
Linked List
Nodes chained by pointers.
Hash Table
Hash keys to buckets; chain collisions.
Deque
Double-ended queue — push/pop both ends.
Priority Queue
Heap-backed min queue (sift up/down).
Trees
Binary Search Tree
Build, traverse, and search a BST.
AVL Tree
Self-balancing BST with rotations.
Heap (Binary)
Complete tree with the heap property.
Trie
Prefix tree for strings.
Segment Tree
Range queries over array slices.
Advanced Data Structures
Red-Black Tree
Self-balancing BST kept in shape by recoloring and rotations.
B-Tree
Balanced multi-way search tree that splits and rebalances on insert.
Binomial Heap
Mergeable heap built from binomial trees.
Fibonacci Heap
Lazy mergeable heap with O(1) amortized decrease-key.
Graphs
Breadth-First Search
Explore layer by layer (FIFO queue).
Depth-First Search
Dive deep, backtrack (call stack).
Dijkstra
Shortest paths with a priority queue.
A* Search
Heuristic-guided shortest path.
Prim's MST
Grow a tree by cheapest frontier edge.
Kruskal's MST
Sort edges, union-find to avoid cycles.
Topological Sort
Order a DAG by dependencies (Kahn's).
Bellman-Ford
Shortest paths with negative edges.
Floyd-Warshall
All-pairs shortest paths.
Strongly Connected Components
Collapse cycles into components (Kosaraju & Tarjan).
Dynamic Programming
Coin Change
Fill a table, reuse subproblems for the fewest coins.
Longest Common Subsequence
Align two sequences by filling a grid.
Matrix Chain Multiplication
Parenthesize a product chain for the fewest multiplications.
0/1 Knapsack
Maximize value under a weight budget via a DP table.
Assembly Line Scheduling
Fastest path through two parallel assembly lines.
Travelling Salesman (Held-Karp)
Shortest tour over all cities via bitmask DP.
Greedy Algorithms
Activity Selection
Pick the most non-overlapping activities greedily.
Fractional Knapsack
Take the highest value-per-weight items first.
Huffman Coding
Build an optimal prefix code from a frequency heap.
Backtracking & Branch and Bound
Backtracking (N-Queens)
Explore the decision tree, prune dead ends.
0/1 Knapsack (Branch & Bound)
Prune the search tree using optimistic bounds.
Travelling Salesman (Branch & Bound)
Bound partial tours to cut the search space.
String Matching
Naïve String Matching
Slide the pattern and compare at every shift.
Rabin-Karp
Find matches fast with a rolling hash.
Knuth-Morris-Pratt (KMP)
Skip ahead using the prefix (failure) table.
Finite Automaton Matching
Preprocess the pattern into a DFA, then scan once.
Build it yourself
Playground
Write plain code and watch it animate.