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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:20:07+00:00 2026-05-20T00:20:07+00:00

in C++, how to handle hash collision in hash map? and how much time

  • 0

in C++, how to handle hash collision in hash map? and how much time will spend to search an element if a collision occurred?

And, what is a good hash function?

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

    There are dozens of different ways to handle collisions in hash maps depending on what system you’re using. Here are a few:

    1. If you use closed addressing, then you probably would have each item hash to a linked list of values, all of which have the same hash code, and would then traverse the list looking for the element in question.
    2. If you use linear probing, then following a hash collision you would start looking at adjacent buckets until you found the element you were looking for or an empty spot.
    3. If you use quadratic probing, then following a hash collision you would look at the elements 1, 3, 6, 10, 15, …, n(n+1)/2, … away from the collision point in search of an empty spot or the element in question.
    4. If you use cuckoo hashing, you would maintain two hash tables, then displace the element that you collided with into the other table, repeating this process until the collisions resolved or you had to rehash.
    5. If you use dynamic perfect hashing, you would build up a perfect hash table from all elements sharing that hash code.

    The particular implementation you pick is up to you. Go with whatever is simplest. I personally find chained hashing (closed addressing) the easiest, if that suggestion helps.

    As for what makes a good hash function, that’s really dependent on what type of data you’re storing. Hash functions for strings are often very different than hash codes for integers, for example. Depending on the security guarantees you want, you may want to pick a cryptographically secure hash like SHA-256, or just a simple heuristic like a linear combination of the individual bits. Designing a good hash function is quite tricky, and I’d advise doing a bit of digging for advice on the particular structures you’re going to be hashing before coming to a conclusion.

    Hope this helps!

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

Sidebar

Related Questions

How to handle personal stress caused by utterly incompetent and lazy co-workers?
Given a handle of type HWND is it possible to confirm that the handle
Is it possible to handle POSIX signals within the Java Virtual Machine? At least
I'm trying to handle Winsock_Connect event (Actually I need it in Excel macro) using
Does your software handle newline characters from other systems? Linux/BSD linefeed ^J 10 x0A
I have the handle of process 'A' on a Pocket PC 2003 device. I
How does one handle a DateTime with a NOT NULL ? I want to
How does C handle converting between integers and characters? Say you've declared an integer
How do most people handle updating ASP.NET applications running in a webfarm? I am
I would like to handle an OracleException thrown when my network/database connection is interrupted,

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.