1. What makes an order of filling a dynamic programming table correct?
A Every cell's inputs, the cells its recurrence reads, are filled before the cell itself B Filling the base cases last, once every other cell is known, so they can check the rest C Any order works, since each cell is computed exactly once and then never changes D Filling it row by row, top to bottom, which is always correct because every table is read in that order
2. For the longest increasing run with one deletion, why does the table need a row for nothing deleted and a row for at most one deleted?
A Two rows run faster than one, since each row only has to look one place back B To delete the element before a[i], you need the best run two places back that hasn't spent its deletion, and one number per position can't tell C One row would be enough if the array were sorted first, so the second row is there only to avoid the sort, which would cost O(n log n) and move the elements around D The second row stores which element was deleted, so the answer can print the run without it
3. In the edit distance table, what does moving from d[i - 1][j] to d[i][j] stand for?
A Keeping a letter both strings share B Inserting b[j - 1] C Deleting a[i - 1] D Swapping a[i - 1] for b[j - 1]
4. Several routes share the best score, and you must return the one whose list of junctions comes first. A forward pass that keeps a parent for each junction returns a best route that isn't that one. What fixes it?
A Sort the stretches by name before the forward pass, so the first parent found for each junction is the smallest B Fill the best total from each junction to an exit, then walk forward from the start, taking the smallest name among the stretches worth taking C Replace a parent on a tie as well as on a better total, so the junction with the smaller name always wins the tie, all the way back to the start D Return the route with the fewest stretches, since among the best routes the shortest list of junctions comes first
5. A lift is added that carries riders from an exit back up to the trailhead, and every lap of the loop is worth points. What happens to the best route?
A Nothing changes, since the topological order still handles it: the lift is one more stretch after the exit it leaves from B Dijkstra's algorithm finds it, since it works on graphs with cycles, where no topological order exists C The memoized recursion still finds it, more slowly, because each junction's best score is computed once and then reused around every lap of the loop D With repeats allowed there's no best score, because each lap adds points, and without repeats it's the longest simple path, NP-complete in general
6. A route may ride at most k expert stretches. Why does the table need a cell for every junction and every count up to k?
A Because the best total at a junction may have spent expert stretches that a worse total kept, and a later expert stretch can make the worse one win B Because Python lists can't hold pairs, so each count needs a separate cell in the table C It doesn't: one total per junction is enough if it also stores how many expert stretches that best total used, and compares counts when two totals tie D Because the answer is always at count k, so the table must fill every count up to k to reach it