In this tutorial, we will learn how to compute a permutation that transforms one sequence into another after applying a sequence of permutations. Specifically, we will use the following problem:
Problem Statement
We are given:
- An original sequence
S = ['A', 'B', 'C', 'D', 'E', 'F']
. - First permutation (
P1
): A permutation applied toS
to getS'
. For example:
P 1 = [ 5 , 2 , 3 , 4 , 0 , 1 ] P1 = [5, 2, 3, 4, 0, 1] P1=[5,2,3,4,0,1]
ApplyingP1
toS
givesS'
:
S ′ = [ F , C , D , E , A , B ] S' = [F, C, D, E, A, B] S′=[F,C,D,E,A,B] - Second permutation (
P2
): A permutation applied to the original sequenceS
to get a new sequenceS''
. For example:
P 2 = [ 2 , 3 , 4 , 1 , 0 , 5 ] P2 = [2, 3, 4, 1, 0, 5] P2=[2,3,4,1,0,5]
ApplyingP2
toS
givesS''
:
S ′ ′ = [ C , D , E , B , A , F ] S'' = [C, D, E, B, A, F] S′′=[C,D,E,B,A,F]
Our goal is to find a permutation P
such that applying P
to S'
(i.e., the result of applying P1
to S
) gives S''
.
Mathematical Representation
We want to find P
such that:
S ′ ′ = P ( S ′ ) = P ( P 1 ( S ) ) S'' = P(S') = P(P1(S)) S′′=P(S′)=P(P1(S))
where S'
is the result of applying P1
to S
, and S''
is the result of applying P2
to S
.
Step-by-Step Solution
Step 1: Compute the Inverse of Permutation P1
The first thing we need to do is compute the inverse of P1
, denoted as P1^{-1}
. The inverse of a permutation P
is the permutati