I have two tuples, both with N values consisting of K unique values. Both tuples are similar. For example,
A = (1, 1, 0, 0, 2, 2, 2, 2) and B = (0, 0, 2, 2, 1, 1, 1, 1)
are both similar, and an isomorphism exists from A to B. However, given two slightly different tuples, say
A = (1, 1, 0, 0, 2, 2, 2, 2) and B = (0, 0, 2, 2, 1, 1, 0, 1)
I need to find a tuple isomorphic to A such that the new tuple (say C) and B share the maximum number of elements in the same position. Here, C would equal (0, 0, 2, 2, 1, 1, 1, 1).
What is the most efficient way to do this? Any brute force approach would have an O(K!) time complexity, and I'm hoping to find a faster algorithm.