2
I’m trying to find a subset, of size M, of binary strings of length n, where any string has a distance greater than 2 for any other string in the subset.
Where the distance between two strings is the number of positions where they differ. For example, the distance between 101 and 011 is 2.
Example: {00000,00001,00010,00011,00100,00101,00110,00111,01000,01001,01010,01011,01100,01101,01110,01111,10000,10001,10010,10011,10100,10101,10110,10111,11000,11001,11010,11011,11100,11101,11110,11111}
A subset with 3 elements with distance > 2 would be {00000,00111,11001}. Suppose that with this choice, I cannot add any more elements to the subset. I want the program to remove the last placed element, 01011, and put the next one that has dist > 2 to 00000 and 00111, in case, 11001. Then the subset would be {00000,00111,11010}. And he would be able to add one more element, which would be 11101.
And give me the subset {00000,00111,11010,11101}.
This is a difficult problem. But I need to solve for small cases, so a brute force program is enough.
Note: A greedy algorithm does not solve all the cases I need.
Hi. Welcome to SOPT. Your question is somewhat difficult to answer because you don’t explain your code and what it does is also somewhat vague. You talk about a set of strings, but you don’t exemplify or illustrate the strings. You say you "don’t get an answer," but what would be the expected answer? Anyway, it’s hard for anyone to even be interested in helping you. I suggest you read [Ask] and edit your question to explain exactly what your difficulty is. If the problem is wide, break it into smaller pieces (you can open more than one question here).
– Luiz Vieira
I tried hard to understand your problem, but it’s not very clear what you’re trying to do, at first your problem seems to be related to the Levenshtein Distance, but it’s just a hunch...
– ederwander
Thanks, I tried to explain better. The program must be very bad, I know almost nothing of python, sorry, rs
– Natália
"A subset with 3 elements with distance > 2 would be {00000,00111,01011}". No, it wouldn’t be, because the distance between "00111" and "01011" is 2.
– Luiz Vieira
@Luizvieira removed my answer, the last edition left me more confused about the actual functioning of the algorithm, as far as I had understood, she seemed to be comparing the first element with the others, and was doing this successively until comparing all, unfortunately it’s not yet clear to me, maybe someone else with more patience.
– ederwander
Yes, indeed, the example was wrong. Thank you. Only need a set where any element has distance > 2 for any other element of the set =/ Rs
– Natália