Data Structures & AlgorithmsVery hard

Why does the lexicographically smallest arrangement with a 'no fixed point' constraint start with the value 2?

  1. A. Derangements always start with the largest value.
  2. B. Position 1 cannot hold the value 1 because that would be a fixed point, and 2 is then the smallest allowed value for that position.
  3. C. The first position is always the value 5.
  4. D. Lexicographic order ignores the first position.

Correct answer: B. Position 1 cannot hold the value 1 because that would be a fixed point, and 2 is then the smallest allowed value for that position.

The constraint forbids the value i at position i, so position 1 must hold something other than 1, and 2 is the smallest such choice. The rest of the permutation then follows the same greedy rule.

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

Exams that ask this topic