brain

tamnd's digital brain — notes, problems, research

41802 notes

15.14 Counting Inversions

You need to measure how far an array is from being sorted.

algorithmsdivide-and-conquerrecursion
15.23 Design Patterns

After studying many divide-and-conquer algorithms, they can appear unrelated.

algorithmsdivide-and-conquerrecursion
15.10 Parallel Divide and Conquer

Divide-and-conquer algorithms naturally create independent subproblems.

algorithmsdivide-and-conquerrecursion
15.12 Selection Algorithms

You need to find the \(k\)-th smallest element in an unsorted array.

algorithmsdivide-and-conquerrecursion
15.15 Binary Search on Answer

Some problems ask for an optimal value rather than a specific object.

algorithmsdivide-and-conquerrecursion
15.21 Testing Divide-and-Conquer Algorithms

Divide-and-conquer algorithms are prone to subtle implementation errors.

algorithmsdivide-and-conquerrecursion
15.25 Exercises

You have learned the main divide-and-conquer patterns in this chapter.

algorithmsdivide-and-conquerrecursion
15.16 Fast Fourier Transform

You need to multiply two polynomials.

algorithmsdivide-and-conquerrecursion
15.18 Closest Pair of Points

Given \(n\) points in a plane, find the pair with the smallest Euclidean distance.

algorithmsdivide-and-conquerrecursion
15.19 Correctness Proofs

A divide-and-conquer algorithm may look correct because its structure is simple: ```text split solve recursively

algorithmsdivide-and-conquerrecursion
14.12 Priority Queue Greedy

Many greedy algorithms appear different on the surface.

algorithmsgreedy
14.11 Sorting Plus Greedy

Many greedy algorithms begin with a sort.

algorithmsgreedy
14.7 Fractional Knapsack

The fractional knapsack problem is one of the clearest examples of a greedy algorithm producing an optimal solution.

algorithmsgreedy
14.20 Proving Greedy Algorithms

Designing a greedy algorithm is often easier than proving it correct.

algorithmsgreedy
14.4 Interval Scheduling

Interval scheduling is one of the most important greedy problems.

algorithmsgreedy
14.5 Activity Selection

The activity selection problem is historically one of the first optimization problems used to demonstrate the power of greedy algorithms.

algorithmsgreedy
14.21 Complexity Analysis

Greedy algorithms often have simple control flow.

algorithmsgreedy
14.13 Two-Pointer Greedy

Many greedy algorithms operate on sorted data and repeatedly make decisions from the extremes of a range.

algorithmsgreedy
14.25 Exercises

Greedy algorithms are best learned by proving, breaking, and implementing them.

algorithmsgreedy
14.23 Case Studies

Greedy algorithms become easier to recognize after seeing them embedded in complete problems.

algorithmsgreedy
14.18 Local vs Global Optimum

Greedy algorithms are attractive because they make local decisions.

algorithmsgreedy
14.8 Job Sequencing with Deadlines

Many scheduling problems ask a simple question: > Given limited time and many competing jobs, which jobs should be performed?

algorithmsgreedy
14.14 Graph Greedy

Many of the most successful graph algorithms are greedy algorithms.

algorithmsgreedy
14.16 String Greedy

String problems often invite dynamic programming, tries, automata, and hashing.

algorithmsgreedy
14.24 Advanced Greedy Techniques

The classical greedy algorithms presented earlier in this chapter are often introduced as isolated ideas: - Interval scheduling - Huffman coding - Fractional knapsack

algorithmsgreedy
14.1 Greedy Choice Property

The greedy choice property is the fundamental condition that allows a greedy algorithm to produce an optimal solution.

algorithmsgreedy
14.22 Greedy Algorithm Design Checklist

Throughout this chapter, we have studied a wide variety of greedy algorithms: - Interval scheduling - Activity selection - Huffman coding

algorithmsgreedy
14.15 Greedy Scheduling Patterns

Scheduling problems occupy a special place in algorithm design.

algorithmsgreedy
14.10 Prefix Constraints

Many greedy algorithms operate under a simple principle: > A decision is either feasible or infeasible.

algorithmsgreedy
14.17 Greedy Data Structure Design

Many greedy algorithms are remembered by their choice rule: - Choose the earliest finishing interval.

algorithmsgreedy
14.2 Exchange Arguments

Most greedy algorithms are not proved by directly showing that the greedy solution is optimal.

algorithmsgreedy
14.9 Minimum Refueling Stops

Minimum refueling stops is a greedy scheduling problem disguised as a travel problem.

algorithmsgreedy
14.6 Huffman Coding

Huffman coding is one of the most successful greedy algorithms ever developed.

algorithmsgreedy
14.19 Counterexamples

A counterexample is a small input that disproves a proposed algorithm, lemma, or proof idea.

algorithmsgreedy
14.3 Matroids Overview

Many greedy algorithms appear unrelated on the surface.

algorithmsgreedy
14.26 Chapter Summary

Greedy algorithms are among the most elegant techniques in algorithm design.

algorithmsgreedy
13.20 Dynamic Programming Design Patterns and Problem-Solving Framework

Throughout this chapter, we have studied many different forms of dynamic programming: * one-dimensional DP * two-dimensional DP * knapsack DP

algorithmsdynamic-programming
13.6 Two-Dimensional Dynamic Programming

One-dimensional dynamic programming models progress along a single axis.

algorithmsdynamic-programming
13.15 Counting Dynamic Programming

Many dynamic programming problems ask for the best solution: ```text minimum cost maximum value

algorithmsdynamic-programming
13.22 State Compression and Memory Optimization

One of the most common mistakes in dynamic programming is focusing exclusively on time complexity while ignoring memory consumption.

algorithmsdynamic-programming
13.11 Interval Dynamic Programming

Most dynamic programming problems decompose a problem into prefixes, suffixes, positions, or capacities.

algorithmsdynamic-programming
13.24 Testing Dynamic Programming Algorithms

Dynamic programming algorithms are especially prone to subtle bugs.

algorithmsdynamic-programming
13.7 Knapsack

The knapsack problem occupies a special place in dynamic programming.

algorithmsdynamic-programming
13.2 Recurrence Relations

After defining a state, the next step is to determine how one state depends on other states.

algorithmsdynamic-programming
13.21 Dynamic Programming on Graphs

Dynamic programming is easiest when subproblems form a simple order: left to right, bottom to top, short interval to long interval, child before parent.

algorithmsdynamic-programming
13.1 DP State Design

State design is the most important step in dynamic programming.

algorithmsdynamic-programming
13.10 Edit Distance

The edit distance problem asks a deceptively simple question: > How different are two strings?

algorithmsdynamic-programming
13.8 Longest Common Subsequence

The Longest Common Subsequence (LCS) problem is one of the most influential dynamic programming problems ever studied.

algorithmsdynamic-programming
13.5 One-Dimensional Dynamic Programming

One-dimensional dynamic programming is the simplest and most common form of dynamic programming.

algorithmsdynamic-programming
13.25 Case Studies

This chapter has treated dynamic programming as a toolkit: state design, recurrence construction, memoization, tabulation, counting, optimization, graph DP, interval DP, tree DP, bitmask DP, and trans...

algorithmsdynamic-programming
13.17 Convex Hull Trick

Many dynamic programming solutions are correct but too slow.

algorithmsdynamic-programming
13.12 Tree Dynamic Programming

Many dynamic programming problems are defined on linear structures such as arrays, strings, and intervals.

algorithmsdynamic-programming
13.19 Knuth Optimization

Knuth optimization is a specialized dynamic programming optimization for interval-like recurrences.

algorithmsdynamic-programming
13.9 Longest Increasing Subsequence

The Longest Increasing Subsequence (LIS) problem is one of the most important sequence optimization problems in algorithm design.

algorithmsdynamic-programming
13.3 Memoization

Once a state and recurrence have been defined, the most direct way to implement a dynamic programming solution is memoization.

algorithmsdynamic-programming
13.23 Correctness Proofs for Dynamic Programming

A dynamic programming solution is easy to mistrust.

algorithmsdynamic-programming
13.18 Divide-and-Conquer Dynamic Programming

Many dynamic programming recurrences have the correct state design but suffer from an expensive transition step.

algorithmsdynamic-programming
13.13 Bitmask Dynamic Programming

Most dynamic programming problems use states based on positions, intervals, capacities, or tree nodes.

algorithmsdynamic-programming
13.14 Probability Dynamic Programming

Probability dynamic programming appears when each transition has uncertainty.

algorithmsdynamic-programming
13.4 Tabulation

Memoization evaluates states on demand through recursion.

algorithmsdynamic-programming
13.16 Optimization Dynamic Programming

Optimization dynamic programming is the form most programmers first associate with DP.

algorithmsdynamic-programming
12.20 Image Segmentation with Graph Cuts

Suppose you have an image and want to separate the foreground from the background.

algorithmsgraphsnetwork-flow
12.11 Assignment Problem

In maximum bipartite matching, every assignment has the same value.

algorithmsgraphsnetwork-flow
12.1 Flow Networks

You need to model the movement of resources through a constrained system.

algorithmsgraphsnetwork-flow
12.6 Push-Relabel Algorithm

The algorithms developed so far share a common strategy.

algorithmsgraphsnetwork-flow
12.25 Common Flow Modeling Patterns

Many optimization problems appear completely different on the surface.

algorithmsgraphsnetwork-flow
12.18 Vertex-Disjoint Paths

Edge-disjoint paths are allowed to share vertices.

algorithmsgraphsnetwork-flow
12.16 Vertex Capacities

Standard flow networks place capacity constraints on edges.

algorithmsgraphsnetwork-flow
12.5 Dinic's Algorithm

Edmonds-Karp guarantees polynomial running time, but it still performs only one augmentation per BFS search.

algorithmsgraphsnetwork-flow
12.22 Correctness Proofs

Flow algorithms are easy to implement incorrectly because their state changes over time.

algorithmsgraphsnetwork-flow
12.13 Minimum-Cost Maximum-Flow

Traditional maximum-flow algorithms answer a single question: > How much flow can be sent from the source to the sink?

algorithmsgraphsnetwork-flow
12.17 Edge-Disjoint Paths

Suppose you are designing a communication network between two data centers.

algorithmsgraphsnetwork-flow
12.14 Circulation with Demands

So far, flow networks have had a source and a sink.

algorithmsgraphsnetwork-flow
12.2 Residual Graphs

Suppose you have already constructed a valid flow in a network.

algorithmsgraphsnetwork-flow
12.9 Bipartite Matching

Suppose you have a set of workers and a set of tasks.

algorithmsgraphsnetwork-flow
12.23 Complexity Analysis

Flow algorithms solve the same abstract problem, but their running times differ sharply.

algorithmsgraphsnetwork-flow
12.8 Max-Flow Min-Cut Theorem

A maximum-flow algorithm returns a number.

algorithmsgraphsnetwork-flow
12.21 Scheduling Applications

Scheduling problems often look different from flow problems.

algorithmsgraphsnetwork-flow
12.12 Hungarian Algorithm

You need to solve an assignment problem exactly.

algorithmsgraphsnetwork-flow
12.24 Testing Flow Code

Flow implementations are compact, but bugs are easy to hide.

algorithmsgraphsnetwork-flow
12.10 Hopcroft-Karp Algorithm

You need to find a maximum matching in a bipartite graph.

algorithmsgraphsnetwork-flow
12.7 Minimum Cut

Maximum flow asks how much can be sent from a source to a sink.

algorithmsgraphsnetwork-flow
12.3 Ford-Fulkerson Algorithm

Given a flow network with capacities on every edge, determine the maximum amount of flow that can be sent from the source to the sink.

algorithmsgraphsnetwork-flow
12.15 Lower Bounds on Edges

A normal flow edge has only an upper capacity: ```text 0 ≤ f(u, v) ≤ c(u, v) ```

algorithmsgraphsnetwork-flow
12.19 Project Selection

You have a set of possible projects.

algorithmsgraphsnetwork-flow
12.4 Edmonds-Karp Algorithm

The Ford-Fulkerson method provides a simple framework for computing maximum flow, but its performance depends heavily on the choice of augmenting paths.

algorithmsgraphsnetwork-flow
11.17 Dense Graph Handling

Sparse graphs reward algorithms that touch only existing edges.

algorithmsgraphsspanning-trees
11.15 Network Design

Many real-world optimization problems can be modeled as graphs.

algorithmsgraphsspanning-trees
11.13 Second-Best Spanning Tree

A minimum spanning tree gives the cheapest way to connect all vertices.

algorithmsgraphsspanning-trees
11.7 Union-Find

Many graph algorithms repeatedly ask the same question: > Do these two vertices already belong to the same connected component?

algorithmsgraphsspanning-trees
11.4 Kruskal's Algorithm

Given a connected weighted undirected graph, find a spanning tree whose total edge weight is minimum.

algorithmsgraphsspanning-trees
11.24 Common Bugs

Minimum spanning tree code often fails for reasons that are easy to miss in clean textbook examples.

algorithmsgraphsspanning-trees
11.12 Minimum Bottleneck Spanning Trees

Minimum spanning trees minimize the **total weight** of selected edges.

algorithmsgraphsspanning-trees
11.23 Choosing the Right MST Algorithm

By this point, you have seen three major minimum spanning tree algorithms: ```text Kruskal Prim

algorithmsgraphsspanning-trees
11.8 Path Compression

The basic union-find structure can become highly unbalanced.

algorithmsgraphsspanning-trees
11.19 Correctness Proofs

Minimum spanning tree algorithms are short.

algorithmsgraphsspanning-trees
11.11 Dynamic Connectivity Overview

Offline connectivity works well when edges are fixed, or when all updates can be processed in a convenient order.

algorithmsgraphsspanning-trees
11.16 Sparse Graph Handling

Minimum spanning tree algorithms are usually described in terms of `V` vertices and `E` edges.

algorithmsgraphsspanning-trees
11.25 Case Study: Building a Production-Quality MST Service

Throughout this chapter, we have studied minimum spanning trees from multiple perspectives: * Graph theory * Greedy algorithms * Union-find

algorithmsgraphsspanning-trees
11.10 Offline Connectivity

Suppose you are given a graph and thousands or millions of connectivity queries: ```text Are vertices u and v connected?

algorithmsgraphsspanning-trees