Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8447879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:17:08+00:00 2026-06-10T10:17:08+00:00

I want to find an algorithm to find the pair of bitstrings in an

  • 0

I want to find an algorithm to find the pair of bitstrings in an array that have the largest number of common set bits (among all pairs in the array). I know it is possible to do this by comparing all pairs of bitstrings in the array, but this is O(n2). Is there a more efficient algorithm? Ideally, I would like the algorithm to work incrementally by processing one incoming bitstring in each iteration.

For example, suppose we have this array of bitstrings (of length 8):

B1:01010001 
B2:01101010
B3:01101010
B4:11001010
B5:00110001 

The best pair here is B2 and B3, which have four common set bits.

I found a paper that appears to describe such an algorithm (S. Taylor & T. Drummond (2011); “Binary Histogrammed Intensity Patches for Efficient and Robust Matching“; Int. J. Comput. Vis. 94:241–265), but I don’t understand this description from page 252:

This can be incrementally updated in each iteration as the only [bitstring] overlaps that need recomputing are those for the new parent feature and any other [bitstrings] in the root whose “most overlapping feature” was one of the two selected for combination. This avoids the need for the O(N2) overlap comparison in every iteration and allows a forest for a typically-sized database of 700 features to be built in under a second.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T10:17:09+00:00Added an answer on June 10, 2026 at 10:17 am

    As far as I can tell, Taylor & Drummond (2011) do not purport to give an O(n) algorithm for finding the pair of bitstrings in an array with the largest number of common set bits. They sketch an argument that a record of the best such pairs can be updated in O(n) after a new bitstring has been added to the array (and two old bitstrings removed).

    Certainly the explanation of the algorithm on page 252 is not very clear, and I think their sketch argument that the record can be updated in O(n) is incomplete at best, so I can see why you are confused.

    Anyway, here’s my best attempt to explain Algorithm 1 from the paper.

    Algorithm

    The algorithm takes an array of bitstrings and constructs a lookup tree. A lookup tree is a binary forest (set of binary trees) whose leaves are the original bitstrings from the array, whose internal nodes are new bitstrings, and where if node A is a parent of node B, then A & B = A (that is, all the set bits in A are also set in B).

    For example, if the input is this array of bitstrings:

    Array of bitstrings

    then the output is the lookup tree:

    Lookup tree

    The algorithm as described in the paper proceeds as follows:

    1. Let R be the initial set of bitstrings (the root set).

    2. For each bitstring f1 in R that has no partner in R, find and record its partner (the bitstring f2 in R − {f1} which has the largest number of set bits in common with f1) and record the number of bits they have in common.

    3. If there is no pair of bitstrings in R with any common set bits, stop.

    4. Let f1 and f2 be the pair of bitstrings in R with the largest number of common set bits.

    5. Let p = f1 & f2 be the parent of f1 and f2.

    6. Remove f1 and f2 from R; add p to R.

    7. Go to step 2.

    Analysis

    Suppose that the array contains n bitstrings of fixed length. Then the algorithm as described is O(n3) because step 2 is O(n2), and there are O(n) iterations, because at each iteration we remove two bitstrings from R and add one.

    The paper contains an argument that step 2 is Ω(n2) only on the first time around the loop, and on other iterations it is O(n) because we only have to find the partner of p “and any other bitstrings in R whose partner was one of the two selected for combination.” However, this argument is not convincing to me: it is not clear that there are only O(1) other such bitstrings. (Maybe there’s a better argument?)

    We could bring the algorithm down to O(n2) by storing the number of common set bits between every pair of bitstrings. This requires O(n2) extra space.

    Reference

    • S. Taylor & T. Drummond (2011). “Binary Histogrammed Intensity Patches for Efficient and Robust Matching”. Int. J. Comput. Vis. 94:241–265.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a set of vertices(called A) and I want to find all the
I want to find parameters for some CRC-24 algorithm. All I know is that:
I am currently working on a algorithm that needs to find all equal occurrences
Suppose that we have a set of number as P = { p1, p2,
Let A[1]<=A[2]<=....<=A[n]. Let X be an arbitrary number. Give an algorithm find all pairs
I want find all Saturdays and Sundays in A given month. How can I
I want to find the Xelement attribute.value which children have a concrete attribute.value. string
I want to find out if it is possible to create Android API's that
I want to find the first element that has appeared in previous positions in
I want to find all the demo words using PHP and regEx. $input ='demo';

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.