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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:44:50+00:00 2026-06-06T00:44:50+00:00

I have the following question, and it screams at me for a solution with

  • 0

I have the following question, and it screams at me for a solution with hashing:

Problem :

Given a huge list of numbers, x1........xn where xi <= T, we’d like to know
whether or not exists two indices i,j, where x_i == x_j.
Find an algorithm in O(n) run time, and also with expectancy of O(n), for the problem.

My solution at the moment : We use hashing, where we’ll have a mapping function h(x) using chaining.

First – we build a new array, let’s call it A, where each cell is a linked list – this would be the destination array.

Now – we run on all the n numbers and map each element in x1........xn, to its rightful place, using the hash function. This would take O(n) run time.

After that we’ll run on A, and look for collisions. If we’ll find a cell where length(A[k]) > 1
then we return the xi and xj that were mapped to the value that’s stored in A[k] – total run time here would be O(n) for the worst case , if the mapped value of two numbers (if they indeed exist) in the last cell of A.

  • 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-06T00:44:52+00:00Added an answer on June 6, 2026 at 12:44 am

    The same approach can be ~twice faster (on average), still O(n) on average – but with better constants.

    No need to map all the elements into the hash and then go over it – a faster solution could be:

    for each element e:
      if e is in the table:
          return e
      else:
        insert e into the table
    

    Also note that if T < n, there must be a dupe within the first T+1 elements, from pigeonhole principle.

    Also for small T, you can use a simple array of size T, no hash is needed (hash(x) = x). Initializing T can be done in O(1) to contain zeros as initial values.

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

Sidebar

Related Questions

I have the following question: If asked whether to use a shift vs a
I have the following question: I was given the task - to build an
I have following question. I'd like to place a file named data.xml into sdcard/appname
I have the following question regarding Sitecore item creation: Given the following content tree:
I have the following question: I have data frame which looks like this. I
I have the following question: First of all, I know (and have some academic
I have started to learn Maven and have the following question: I would like
I have following question on adobe omniture How we can register an iPhone app
I am new to Spring Batch. I have following question. I am using Spring
I have the following question. I have a set of Fortran90 source files, most

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.