Generate all sequences of bits within Hamming distance t

后端 未结 4 1492
春和景丽
春和景丽 2020-12-04 03:22

Given a vector of bits v, compute the collection of bits that have Hamming distance 1 with v, then with distance 2, up to an input paramet

4条回答
  •  -上瘾入骨i
    2020-12-04 03:59

    If Hamming distance h(u, v) = k, then u^v has exactly k bits set. In other words, computing u ^ m over all masks m with k bits set gives all words with the desired Hamming distance. Notice that such set of mask does not depend on u.

    That is, for n and t reasonably small, precompute sets of masks with k bits set, for all k in 1,t, and iterate over these sets as required.

    If you don't have enough memory, you may generate the k-bit patterns on the fly. See this discussion for details.

提交回复
热议问题