Question bank — DP problems — rod cutting, egg drop, DP on trees
True or false — justify
Recall Reveal all
Rod cutting requires that the cuts be made at integer positions. ::: True — the price array only defines values for integer lengths, so a "piece of length 2.5" has no defined price; the whole model lives on integers. In rod cutting, looping the leftmost piece over misses some cuttings because it never fixes the rightmost piece. ::: False — every cutting has exactly one leftmost piece, so ranging over all leftmost lengths and recursing on the rest already covers every arrangement; fixing the rightmost would be a redundant second way to say the same thing. Egg drop's answer can never exceed . ::: True — the one-egg strategy (scan floor by floor) always works and costs at most drops, so more eggs can only help; . With unlimited eggs, egg drop collapses to binary search and the answer is . ::: True — with eggs to spare a break is never catastrophic, so each drop can split the remaining candidate floors plus the "no floor" outcome in half; drops distinguish at most outcomes, and there are possible thresholds (floors or "never breaks"), so you need , i.e. . In DP on trees, the two states and are needed because a node's optimal contribution depends on a choice its parent hasn't made yet. ::: True — the parent must know "what's the best you offer if I take you" versus "if I don't", so the child publishes both and lets the parent pick. MWIS on a tree can be solved greedily by always picking leaves first. ::: False in general — picking leaves is a heuristic that can lose; the two-state DP is what guarantees optimality by comparing include-vs-exclude for every subtree. The rod-cutting recurrence is essentially unbounded knapsack in disguise. ::: True — each length is an item of "weight" and value reusable any number of times, capacity ; see Knapsack Problem. Memoizing the top-down rod-cutting recursion changes the answer it returns. ::: False — memoization only removes recomputation; the value is identical to the plain recursion, it just runs in instead of exponential time.
Spot the error
Recall Reveal all
"Rod cutting base case: because a length-1 rod can't be cut." ::: Error — you don't have to cut. : the "zero cuts" option (sell the whole piece) is always allowed, so equals the price of length 1, not 0. "Egg drop: when the egg breaks at floor , the sub-problem is floors below." ::: Error — a break means the threshold is at or below , leaving floors to test (floor itself is now known to be a breaking floor), so it's . "Egg drop: take the min of the break case and survive case, since we hope for the better outcome." ::: Error — you don't control which happens; the adversary (worst case) does, so you must take the max of the two, then minimize over . "MWIS: ." ::: Error — if is included, no child may be included, so each child is forced to state 0: . The only appears in . "MWIS: the answer is because including the root captures the most weight." ::: Error — the root might be better left out; the answer is . "DP on a tree must process nodes root-first (pre-order) so the root's answer is ready." ::: Error — a node needs its children's answers first, so you process leaves-up (post-order / DFS return); the root is computed last, not first. "Rod cutting is because you fill one array of size ." ::: Error — filling entry costs an inner loop of up to trials, so the total is , not .
Why questions
Recall Reveal all
Why does DP beat brute force for these three problems specifically? ::: Because the same subproblem (shorter rod / fewer eggs-floors / same subtree) recurs exponentially many times in the naive tree; solving each once and caching turns exponential into polynomial. Why is the tree case while rod cutting is ? ::: In a tree each edge is touched exactly once (each child feeds its parent once), whereas rod cutting re-scans all shorter lengths at every , giving a quadratic double loop. Why does egg drop use over but over outcomes? ::: You choose the drop floor to your advantage (min), but you cannot choose whether it breaks — nature/adversary picks the worse branch (max). Why can't we reuse the rod-cutting item-once logic here — why is it unbounded? ::: A length- piece can be cut out repeatedly (a length-6 rod could be three length-2 pieces), so each "item" is reusable, unlike 0/1 knapsack; that's why the recurrence recurses on (same rod again), not with item removed. Why does the "dual" egg-drop view give the same answer faster? ::: It flips the question to "with drops and eggs, how many floors can I clear?"; the drop splits floors into the break-branch (), the survive-branch (), plus the current floor. How do you recover from the dual ? ::: Since is strictly increasing in , "the fewest drops that clear floors" equals "the smallest with "; scan and stop at the first that reaches — that is , because but . Why do subtrees add cleanly in MWIS but "just adding" fails across a parent–child edge? ::: Sibling subtrees are disjoint (no shared nodes, no adjacency between them) so their optima add; a parent and child are adjacent, so they can't both be picked — that single constraint is exactly what the two states manage. Why is greedy correct for some problems but not MWIS? ::: Greedy Algorithms work only when a local best is guaranteed globally optimal (matroid-like structure); MWIS lacks it because a heavy node blocks neighbors whose combined weight can exceed it.
Edge cases
Recall Reveal all
Rod cutting with : what is ? ::: — an empty rod yields no revenue; this base case anchors every longer recurrence.
Rod cutting where selling whole always wins — does the algorithm still cut? ::: No — trying leftmost piece leaves , giving ; if that's the max, cut[n]=n records a single (trivial) piece, i.e. no real cut.
Egg drop with a single egg, , arbitrary : what is ? ::: — one egg forces a bottom-up linear scan (a break is permanent, so you can never risk skipping a floor), costing up to drops in the worst case.
Egg drop with eggs and floors: what should be? ::: Undefined / impossible () — with no eggs you can never test a floor, so no finite strategy guarantees finding ; only is a safe zero.
Egg drop with floors: why is for every ? ::: There is nothing to identify — zero floors means the threshold question is already resolved, so zero drops are needed regardless of egg count.
Egg drop, exactly 1 floor: why is and not 0? ::: You still must confirm whether that single floor is a breaking floor, which requires one drop; knowing the building exists isn't the same as knowing the threshold.
MWIS on an empty tree (zero nodes): what's the answer? ::: — the empty set is a valid independent set with total weight 0; the DFS never runs, so no state is set and the base return is 0.
MWIS on a single-node tree: what's the answer? ::: if ; a lone node has no neighbor to block it.
MWIS with all-negative weights: does the DP still work? ::: Yes — the exclude state can leave every node out (contributing 0), so the answer is ; the "empty set" is always a legal independent set.
A path graph (a degenerate "tree" that is one line): does tree-MWIS still apply? ::: Yes — root it at one end and DFS; the recurrence reduces to the classic 1-D house-robber DP, since each node has at most one child.
Star graph, centre weight 10, four leaves weight 4: what does the DP output and why does greedy fail? ::: DP outputs (all four leaves), because excluding the centre frees every leaf; greedy grabs the centre (10) first, blocks all leaves, and loses — the two-state comparison catches this globally.