The Greedy Algorithm for Submodular Maximization
The greedy algorithm achieves a (1 - 1/e) approximation for monotone submodular maximization, provably the best any efficient algorithm can do. This post covers the algorithm, its proof, and when greedy fails.
Series parts
On this page
In Part 1, I defined submodular functions and showed that they capture the pattern of diminishing returns across sensor placement, document summarization, influence maximization, and many other domains. I formalized the constrained maximization problem: given a monotone submodular function and a budget , find subject to . I also showed that this problem is NP-hard: enumerating all candidate subsets is intractable for any realistic problem size.
The question becomes: how do we find a good solution efficiently, given that finding the exact optimum is out of reach? The answer lies in approximation algorithms.
Approximation Algorithms
An -approximation algorithm for a maximization problem runs in polynomial time and, for every instance of the problem, returns a solution whose value is at least . Here is the value of the optimal solution. The factor is called the approximation ratio (or performance guarantee).
For instance, a -approximation algorithm for a maximization problem produces a solution worth at least half of the true optimum, on every instance. Note that this lower-bound guarantee holds for the worst-case, so the algorithm may perform significantly better on many practical instances.
I can think of at least three reasons to care about approximation algorithms. They offer:
- Polynomial-time solutions to NP-hard problems. We cannot solve these problems exactly in polynomial time (unless P NP), but we can get provably close.
- A rigorous metric for comparing heuristics. Instead of “this heuristic works well on my benchmark,” you get results like “this algorithm is within 63.2% of optimal on every possible input”. The guarantee does not depend on the dataset!
- Implicit bounds on the optimum. When an -approximation algorithm returns a solution of value , it also tells you that . That bound is useful when computing the exact optimum is too expensive, which tends to be the case in practice.
For minimization problems, the convention flips: , and the algorithm’s output is at most . A -approximation for a minimization problem never exceeds twice the optimal cost.
The Greedy Algorithm
The greedy algorithm for monotone submodular maximization under a cardinality constraint is as simple and elegant as it can be, and left me in awe when I first learned it.
It is a single unconditional loop that, starting from an empty set (), repeatedly adds the element with the largest marginal gain to the current solution. Each iteration adds a single element to the solution set, without repetitions, for a total of iterations. Once an element is greedily picked, it is never removed. The algorithm is greedy because each step makes the locally optimal choice of the element with the largest marginal gain.
That’s it, that’s the entire algorithm. No relaxation step, no rounding, no linear program. Fully deterministic too!
Runtime. At each of the iterations, the algorithm evaluates for every element . Each marginal gain computation requires one call to the value oracle for , the black box from Part 1. The total cost is oracle calls.
A Worked Example: Sensor Coverage
Consider 6 candidate sensor locations on a grid, labeled , and a budget of . Each sensor covers a circular region, and the submodular function measures the total area covered by the union of all sensors in . The sensors have different ranges, so each one covers a different amount of area on its own.
In the map below, solid circles are placed sensors, and dashed arcs mark the new area each remaining sensor would still add. Hover over any sensor to see its current marginal gain. Run the algorithm one step at a time, then try placing the sensors yourself and see if you can beat it.
Greedy will score all 6 sensors by the area each one covers, then place the best.
Map of six candidate sensor locations. No sensors placed yet.
New area each would add. One oracle call per bar.
Step 1. The algorithm computes the marginal gain for each candidate , since the current set is empty. Suppose sensor 3 covers the largest area individually. We set .
Step 2. The algorithm recomputes the marginal gain of each remaining element with respect to the current solution . Sensor 5, which covers a region that barely overlaps with sensor 3, has the highest additional area. We set .
Step 3. Same logic. Sensor 1 adds the most new area given that sensors 3 and 5 are already placed. We set .
It’s crucial to notice that, at each step, the marginal gain of the selected sensor decreases. The first sensor might cover 120 on its own; the second adds 95 of new area; the third adds only 60 . That decline is submodularity at work: the same sensor would have contributed more if placed earlier, when less ground was already covered.
For a ground set this small, you can enumerate all possible subsets and verify that the greedy solution is close to (or exactly equal to) the true optimum. On realistic instances with thousands of candidate locations, enumeration is of course impossible, but the greedy solution is still guaranteed to be within a precise factor of the optimum. In this case, this factor is guaranteed to be approximately , as I’ll show in a moment.
The Approximation Guarantee
The following result, due to Nemhauser, Wolsey, and Fisher (1978)1, is arguably the most celebrated theorem in submodular optimization.
Theorem. Let be a monotone submodular function, and let be a positive integer. The Greedy algorithm returns a set satisfying:
where is the optimal solution and is Euler’s number.
Since , the greedy algorithm always returns a solution worth at least of the true optimum. The guarantee holds for every monotone submodular function and every cardinality constraint . No randomization, no special structure, no tuning.
Two additional facts make this result striking:
- The bound is tight: there exist instances where the greedy algorithm achieves exactly a fraction of the optimum and no better.
- The bound is optimal: Feige (1998)2 proved that no polynomial-time algorithm can achieve an approximation ratio better than for this problem, unless P NP.
In other words, the greedy algorithm gives us the best possible approximation guarantee for monotone submodular maximization under a cardinality constraint. This however doesn’t mean that greedy is the fastest algorithm for this kind of problem. If you are interested in faster variants, Part 3 and Part 4 of this series cover two of them.
Pick a submodular objective below, then run the race. Greedy picks the element with the highest marginal gain at each step. Random picks blindly. Both select k elements from a ground set of n. How close does each strategy get to the optimum?
Hire a team that covers the most distinct skills. Each candidate knows 2–5 skills; overlapping skills don't count twice.
Why Does It Work? A Proof Sketch
The proof has three key steps. I will renounce the full formalism for the sake of emphasizing the geometric intuition behind it.
Step 1: Each Greedy Step Closes a Fraction of the Gap
Let be the greedy solution after steps, and let be the optimal solution with . Define the gap at step as:
The gap measures how far the current greedy solution is from the optimum. At step , the greedy algorithm picks the element with the largest marginal gain .
The optimal solution contains at most elements. By the monotonicity of , we know that , so the total marginal gain of adding all elements of to is at least . By submodularity, the marginal gains of individual elements of (with respect to ) sum to at least this gap3:
Since , at least one element in has marginal gain at least . The greedy algorithm picks the best element overall, so:
In words: each greedy step closes at least a fraction of the remaining gap.
Step 2: The Gap Shrinks Geometrically
The inequality above means that after step :
Apply this recursively from the initial gap , assuming , which is standard for these problems:
Step 3: Bounding the Geometric Compound
The expression is a well-known sequence from calculus. It is monotonically increasing and converges to as 4.
The sequence rises steeply for small k and levels off well before k = 10. The dashed line marks the limit 1/e ≈ 0.368. Hover or tap a point to inspect its value.
Since for all , we get:
Rearranging:
Each step closes at least a fraction of the gap; the gap compounds geometrically; and the geometric compound is bounded above by .
Each step closes at least a 1/k fraction of the remaining gap. The teal bars show f(Sj) rising; the faded region above is the gap δj. Step through to watch the gap compound geometrically.
When Greedy Fails
The guarantee depends critically on monotonicity. When is non-monotone (i.e., adding elements can decrease ), the greedy algorithm can perform arbitrarily badly.
The thesis chapter I drew this material from contains a concrete counterexample. Consider a ground set and define the non-monotone submodular function:
Let . At the first step, the greedy algorithm adds element , because its marginal gain is , which is the largest among all singletons (every other element has a gain of ). Once is in the solution, it stays there; the algorithm only adds elements, never removes them. The consequence: no matter what the algorithm picks in the remaining steps, the function value is stuck at , because the presence of forces for any containing .
The optimal solution is to take any elements other than , yielding . The greedy solution achieves . The approximation ratio is , which goes to as grows. The algorithm gets trapped by a locally attractive choice that is globally catastrophic.
This tells us that, for non-monotone submodular functions, standard greedy is the wrong tool. Randomized variants like the Random Greedy algorithm (Buchbinder et al. 2014)5 recover a constant approximation ratio of by introducing randomness into the selection step, at the cost of a weaker guarantee.
The type of constraint also matters. With a cardinality constraint, the greedy algorithm achieves . With a single matroid constraint (a generalization of cardinality constraints), the same ratio holds, though the analysis that proves it is more involved6. With knapsack constraints, where each element has a cost and the total budget is limited, one needs different algorithms altogether, which I’ll let you explore autonomously.
Looking Ahead
The greedy algorithm requires function evaluations. For moderate problem sizes, this is fine. For massive datasets ( in the millions, in the thousands), even becomes prohibitive.
The next two parts of this series attack that cost from different angles. In Part 3, I will show how Lazy Greedy exploits the diminishing returns property itself to skip most recomputations, keeping the guarantee fully intact. In Part 4, I will introduce the Stochastic Greedy algorithm, which replaces the full scan over at each step with a random subsample. The total cost drops from to ; the factor of becomes a logarithmic term, at the price of a slightly weaker guarantee.
Key Takeaways
- The greedy algorithm for monotone submodular maximization under a cardinality constraint is simple: at each step, pick the element with the largest marginal gain. Repeat times.
- It achieves an approximation ratio of , provably the best any efficient algorithm can achieve for this problem.
- The proof relies on a geometric argument: each greedy step closes at least a fraction of the remaining gap to the optimum, and after steps the residual gap is at most .
- The greedy algorithm requires function evaluations. For massive datasets, this becomes too expensive, motivating the faster variants in Part 3 and Part 4.
- Monotonicity is critical: without it, greedy can achieve an approximation ratio as bad as , which is effectively useless for large .
Further Reading
- G. L. Nemhauser, L. A. Wolsey, and M. L. Fisher, “An Analysis of Approximations for Maximizing Submodular Set Functions” (1978). The original paper proving the bound.
- U. Feige, “A Threshold of for Approximating Set Cover” (1998). The hardness result establishing that is optimal.
- A. Krause and D. Golovin, “Submodular Function Maximization” (2014). A survey covering greedy, its accelerated variants, and continuous relaxation methods.
- D. P. Williamson and D. B. Shmoys, “The Design of Approximation Algorithms” (2011). A broader textbook on approximation algorithms.