Algorithms
An algorithm is a precise, finite sequence of steps for transforming an input into an output, and the choice of algorithm — not just the choice of data structure from the previous topic — is what decides whether a program finishes in milliseconds or never finishes at all. Searching is the simplest case: a linear search checks every element one at a time and works on any array, but a binary search exploits a sorted array's ordering by repeatedly checking the middle element and discarding half the remaining range, the same divide-in-half trick a binary search tree already performs structurally. Sorting rearranges an array into order so that binary search and other ordering-dependent operations become possible at all; a sorting visualizer — one of this series' project ideas — makes the contrast between approaches visible directly, since a simple approach like bubble sort repeatedly swaps adjacent out-of-order pairs in a slow quadratic crawl, while a divide-and-conquer approach like merge sort splits the array in half, recursively sorts each half, and merges the two sorted halves back together in linear time, finishing in a fraction of the comparisons. Recursion is a function calling itself on a smaller version of the same problem until it reaches a base case simple enough to answer directly, and it is exactly how merge sort's "split in half" step is actually implemented, with each recursive call consuming its own frame on the call stack this series already covered under memory and program execution. Graph traversal walks a graph's nodes and edges systematically: breadth-first search explores everything one step away before moving two steps away, guaranteeing the shortest path in an unweighted graph, while depth-first search commits to one path as far as it can go before backtracking — a maze solver is depth-first search applied directly to a grid where walls block edges, and a route finder layers in edge weights (distance or time) to find not just any path but the cheapest one. A greedy method builds a solution by always taking the locally best-looking choice at each step and never reconsidering it, which is fast but only provably correct for problems with the right structure; dynamic programming instead breaks a problem into overlapping subproblems and stores each subproblem's answer the first time it is computed so that every later reference to the same subproblem is a lookup instead of a recomputation, turning an exponential brute-force search into a polynomial one. Every one of these six tools — search, sort, recursion, traversal, greedy, dynamic programming — is a direct answer to a specific problem shape, which is why the next topic in this series, algorithm analysis, exists to measure exactly how much each one actually costs.