Data Structures & AlgorithmsVery hard

Why is the minimum over all rotations of a permutation's inversion count achieved by a specific rotation that can be found in linear time?

  1. A. All rotations have the same inversion count.
  2. B. Rotating by one moves the first element to the end, which changes the inversion count by an amount computable from counts of smaller and larger values in O(1) per step.
  3. C. The minimum is always at the identity rotation.
  4. D. Inversions cannot be counted after rotation.

Correct answer: B. Rotating by one moves the first element to the end, which changes the inversion count by an amount computable from counts of smaller and larger values in O(1) per step.

Moving the first element to the end removes its inversions with smaller elements and adds those with larger elements, a simple update. The sequence of counts is therefore computed incrementally.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic