Definition · Independent set, and its weighted versionA set of vertices is independent if no edge joins two of them. Given a weight on each vertex, the maximum weight independent set problem asks for an independent set of largest total weight. On a general graph this is NP-hard; on a tree it is one pass, and this lesson is about why the difference is the tree and not the cleverness.
Theorem · The pair recurrence on a treeRoot the tree anywhere. For a vertex v with children u, let with(v) be the largest total over independent sets in v's subtree containing v, and without(v) the largest over those not containing it. Then with(v) = weight(v) + sum of without(u) and without(v) = sum of max(with(u), without(u)), and the answer is max(with(root), without(root)).
Take an independent set S in v's subtree that is largest among those containing v. No child of v is in S, since each is adjacent to v. For each child u, the part of S inside u's subtree is independent and avoids u, and it must be largest among such sets — otherwise substituting a heavier one gives a heavier S, and the substitution is legal because the subtrees are disjoint and share no edge. Summing gives the first equation.
If S is largest among sets avoiding v, each child is free, and the part of S in u's subtree must be a heaviest independent set there with no constraint, which is max(with(u), without(u)). Again the substitution is legal because distinct subtrees share no vertex and no edge. That disjointness is exactly what a tree provides and a cycle destroys, and it is where the proof would fail on a general graph.
□
The proof is worth reading twice for that last sentence. Optimal substructure here is not a property of the objective; it is a property of the input's shape. The same objective on a graph with one extra edge has no such decomposition, and no amount of care with the recurrence recovers it.
Example · A spine with legs, and the two heavy vertices that cannot both goThe lab loads a tree on seven vertices: a path 1-2-3-4 with extra leaves hanging off 2, 3 and 4, and weights 1 6 6 6 1 1 1. Vertices 2, 3 and 4 are the heavy ones and they form a path, so at most two of them can be chosen. The pass returns 13, choosing vertices 2, 4 and 6 — two of the three heavy ones and one leaf — and every one of the 128 subsets confirms 13.
The two checks, and why both
The chosen set is tested for independence against the edge list as it was typed, not against the adjacency structure the pass walked. That matters: a bug in building the adjacency map would make the pass and a structure-based check wrong in the same way, and the two would agree. Reading the raw edges is a route that shares nothing with the pass.
Then the set is re-weighed, and its total compared with the number the pass reported. Independence alone is not enough — the empty set is independent — and a matching total alone is not enough either, since a heavier but illegal set would also fail to be an answer. Both checks, separately, and the panel prints both verdicts.
Where the greedy instinct goes, and what the counts say
The instinct readers arrive with is to alternate: take every second level. On a path that is right, and the lab ships a path where it gives 15, the correct answer. On this tree, alternating from the root takes vertices 1, 3, 5 and 7 for a total of 9, against the optimum's 13 — and alternating the other way happens to give 13. A rule whose answer depends on which parity you start from is not a rule until that choice is made, and making it correctly is the problem again.
The measured counts are 7 vertex visits and 12 reads for the pass, against 128 subsets for the check, on a tree of seven vertices. The proved bounds are Θ(n) and Θ(2ⁿ n). Here the measurement and the bound agree in order already at n = 7, which is worth stating plainly because on three other pages of this course they do not — the coin table loses to a plain recursion at an amount of six, the chain table loses to enumeration at four matrices, and the last lesson of the course loses by a factor of forty.