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

  • Home
  • SEARCH
  • 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 7537235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:47:42+00:00 2026-05-30T06:47:42+00:00

I was recently asked ‘how would you implement a hastable’. I know the hashing

  • 0

I was recently asked ‘how would you implement a hastable’. I know the hashing algorithm is critical as the less collisions the better WRT performance, but what algorithm/data structure should be employed to deliver amortized constant time {O(1)} for insert/delete/lookups?

  • 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-30T06:47:43+00:00Added an answer on May 30, 2026 at 6:47 am

    Hash tables have two main possibilities:

    1. Open Addressing, which is a simple array [dynamic array actualy if you
      can let your table grow on the fly]. Once a conflict has met – you need to use a second hash function to find the next entree that the element will be mapped to. Note this solution has some troubles [which can be solved] when your hash table also allows deletions. [Special mark for “deleted” entrees]
    2. Chaining – in this solution, each entree in the array is a linked list – containig all elements hashed to this entree. In here – all elements mapped to a certain value are in the list.

    The important part about hash tables [in both solutions] in order to allow armotorized O(1) insert/del/look up – is allocating a bigger table and rehashing once a pre defined load factor was reached.

    EDIT: complexity analsis:

    Assume a load factor of p for some p < 1.

    1. The probability of “collision” in each access is p Thus the mean of array accesses is: Sigma(i * p^(i-1) * (1-p)) for each i in [1,n] This gives you: Sigma(i * p^(i-1) * (1-p)) = (1-p) * Sigma(i * p^(i-1)) <= (1-p) * 1/(p-1)^2 = 1-p = CONST. [have a look at the correctness of Sigma(i * p^(i-1)) < 1/(p-1)^2 in wolfram alpha]. Thus resulting on average a constant number of accesses to the array. Also: You might need to rehash all elements after the load factor was reached, resulting in O(n) accesses to the array. This results in n * O(1) ops [adding n elements] and 1 * O(n) op [rehashing], so you get: (n * O(1) + 1 * O(n)) / n = O(1) armotorized time.
    2. Very similar to (1), but the analysis is done on list accesses. Each operation requires exactly one array accesses, and a variant number of list accesses – with the same analysis as before.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently asked for and received help regarding a Java regular expression that would
I was recently asked if I could find an algorithm to compute the minimum
I recently asked for help with a regular expression; I now know I did
I recently asked a question about IIf vs. If and found out that there
I recently asked a question about what I called method calls. The answer referred
I recently asked about keyword expansion in Git and I'm willing to accept the
I recently asked a question about Oracle Encryption. Along the way to finding a
I recently asked a question about tracing Linq-to-Entities I think that one of the
I recently asked this question: Expose XML or Objects - thanks all for the
I recently asked a question about functional programming, and received (good!) answers that prompted

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.