Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Combine the two permutations p 1 and p 2 into a result permutation p that represents the operation of first applying permutation p 2 to
Combine the two permutations p and p into a result permutation p that represents the operation of first applying permutation p to the given array, followed by applying permutation p to this intermediate result.
public static int chainint p int p
int p new intplength;
for int i ; i plength; i
pi ppi;
return p;
Given the permutation perm, construct its inverse permutation that, when combined with perm, produces the identity permutation for which pi i for all positions i
public static int inverseint perm
int inv new intpermlength;
for int i ; i perm.length; i
invpermi i;
return inv;
The square of the permutation is constructed by combining it with itself.
public static int squareint perm
return chainperm perm;
Compute the kth power of the given permutation perm, that is the result of chaining perm with itself k times.
public static int powerint perm, int k
if k
int idenPerm new intpermlength;
for int i ; i perm.length; i
idenPermi i;
return idenPerm;
else if k
return perm;
else if k
return squareperm;
else if k
return powerinversepermk;
else if k
int tempPerm powerperm k;
return squaretempPerm;
else
int tempPerm powerpermk;
return chainperm squaretempPerm;
Main method for testing
public static void mainString args
int perm;
int perm;
int perm;
int res powerperm;
int res powerperm;
int res powerperm;
Print expected and actual results
System.out.printlnExpected result for perm: ;
System.out.printlnActual result: Arrays.toStringres;
System.out.printlnExpected result for perm: ;
System.out.printlnActual result: Arrays.toStringres;
System.out.printlnExpected result for perm: ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started