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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:27:14+00:00 2026-05-27T15:27:14+00:00

I have been trying to come up with a way to write an efficient

  • 0

I have been trying to come up with a way to write an efficient algorithm to perform an unsorted intersection on two vectors/arrays, but with no luck. I am working with one large non-unique array (generally 500,000 to 1,000,000 values), and one relatively smaller (maybe 5000 values max) unique array.

I have seen a variety of methods suggested on here involving techniques such as unordered_sets, but to my understanding, this doesn’t work if one of the arrays is non-unique. Secondly, instead of having an output vector that contains the numbers common to both arrays, I’d like to have the output vector contain the indices of those common values with respect to the larger array. So, if the larger array has 5 locations that equal one of the values in the smaller array, I need each of those 5 indices. Perhaps something similar to python’s in1d function.

Anyone have any ideas? 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-05-27T15:27:15+00:00Added an answer on May 27, 2026 at 3:27 pm

    Put the unique side into an unordered_set, and go through the non-unique side one by one. If you find an item at non_unique_side[i] in the unordered_set(unique_side), add i to the result.

    Assuming that unordered_set is implemented as a hash set with O(1) amortized insertion and lookup times, this algorithm gets you O(L+S) time complexity, where L is the number of items in the larger list, and S is the number of items in the smaller set. This is as fast as you can do an intersection.

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

Sidebar

Related Questions

I have been trying some programs in the C Language and come across to
I have been trying to find a really fast way to parse yyyy-mm-dd [hh:mm:ss]
I have been trying to work my way through Project Euler, and have noticed
I have been trying for the last week to find a way to make
I've been trying to come up with an ideal way to query WiFi information
I have been trying to come up with a better localization approach than LocBaml
So I have been trying to figure out the best way to go about
I've been trying to come up with a way to declare array constants in
I've been trying to come up with a decent solution to this, but I
I have been trying to fix this issue for weeks but I'm at the

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.