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

  • Home
  • SEARCH
  • 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 6734671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:55:00+00:00 2026-05-26T10:55:00+00:00

I have an array of char pointers of length 175,000. Each pointer points to

  • 0

I have an array of char pointers of length 175,000. Each pointer points to a c-string array of length 100, each character is either 1 or 0. I need to compare the difference between the strings.

char* arr[175000];

So far, I have two for loops where I compare every string with every other string. The comparison functions basically take two c-strings and returns an integer which is the number of differences of the arrays.

This is taking really long on my 4-core machine. Last time I left it to run for 45min and it never finished executing. Please advise of a faster solution or some optimizations.


Example:

000010
000001

have a difference of 2 since the last two bits do not match.

After i calculate the difference i store the value in another array

                int holder;

                for(int x = 0;x < UsedTableSpace; x++){
                    int min = 10000000;

                    for(int y = 0; y < UsedTableSpace; y++){

                        if(x != y){
                            //compr calculates difference between two c-string arrays
                            int tempDiff =compr(similarity[x]->matrix, similarity[y]->matrix);

                            if(tempDiff < min){
                                min = tempDiff;
                                holder = y;
                            }
                        }       
                    }
                    similarity[holder]->inbound++;

                }
  • 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-26T10:55:01+00:00Added an answer on May 26, 2026 at 10:55 am

    One simple optimization is to compare the strings only once. If the difference between A and B is 12, the difference between B and A is also 12. Your running time is going to drop almost half.

    In code:

    int compr(const char* a, const char* b) {
      int d = 0, i;
      for (i=0; i < 100; ++i)
        if (a[i] != b[i]) ++d;
      return d;
    }
    
    void main_function(...) {
    
        for(int x = 0;x < UsedTableSpace; x++){
            int min = 10000000;
    
            for(int y = x + 1; y < UsedTableSpace; y++){
    
                //compr calculates difference between two c-string arrays
                int tempDiff = compr(similarity[x]->matrix, similarity[y]->matrix);
    
                if(tempDiff < min){
                    min = tempDiff;
                    holder = y;
                }
            }
            similarity[holder]->inbound++;
        }
    }
    

    Notice the second-th for loop, I’ve changed the start index.

    Some other optimizations is running the run method on separate threads to take advantage of your 4 cores.

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

Sidebar

Related Questions

if I have an array of pointers like char **lines, how can i determine
My approach: An array of fixed-length (lets say 20) each element is pointer to
I got the following problem: I have an array of char pointers char *opts[]
I have a binary search function I am passing a pointer character array, the
I currently have the dynamic array: char *myData[500][10]; //myData is the name of an
I have a char array in a C application that I have to split
I have a char array buffer that I am using to store characters that
i have an char array b[20] which i want to write into a file
Have an array of chars like char members[255]. How can I empty it completely
I have a big lump of binary data in a char[] array which I

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.