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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:49:45+00:00 2026-05-22T00:49:45+00:00

What is the fastest method of finding duplicates across multiple (large) linked lists. I

  • 0

What is the fastest method of finding duplicates across multiple (large) linked lists.
I will attempt to illustrate the problem with arrays instead just to make it a bit more readable. (I used numbers from 0-9 for simplicity instead of pointers).

list1[] = {1,2,3,4,5,6,7,8,9,0};
list2[] = {0,2,3,4,5,6,7,8,9,1};
list3[] = {4,5,6,7,8,9,0,1,2,3};
list4[] = {8,2,5};
list5[] = {1,1,2,2,3,3,4,4,5,5};

If I now ask: ‘does the number 8 exist in list1-5?’ I could sort the lists, remove duplicates, repeat this for all lists and merge them into a “superlist” and see if the number of (new) duplicates equal the number of lists that I search through. Assuming that I got the correct number of duplicates I can assume that what I searched for (8) exists in all of the lists.
If I instead searched for 1 I will only get four duplicates—ergo not found in all of the lists.

Is there a faster/smarter/better way to achieve the above without sorting and/or changing the lists in any way?

P.S.: This question is asked mostly out of pure curiosity and nothing else! 🙂

  • 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-22T00:49:46+00:00Added an answer on May 22, 2026 at 12:49 am

    Define an array hash and set all the location values to 0

    define hash[MAX_SYMBOLS] = {0};
    define new_list[LENGTH]
    defile list[LENGTH] and populate
    

    Now for each element in your list, use this number as an index in hash and increment that location of hash . Each presence of that number would increment the value at that hash location once. So a duplicate value i would have hash[i] > 1

    for i=0 to (n - 1)
      do
        increment hash[list[i]]
    endfor
    

    If you want to remove the duplicates and create a new list then scan the hash array and for each presence of i ie. if hash[i] > 0 load them into a new list in the order in which they appeared in the original list.

    define j = 0
    for i=0 to (n - 1)
      do
        if hash[list[i]] is not 0
          then
            new_list[j] := i
            increment j
        endif
    endfor
    

    Note that when using with negative numbers you will not be able to use the values directly to index. To use negative numbers, first we can find the largest magnitude of the negative numbers and use that magnitude to add to all the numbers when we use them to index the hash array.

    find the highest magnitude of negative value into min_neg
    
    for i=0 to (n - 1)
      do
        increment hash[list[i + min_neg]]
    endfor
    

    Or in implementation you can allocate contiguous memory and then define a pointer at the middle of the allocated memory block, so that you could move in both front and back directions so that you can use negative index with it. You need to make sure that you have enough memory to use in front and back of the pointer.

    int *hash = malloc (sizeof (int) * SYMBOLS)
    int *hash_ptr = hash + (int)(SYMBOLS/2)
    

    now you can do hash_ptr[-6] or some hash_ptr[i] with -SYMBOLS/2 < i < SUMBOLS/2 + 1

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

Sidebar

Related Questions

Which is the fastest method for over all performance on a large scale with
What is the fastest method of parsing an XML file in C#? I'm using
Given a string s , what is the fastest method to generate a set
What is the fastest way to execute a method on an ASP.NET website? The
Using SQL Server, which is the fastest or best practice method to use for
What is the single fastest method for table row hover css change? I've tried
Which is the fastest method for convert an string's array [1,2,3] in a int's
What is the fastest method to fill a database table with 10 Million rows?
What is the fastest built-in comparison-method for string-types in C#? I don't mind about
Is the Visitor Pattern the fastest way to accomplish method parameter type identification (effectively

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.