Group Abstract Group Abstract

Message Boards Message Boards

5
|
3.9K Views
|
1 Reply
|
10 Total Likes
View groups...
Share
Share this post:

Efficient sort by template

Posted 10 years ago

You are given 2 vectors:

x={a,b,c,d,e,f,r,e,t};
y={f,a,c,f,b,a,b,f,g};

and need to sort vector y in such a way that the HammingDistance[x,y] is minimized. This literal implementation:

HumMin[x_, y_] := First[MinimalBy[Permutations[y], HammingDistance[#, x] &, 1]]

x
HumMin[x, y]    
(*{a,b,c,d,e,f,r,e,t}*)
(*{a,b,c,f,f,f,b,a,g}*)

is terribly inefficient due to generally large space of Permutations[y]. The order of non-matching elements between x and y is not important, so there could be several equivalent solutions and any would do. So in principle an algorithm should stop as soon as first solution is found. THis is when all elements of y identical to some elements of x aligned at the same position if possible. For example it is possible for one a in y and impossible for the other. What would be a more efficient implementation?

POSTED BY: Vitaliy Kaurov
POSTED BY: Daniel Lichtblau
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard