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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:48:19+00:00 2026-06-03T13:48:19+00:00

If items are organized randomly, how does the table know where to start looking?

  • 0

If items are organized randomly, how does the table know where to start looking?

In a non-random table items are organized according to some characteristic. (i.e. name). So if the table needs to look up some arbitrary information about “John”, it can start looking in the ‘J’ bucket.

In a universal hash table though, items are arranged randomly. There’s no defining characteristic. Therefore to find some arbitrary info about “John”, wouldn’t the table have to look through every bucket?

Isn’t that a huge waste of time? It’s like looking through every cabinet in your house to find a spoon.

  • 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-03T13:48:20+00:00Added an answer on June 3, 2026 at 1:48 pm

    A hash looks more or less random, but it’s deterministic — that is, a particular input always produces the same hash value.

    Based on that, when you want to insert an item in a hash table, you start by generating the hash for that input. You then use that to index into the table, and insert your item at that spot in the table. In a typical case, you have one part that’s treated as the key, and you have some more information associated with that (e.g., you might be able to look up people by name, and with each name you have information about that person).

    Later, when you want to look up (the information associated with) a particular key (in this case, the person) you enter and hash the key to find the right spot in the hash table to look for that information.

    That does skip over a few crucial details, such as how you handle the two or more inputs happening to produce the same hash value (which is unavoidable unless you place some limits on the allowable inputs). There are various ways to handle this, such as just looking through the table sequentially to find the next free spot, re-hashing to find another spot in the table, or building something like a linked list of items that hashed to the same value.

    In any case, it should probably be added that there are use cases for which a hash table does end up a bit like you’ve surmised. Just for one example, when you want to see all the contents of a hash table (rather than just looking up one item at a time), you really do normally scan through the whole table. Even if your hash table is nearly empty, you normally have to scan from one end to the other, looking for every entry that’s actually in use. When you do that, you get items in an order that appears fairly random.

    This points to another shortcoming of hash tables — you generally need a precise match with a single original record for them to work well. For example, let’s consider some queries based on my last name. Assuming you indexed on the entire last name, it would be trivial to find “Coffin” — but at least with most normal hash functions, searching for “something starting with “Cof” would be dramatically slower, as would “find all the names between “Coffin” and “Demming”.

    As such, you’re sort of half correct — while hash tables are typically very fast for a few specific cases (primarily searching for an exact match), the general idea you’ve outlined (scanning through the entire table to find the data) is nearly the only choice available for some other purpose, so if you want to support anything but exact matches, a different data structure may be preferable.

    That’s dealing primarily the the most typical uses/types of hash tables. It’s possible to create hash functions that at least bend (if not outright break) those rules to varying degrees. In most cases these involve some compromises though. For example, given geographic information as input, you could create a hash (of sorts) by simply truncating the coordinates (or one of them, anyway) to get the same information at lower precision. This organizes the information to at least a degree, so things that are close together end up with similar hash values, making it easier to find neighboring data. This, however, will often lead to more collisions (e.g., you’ll get a lot of items hashing to the same value for the downtown of a large city).

    Looking specifically at universal hashing, this adds one extra element to the puzzle: instead of a single hash function, you have a family of hash functions from which you choose “randomly”. When universal hashing is used to implement a hash table (which isn’t always–it’s also often used for things like message authentication codes) you typically do not choose the hash function randomly every time you insert an item. Rather, you typically choose a hash, and continue to use it until you encounter some fixed number of collisions. Then you randomly choose another hash function.

    For example, in Cuckoo hashing (probably the most commonly used universal hash), you hash your key to find a location. If it’s already occupied, you “kick out” the existing item there, and re-hash it to find an alternate location for it. It gets inserted there. If that slot is already occupied, it “kicks out” the item already in that slot, and the pattern repeats.

    When you’re searching for an item, you hash it and look at that location. If that’s empty, you immediately know your item isn’t present. If that slot’s occupied, but doesn’t contain your item, you re-hash to find the alternate location. Continue this pattern for as many hash functions as you’re using (normally only two in the case of cuckoo hashing, but you could obviously use an otherwise similar algorithm with more functions).

    It is possible for this to fail–to enter an infinite loop, or (almost equivalently) to build a chain that exceeds some pre-set length. In this case, you start over, re-building the table with a different pair of hash functions.

    When using open hashing (of which universal hashing is one form) deletion tends to be non-trivial. In particular, we have to ensure that when we remove an item at one location, it wasn’t the beginning of a chain of items that collided at that location. In many cases, it’s most efficient to simply add a third state for a slot: if it’s never been occupied, it’s just empty. If it’s currently occupied, it’s in use. If an item has been deleted there, it’s deleted. This way when you’re searching for an item, if you encounter a “deleted” slot, you continue searching for your item (whereas, if you get to a slot that’s never been used, you can stop searching immediately–your item clearly was never inserted).

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

Sidebar

Related Questions

I've a large table of Items and I need to organize them by Category,
I have some items in my .emacs that I don't want to run if
I have some items called tickers which can be created and subscribed to. When
I have some items, each item has a category and a sub-category. What is
I got this tasks table that has TODO items. We are retrieving the todo
How do I organize my items in a table so that my row has
I have a list of items inside a table. I have decided to change
I'm writing a script in Python that will spit out some data organized as
I have two tables, one table is the items container, which holds all data
items: house: - bathroom: - toothbrush - soap - bedroom: - bed: - pillow

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.