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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:28:47+00:00 2026-05-26T03:28:47+00:00

Stage 1: Given two arrays, say A[] and B[], how could you find out

  • 0
  • Stage 1: Given two arrays, say A[] and B[], how could you find out if elements of B is in A?

  • Stage 2: What about the size of A[] is 10000000000000… and B[] is much smaller than this?

  • Stage 3: What about the size of B[] is also 10000000000…..?

My answer is as follows:

  • Stage 1:

    1. double for loop – O(N^2);
    2. sort A[], then binary search – O(NlgN)
  • Stage 2:
    using bit set, since the integer is 32bits….

  • Stage 3: ..

Do you have any good ideas?

  • 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-26T03:28:47+00:00Added an answer on May 26, 2026 at 3:28 am

    hash all elements in A [iterate the array and insert the elements into a hash-set], then iterate B, and check for each element if it is in B or not. you can get average run time of O(|A|+|B|).

    You cannot get sub-linear complexity, so this solution is optimal for average case analyzis, however, since hashing is not O(1) worst case, you might get bad worst-case performance.

    EDIT:

    If you don’t have enough space to store a hash set of elements in B, you might want to concider a probabilistic solution using bloom filters. The problem: there might be some false positives [but never false negative]. Accuracy of being correct increases as you allocate more space for the bloom filter.

    The other solution is as you said, sort, which will be O(nlogn) time, and then use binary search for all elements in B on the sorted array.

    For 3rd stage, you get same complexity: O(nlogn) with the same solution, it will take approximately double time then stage 2, but still O(nlogn)

    EDIT2:

    Note that instead of using a regular hash, sometimes you can use a trie [depands on your elements type], for example: for ints, store the number as it was a string, each digit will be like a character. with this solution, you get O(|B|*num_digits+|A|*num_digits) solution, where num_digits is the number of digits in your numbers [if they are ints]. Assuming num_digits is bounded with a finite size, you get O(|A|+|B|) worst case.

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

Sidebar

Related Questions

I have 10 tables in my database(MySQL). two of them is given below tbl_state
The following program loads two images with PyGame, converts them to Numpy arrays, and
Not homework. Given two strings S and T of same length. Given a set
Well, there are at least two low-level ways of determining whether a given number
Given a set of two or more logical conditions, is it possible to algorithmically
Given two data frames: df1 = data.frame(CustomerId = c(1:6), Product = c(rep(Toaster, 3), rep(Radio,
Given two points in a 2D plane, and a circle of radius r that
Given two threads A and B, is there any portable way that A can
I have two objects that are searching for one-another on the stage. They move
I am writing a small HTML+JavaScript (so to call) application. User is given two

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.