Data Structures & AlgorithmsVery hardICPC regional · GATE CS

How many permutations of 1 to 6 have NO fixed point (that is, p[i] ≠ i for every position i)?

  1. A. 265
  2. B. 120
  3. C. 266
  4. D. 714

Correct answer: A. 265

Inclusion–exclusion over the set of fixed points gives D(n) = Σ (−1)^k C(n, k) (n−k)!, which equals 265 for n = 6. Counting permutations that avoid just one position gives a much larger wrong number.

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

Exams that ask this topic