Data Structures & AlgorithmsVery hard

Among all permutations of 1, 2, 3, 4, 5 with NO fixed point (no position i holds the value i), which permutation is lexicographically smallest? Give it as five space-separated numbers.

  1. A. 1 2 3 4 5
  2. B. 2 1 3 4 5
  3. C. 2 1 4 5 3
  4. D. 5 4 2 3 1

Correct answer: C. 2 1 4 5 3

A derangement is a permutation with no fixed point; the lexicographic minimum starts with 2 because position 1 cannot hold 1. Brute force over 120 permutations confirms the first valid one in dictionary order.

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

Exams that ask this topic