AlgoHay
The Journal
Big O Notation: O, Omega, Theta and the Common Growth Classes
Big O describes how an algorithm's cost grows with its input. Learn to count operations, drop constants, tell O from Omega and Theta, and recognize the common growth classes.
What Is an Algorithm? Correctness, Cost and Data Structures
An algorithm is a finite, precise procedure from input to output. This guide shows why correctness comes first, compares two correct ways to find a maximum, and maps out the rest of the course.
Dynamic Programming Time Complexity: Counting States and Work
The running time of a dynamic programming solution is the number of states times the work done per state. Here is that rule applied to coin change, longest common subsequence, 0/1 knapsack and edit distance, with the space savings each allows.
Dynamic Programming Explained: Memoization and Tabulation
Dynamic programming solves each subproblem once and reuses the answer. See it turn naive Fibonacci from exponential to linear time, then apply the same five steps to counting paths through a grid.
Graphs and Graph Representations: Lists, Matrices, Edges
A graph is a set of vertices joined by edges. How you store it, as an adjacency list, an adjacency matrix or an edge list, decides how much memory it takes and how fast each question is answered.
Topological Sort and Cycle Detection: Kahn's Algorithm and DFS
A topological order lists tasks so that every prerequisite comes before what depends on it. It exists only when the directed graph has no cycle, and both standard algorithms tell you when it does.
Breadth-First Search and Depth-First Search in Python
Breadth-first search explores a graph in rings around the start; depth-first search follows one path as far as it goes. Both visit every vertex and edge once, in O(V + E) time on an adjacency list.
Minimum Spanning Trees: Kruskal's and Prim's Algorithms
A minimum spanning tree connects every vertex of a weighted graph at the lowest possible total cost. Kruskal's and Prim's algorithms both build one greedily, and both are correct for the same reason: the cut property.
Dijkstra's Algorithm: Shortest Paths with Non-Negative Weights
Dijkstra's algorithm finds shortest paths from one vertex when no edge weight is negative. Here is a heapq version, its running time, and a three-vertex graph where a single negative edge makes it wrong.
Bellman-Ford: Shortest Paths with Negative Edge Weights
Bellman-Ford is slower than Dijkstra's algorithm but handles negative edge weights and tells you when a negative cycle makes shortest paths meaningless. Here is how it works, why V - 1 rounds are enough, and how to choose a shortest-path algorithm.
Linear Search vs Binary Search: O(n), O(log n) and bisect
Linear search works on any list in O(n). Binary search needs sorted input and finds an item among a million in at most 20 probes, provided its boundaries are right.
Counting Sort, Radix Sort and Bucket Sort Explained
Counting sort and radix sort never compare two items, so the n log n lower bound does not apply to them. Their cost depends on the key range and the number of digits instead.