Let's say we have two arrays: Array a1 and Array a2.
'a1' and 'a2' are similar in a way such that both have the same size and same elements but elements don't appear in the same order.
What will be the most effective way of comparing both arrays and finding out the minimum number of swaps required to bring the array 'a1' in the same order as 'a2'?
For example:
int a1[5] = { 1, 2, 3, 4, 5};
int a2[5] = { 2, 3, 1, 5, 4};
Hence the minimum number of swaps required is: 3
In steps:
swap 1: a1[0] <-> a1[1]
swap 2: a1[1] <-> a1[2]
swap 3: a1[3] <-> a1[4]
So, finally a1 will contain { 2, 3, 1, 5, 4}