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 927205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:48:44+00:00 2026-05-15T19:48:44+00:00

First of all, I don’t have multiplication, division operations so i could use shifting/adding,

  • 0

First of all, I don’t have multiplication, division operations so i could use shifting/adding, overflow-multiplication, precalculations etc. I’m just comparing one n-bit binary number to another, but according to algorithm the quantity of such operations seems to be huge. Here it is :

  1. There is given a sequence of 0’s and 1’s that is divided into blocks. Let the length of a sequence be S, the length of a block is N which is some power of two (4,8,16,32, etc.). Quantity of blocks is n=S/N, no rocket science here.
  2. According to chosen N i’m building a set of all possible N-bit binary numbers, which is a collection of 2^N-1 objects.
  3. After this I need to compare each binary number with each block from source sequence and calculate how much times there was a match for each binary number, for example :
    S : 000000001111111100000000111111110000000011111111… (0000000011111111 is repeated 6 times, 16bit x 6 = 96bits overall)
    N : 8
    blocks : {00000000, 11111111, 00000000, 1111111,…}
    calculations:

.

// _n = S/N;
// _N2 = Math.Pow(2,N)-1
// S=96, N=8, n=12, 2^N-1=255 for this specific case
// sourceEpsilons = list of blocks from input, List<string>[_n]
var X = new int[_n]; // result array of frequencies
for (var i = 0; i < X.Length; i++) X[i] = 0; // setting up
for (ulong l = 0; l <= _N2; l++) // loop from 0 to max N-bit binary number
var currentl = l.ToBinaryNumberString(_N/8); // converting counter to string, getting "current binary number as string"
var sum = 0; // quantity of currentl numbers in blocks array
for (long i = 0; i < sourceEpsilons.LongLength; i++)
{
   if (currentl == sourceEpsilons[i]) sum++; // evaluations of strings, evaluation of numbers (longs) takes the same time
}
// sum is different each time, != blocks quantity                    
for (var j = 0; j < X.Length; j++) 
if (sum - 1 == j) X[j]++; // further processing
// result : 00000000 was matched 6 times, 11111111 6 times, X[6]=2. Don't ask me why do i need this >_<

With even small S i seem to have (2^N-1)(S/N) iterations, with N=64 the number grows to 2^64=(max value of type long) so that ain’t pretty. I’m sure there is a need to optimize loops and maybe change the approach cardinally (c# implementation for N=32 takes 2h @ dual-core pc w/ Parallel.For). Any ideas how to make the above scheme less time and resource-consuming? It seems like i have to precompute binary numbers and get rid of first loop by reading “i” from file and evaluate it with blocks “on-the-fly”, but the filesize will be (2^N)*N bytes ((2^N-1)+1)*N) which is somehow unacceptable too.

  • 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-05-15T19:48:44+00:00Added an answer on May 15, 2026 at 7:48 pm

    It seems like what you want is a count of how many times each specific block occurred in your sequence; if that’s the case, comparing every block to all possible blocks and then tallying is a horrible way to go about it. You’re much better off making a dictionary that maps blocks to counts; something like this:

    var dict = Dictionary<int, int>();
    for (int j=0; j<blocks_count; j++)
    {
        int count;
        if (dict.TryGetValue(block[j], out count)) // block seen before, so increment
        {
            dict[block[j]] = count + 1;
        }
        else // first time seeing this block, so set count to 1
        {
            dict[block[j]] = 1; 
        }
    }
    

    After this, the count q for any particular block will be in dict[the_block], and if that key doesn’t exist, then the count is 0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, I don't want to use a join because that will make
First of all - I don't have a problem with bad-indentated code and I
First of all I am an autodidact so I don't have great know how
First of all, I don't want to use any framework but I am looking
First of all, the website I run is hosted and I don't have access
First of all, I have read the similar posts and don't see how they
First of all, I'm using sIFR3, r419 (I can't upgrade since I don't have
Ok, first of all I don't want to use Boost, or any external libraries.
First of all, i don't have access to the php.ini in the webserver. In
First of all, I don't see how I could be getting any deadlock at

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.