Questions tagged [hamming-distance]

The Hamming distance is a mathematical distance function for a pair of strings (sequences) that can be computed with a binary calculation. It counts the number of symbols in the string that are different. Posts that are not about implementation may belong on https://math.stackexchange.com.

For the special case of two binary strings, it may be implemented as the bitcount of their XOR:

int H(int a, int b){
    return popcount(a^b);
}
291 questions
11
votes
2 answers

Fast calculate hamming distance in C

I read the Wikipedia article on Hamming Weight and noticed something interesting: It is thus equivalent to the Hamming distance from the all-zero string of the same length. For the most typical case, a string of bits, this is the number of 1's in…
haneefmubarak
  • 1,911
  • 1
  • 21
  • 32
11
votes
2 answers

How to count the hamming distance of two short int?

Hamming Distance: For example, two binary number: 1011 and 1000's HD(Hamming distance) is 2. The 10000 and 01111's HD is 5. Here is the code: Can some one explain it to me? Thanks! short HammingDist(short x, short y) { short dist = 0; char val =…
David Ding
  • 680
  • 3
  • 9
  • 19
10
votes
3 answers

Hamming Distance / Similarity searches in a database

I have a process, similar to tineye that generates perceptual hashes, these are 32bit ints. I intend to store these in a sql database (maybe a nosql db) in the future However, I'm stumped at how I would be able to retrieve records based on the…
oPless
  • 618
  • 1
  • 8
  • 18
10
votes
4 answers

How to find the closest pairs (Hamming Distance) of a string of binary bins in Ruby without O^2 issues?

I've got a MongoDB with about 1 million documents in it. These documents all have a string that represents a 256 bit bin of 1s and 0s, like: 0110101010101010110101010101 Ideally, I'd like to query for near binary matches. This means, if the two…
Williamf
  • 595
  • 4
  • 14
10
votes
3 answers

Search for bitstring most unlike a set of bitstrings

I have a set of bitstrings: {'0011', '1100', '1110'} (all bitstrings within a set are of same length). I want to quickly find the bitstring of same length that has the smallest max-similarity to the set. Max-similarity can be computed as such: def…
RoyM
  • 735
  • 3
  • 14
10
votes
4 answers

Fastest way to get hamming distance for integer array

Let a and b be vectors of the same size with 8-bit integers (0-255). I want to compute the number of bits where those vectors differs i.e. a Hamming distance between vectors formed by concatenation of binary representations of those numbers. For…
Debasish Mitra
  • 1,394
  • 1
  • 14
  • 17
10
votes
2 answers

Algorithm/approximation for combined independent set/hamming distance

Input: Graph G Output: several independent sets, so that the membership of a node to all independent sets is unique. A node therefore has no connections to any node in its own set. Here is an example path. Since clarification was called for here…
tarrasch
  • 2,630
  • 8
  • 37
  • 61
9
votes
2 answers

Finding the minimum Hamming distance in less than O(n^2m) time

If you have n binary strings, each of length m, is there a faster way to determine the minimum Hamming distance between any pair than to compare all O(n^2) pairs and for each to compute their Hamming distance? That is can it be done in less than…
Simd
  • 19,447
  • 42
  • 136
  • 271
9
votes
5 answers

Similarity distance measures

Vectors like this v1 = {0 0 0 1 1 0 0 1 0 1 1} v2 = {0 1 1 1 1 1 0 1 0 1 0} v3 = {0 0 0 0 0 0 0 0 0 0 1} Need to calculate similarity between them. Hamming distance between v1 and v2 is 4 and between v1 and v3 is also 4. But because I am…
user1306283
8
votes
1 answer

What is the hamming distance, and how do I determine it for a CRC scheme?

While studying for a class in computer networks, the prof talked about the hamming distance between 2 valid code words in a sample code. I have read about hamming distance, and it makes sense from the perspective of telling the difference distance…
naivedeveloper
  • 2,814
  • 8
  • 34
  • 43
7
votes
3 answers

Compare two binary numbers and get the different bits

Possible Duplicate: Best algorithm to count the number of set bits in a 32-bit integer? I want to write a program to get the number of 1's bit in comparing two numbers.if I compare the bits between any two numbers to find where the binary numbers…
TTT
  • 358
  • 3
  • 6
  • 16
7
votes
4 answers

How to generates a list which elements are at a fix distance from a desired list

I have a list of possibilities and a desired input: possibles = [20, 30, 40, 50, 60, 70, 80, 100] desired = [20, 30, 40] I want to generate the close by lists. Example: # Distance of 1 (i.e. 1 element changes to a close-by) [30, 30, 40] [20, 40,…
Mathieu
  • 5,410
  • 6
  • 28
  • 55
7
votes
3 answers

What is the fastest way to XOR A LOT of binary arrays in python?

I am tasked with calculating hamming distances between 1D binary arrays in two groups - a group of 3000 arrays and a group of 10000 arrays, and every array is 100 items(bits) long. So thats 3000x10000 HD calculations on 100 bit long objects.And all…
AlanKalane
  • 981
  • 1
  • 8
  • 17
7
votes
3 answers

find the Hamming distance between two DNA strings

i'm just learning python 3 now. '''It's ask the user for two string and find the Hamming distance between the strings.Input sequences should only include nucleotides ‘A’, ’T’, ‘G’ and ‘C’. Program should ask the user to reenter the sequence if user…
Lena
  • 71
  • 1
  • 2
7
votes
2 answers

Which data structure to store binary strings and query with hamming distane

I'm looking for a data structure to handle bilions of binary strings that contains 512 binary values. My goal is to send querys to the structure and get a resultset which contains all data that are lower a distance. My first idea was to use a kd…
501 - not implemented
  • 2,638
  • 4
  • 39
  • 74
1
2
3
19 20