Lessons 26–30 · About 60 min per lesson

Combined problems, proofs and review

Decide which tool handles each part of a problem and verify the combined solution.

Lesson breakdown

  1. Lesson 26

    Choose states, a graph model or dynamic aggregation from constraints.

  2. Lesson 27

    Combine sorting for rank compression with a Fenwick tree to count inversions.

  3. Lesson 28

    Write a correctness argument for the key transition or update.

  4. Lesson 29

    Design an exhaustive reference, random small inputs and important boundary cases.

  5. Lesson 30

    Organise approaches, code, checks and costs for two problems.

Worked example

Count inversions in [3,1,2,1], using strictly greater left values.

How to solve it

Scanning left to right, count previously seen values that are strictly greater. Counts are 0, 1, 1 and 2, for 4. The equal 1s contribute no pair.

Assignment

Compare your inversion counter with nested loops. For the final assessment, derive the time bound for Time is Mooney and handle equal shortest paths in Shortcut.

Check your result

The example gives 4, equal values give 0, and four decreasing values give 6. For each past problem, submit code, complexity and a test that would catch a wrong approach.