Questions tagged [hash-tables]

A finite map data structure that addresses stored values using a function that maps many values to few addresses.

A hash table is a finite map (i.e. a dictionary), mapping keys to associated values, which relies on a hash function to map keys to a small integer that is typically used as an index in an array.

Hash tables are more efficient than other finite map data structures for many kinds of data.

Further reading

264 questions
14
votes
3 answers

What does "non-pathological data" mean?

I took an algorithms class on Coursera. The professor in the video about hash tables said that What's true is that for non-pathological data, you will get constant time operations in a properly implemented hash table. What does "non-pathological…
11
votes
2 answers

Why should one not use a 2^p size hash table when using the division method as a hash function?

I don't understand what is meant by: "m should not be a power of 2, since if m = 2^p, then h(k) is just the p lowest-order bits of k." (pg. 231 of CLRS) Terms defined: m: size of hash table h(k): hash function = k mod m k: key I don't understand…
zallarak
  • 213
  • 2
  • 5
3
votes
0 answers

Storing variable length Keys in hash table itself

I wrote a custom hash table for a project I'm working on. The core functionality was pretty simple rolling table: In each table there is a memory section for HashItemReference(integer SecondHash, integer ItemN) which is the actual table part and a…
user40153
  • 31
  • 1
2
votes
1 answer

When retrieving values from a hash table with linear probing, how do we know if the wanted value had not been shifted?

So, after a collision, a piece of information gets stored in the next bucket. When retrieving the value later with a key, how do we know it has not been shifted due to a collision and that we are in fact receiving the wrong value?
waterlemon
  • 135
  • 4
2
votes
3 answers

How does hash table search scales with number of keys?

Say, I have one of the standard implementations of a hash table: chaining or open addressing, and my hash key is a pair of strings. Instead of using the hash table with the pair as a key, I can use the first key to get to a "sub" - hash table, and…
LazyCat
  • 141
  • 2
2
votes
1 answer

Quadratic probing maximum load factor with $c_1 = c_2 = 0.5$ to guarantee successful insertion

For quadratic hashing, i.e an open-addressed table with the hash function of the form - $h(x, i)= (h'(x) + c_1i + c_2i^2) \mod m$ Setting $c_1 = c_2 = 1/2$, and $m$ to some power of 2, leads to a hash function $h(x, i) = (h'(x) + 1 + 2 + ... +i)…
slnsoumik
  • 317
  • 3
  • 9
2
votes
0 answers

What is the easiest solution to check if a rational number is in the Cantor set?

To check that a rational number is in the Cantor set, I have written an algorithm to obtain its base-3 representation. To verify if the representation is periodic, I used a hash table in order to save memory. Is there any easier solution to check…
aco
  • 21
  • 1
2
votes
1 answer

HashTable open-addressing is used for main array or buckets

I am trying to understand the HashTable open-addressing technique. I see there are three approaches: linear, quadratic and double hashing. I'm wondering are these techniques used: to find an index of the main array and no bucketing is involved or…
Node.JS
  • 151
  • 1
  • 12
1
vote
1 answer

Hash table: When is it suitable to use modulo power of 2?

I am implementing a hash table that may need to grow and shrink as the number of stored keys varies. I have a hashcode function that uniformly hashes keys to positive 32-bit integers. The table itself will use a smaller array of approximate size M.…
TheSaviour
  • 11
  • 3
1
vote
2 answers

When using a hash and a collision occurs and linear probing is used how is that item found again

How is the search for the item supposed to find the specific item if the data is all clumped together and all the search is given is the output of the hash function. I don't understand how it knows which of the pieces of data is the one that…
james king
  • 13
  • 2
1
vote
1 answer

Trouble Understanding Yao's "Basic Model" for Hashing

I am trying to understand the probing model proposed by Yao in the paper "Should Tables Be Sorted?". Yao suggests a "Basic Model" (in the section appropriately titled "Basic Model") but there seems to be some disconnect in the way I remember hash…
Dair
  • 232
  • 1
  • 9
1
vote
2 answers

Hash maps vs extending structs / classes

A hash map that maps keys of type $K$ into values of type $V$, is essentially equivalent to "extending" this type $K$ to also contain an Option field. Implementing this in practice (apart from the bad habits of adding more fields that are…
nir shahar
  • 11,538
  • 3
  • 14
  • 35
1
vote
0 answers

Can hash tables handle variable sized entries?

Let's say I have a hash table of 10 buckets where each bucket is of a number of bits. However each bucket doesn't have to have the same number of bits. Is it possible to achieve this? Or does it require padding every entry? For example: Index 0 has…
Terence Chow
  • 121
  • 1
  • 2
0
votes
0 answers

how many hash table sequences will produce a given table

given the following hash table with linear probing when the hash function is: $$k mod 10$$ how many different sequences will produce the given table? (starting from an empty table)
chendoy
  • 307
  • 1
  • 3
  • 7
0
votes
0 answers

is hash table a magic?

I have no cs background (algorithm and data structure), but need to find a data analysis related job since my major is math / statistics. However, (I am trying to avoid software engineering related jobs) no matter which position I applied, from…
breezeintopl
  • 273
  • 1
  • 3
  • 7
1
2