A permutation p1
of 1,2,...,n is even
) if it can be returned to the original order 1,2,...,n using an even (resp. odd) number of interchanges of pairs of elements. It is known that every permutation is either even or odd (and therefore not both).
The sign, or signum (for those who want to be fancy), of a permutation is +1 for an even permutation and -1 for an odd permutation.
You are given the integer n and the array p initialized to the integer values p=p1, p=p2, ..., p[n]=pn which are guaranteed to be a permutation of 1,2,...,n. What algorithm would you advocate for determining the sign of the permutation? You need not preserve the original contents of p.
(In reply to re: No Subject
Even more obviously both 4321 and 4312 have no fixed points but differ by only one interchange and therefore have the same sign.
Posted by Charlie
on 2006-08-07 13:10:13