##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
Learn algorithms step-by-step. Each tutorial includes explanations, code implementations, and practice problems.
Bellman-Ford Algorithm
Breadth-First Search BFS
Bipartite Graph Check
Depth-First Search DFS
Dijkstra's Algorithm
Floyd-Warshall Algorithm
Kruskal's Algorithm
Prim's Algorithm
Topological Sort DFS-based
Topological Sort Kahn's Algorithm
A Strongly Connected Component SCC in a directed graph is a maximal set of vertices where every vertex is reachable from every other vertex.
Binary search is a fast algorithm for finding a target value in a sorted array. Instead of checking every element like linear search at , you repeatedly split...
Bubble Sort
A lower bound query asks for the first sorted element that is at least a target value. The array is already sorted, so binary search is the natural tool.
Merge Sort
Coordinate compression replaces large values with their rank among the distinct values. The relative order is preserved while the range becomes small.
The answer is a distance. If it is possible to place all items with minimum distance , then every smaller distance is also possible.
The answer is a time. If the machines can produce enough items by time , then any larger time also works.
The answer is the largest allowed segment sum. If a limit works, then any larger limit also works.
Dynamic Programming: Memoization
Unbounded Knapsack
Let be the number of ways to form sum using the coin types processed so far.
Edit Distance measures the minimum number of single-character operations needed to transform one string into another. You have operations available:
The Knapsack problem asks: given items, each with a weight and value, what's the maximum value you can carry in a bag with capacity ?
A subsequence is a sequence you can derive from another by deleting zero or more elements without changing the order of remaining elements. For example, "ACE"...
The Longest Increasing Subsequence LIS problem asks for the length of the longest subsequence where each element is strictly greater than the previous one.
Let be the minimum number of coins needed to make sum . The answer is built from smaller sums.
The MEX is the smallest non-negative value whose frequency is zero. Updates only change the frequencies of the old value and the new value.
Maintain the lower half and upper half of the numbers seen so far. The lower median is the largest value in the lower half.
Point updates and range sums are a standard Fenwick tree use case. The tree stores enough prefix-sum information to update and query in logarithmic time.
The Range Minimum Query RMQ problem asks: given an array and multiple queries, find the minimum element in a specified range for each query.
Segment Tree
Trie Prefix Tree
Union-Find also called Disjoint Set Union or DSU helps you track elements partitioned into non-overlapping sets. You can perform operations: find tells you...
Factorial with Modular Arithmetic
Euclidean Algorithm for GCD
Fast Exponentiation Binary Exponentiation
Sieve of Eratosthenes
Binomial Coefficient nCr mod p
Modular Multiplicative Inverse