Convexity often arises naturally in many “intuitively” greedy problems. We’ll first give some examples, then go over typical strategies for proving convexity, as well as how to take advantage of it.

Examples

You are given an array 𝑎 of 𝑛 integers. Select 𝑘 distinct indices such that the sum of 𝑎𝑖 at those indices is minimized.

It’s not difficult to see that the answer is convex in 𝑘.

You are given an array of length 𝑛. If you place exactly 𝑘 tiles of length 𝑙 without overlap, what’s the maximum sum of values that can be covered? (AtCoder)

(note that the first example is just this problem with 𝑙=1) Convexity is a little harder to prove here, but it still makes intuitive sense: with each new tile we add, the total sum gained should be less.

You are given a weighted tree, and some edges are labelled. Find the total weight of an MST that uses exactly 𝑘 edges. (QOJ)

Again, we may suspect that 𝑓(𝑘) will look something like a parabola, but this will be the hardest proof of the three example listed.

Proof Strategies

Interpolation

The idea of this strategy is to show that if we have solutions of size 𝑘1 and 𝑘+1 with costs 𝑓(𝑘1) and 𝑓(𝑘+1) respectively, we can construct a solution of size 𝑘 with cost 𝑓(𝑘1)+𝑓(𝑘+1)2 (or , depending on the problem).

Let’s apply this approach to the second example. First, consider 𝑙=1. Let’s draw two valid solutions, one for 𝑘1 and one for 𝑘+1, as follows: Green tiles are tiles common to both solutions.

Note that if we move the larger of the red and blue tiles over to the 𝑘1 solution, the resultant solution will have size 𝑘 and sum 𝑓(𝑘1)+𝑓(𝑘+1)2.

For 𝑙=1, we have to be a bit more clever. Consider the following: Edges are drawn between overlapping tiles. Note that each component forms a zig-zag pattern.

Our claim is that there exists two optimal solutions for 𝑘1 and 𝑘+1 such that all components are either green (equal # of tiles on left and right) or red (one more tile on right). Assuming this is true, there will be exactly two red components, and we can toggle the one with larger net gain to achieve 𝑓(𝑘)𝑓(𝑘1)+𝑓(𝑘+1)2.

Proof of assumption: If there exists a black component 𝐵, consider any other red component 𝑅. Toggle both 𝐵 and 𝑅 in the 𝑘1 solution (that is, replace the tiles in the left sides of 𝐵 and 𝑅 with the tiles on the right sides of 𝐵 and 𝑅). This cannot change the cost of the 𝑘1 solution, otherwise one of the two solutions would not be optimal. Thus 𝑓(𝑘1) and 𝑓(𝑘+1) remain the same while one black component is removed; repeat until no black components remaining.