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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:10:59+00:00 2026-06-12T20:10:59+00:00

I have a master list integer array which has around 500 numbers. And, i

  • 0

I have a master list integer array which has around 500 numbers. And, i have a set of 100 randomized number which has picked from the master list to find the missing numbers. Now, I need to go through this randomized number list against the master list. What would be the best approach in C programming to go through it without hanging the program. If i go through in simple ‘for’ loop for 500 elements, it will hang as it needs to go through the entire list. Could someone direct me on this?

Thanks.

  • 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-12T20:11:01+00:00Added an answer on June 12, 2026 at 8:11 pm

    First, you should profile it. It’s only 500*100=50,000 operations at the max we’re talking about. An average modern computer is capable of finishing it off in under one-tenth of a second, unless you code it very inefficiently.

    Assuming that you would like to optimize it anyway, you should sort the master array, and run a binary search on it for each element of the randomized array. This would reduce the number of operations from 50,000 to at most 900, because a binary search of 500 numbers requires at most 9 comparisons.

    Here is an implementation that uses built-in sorting and binary search functions (qsort and bsearch) of the standard C library:

    int less_int(const void* left, const void* right) {
        return *((const int*)left) - *((const int*)right);
    }
    
    int main(void) {
        size_t num_elements = 500;
        int* a = malloc(num_elements*sizeof(int));
        for(size_t i=0 ; i<num_elements ; i++) {
            a[i] = rand() % num_elements;
        }
        qsort(a, num_elements, sizeof(int), less_int);
        size_t num_rand = 100;
        int* r = malloc(num_rand*sizeof(int));
        for(size_t i=0 ; i < num_rand ; i++) {
            r[i] = rand() % num_rand;
        }
    
        for (size_t i = 0 ; i != num_rand ; i++) {
            int *p = (int*) bsearch (&r[i], a, num_elements, sizeof(int), less_int);
            if (p) {
                printf ("%d is in the array.\n", *p);
            } else {
                printf ("%d is not in the array.\n", r[i]);
            }
        }
    
        free(a);
        free(r);
        return 0;
    }
    

    Here is a link to this running program on ideone.

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

Sidebar

Related Questions

I have a list of IDs: List<Integer> updatedIds . I have a master list
I have a master product list that has a logical object structure: var myProducts
I have a Lookup that has a master list of priority levels and groups.
I have the following code below for list into master page <div id=header> <ul>
I have one master page which applies to all pages in this website. On
I've got a situation where I want to have a master list at the
I have a Master List in the DataGrid that displays all the Monitors -
This is mainly a performance questions. I have a master list of all users
Say I have 2 sheets in my workbook. One is a master list that
I have a list of numbers like so (randomly generated, numbers sorted within each

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.