Skip to main content

Questions tagged [hash-tables]

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

Filter by
Sorted by
Tagged with
1 vote
1 answer
68 views

How bad re-hashing can cost?

Lets assume that the load factor of a hash table of size $n$ became inappropriate. The process of re-hashing involves choosing a new hash function. A good choice of a new function will make the cost ...
Daniel's user avatar
  • 191
1 vote
1 answer
55 views

Do edge lists have O(E) storage if default values are used for absent keys?

Ordinarily, edge list representations of graphs take $O(V+E)$ space, where $V$ is the number of vertices and $E$ is the number of edges. For example, consider a graph with 5 nodes and a single edge ...
Ellen Spertus's user avatar
0 votes
1 answer
134 views

Time complexity of delete and insert operations in a hash table

Let's take a hash table where the collision problem is solved using a linked list. As we know, in the worst case, due to collisions, searching for an element in the hash table takes O(n). But why does ...
Slaycapь's user avatar
0 votes
1 answer
14 views

Hash function for use with hash table, given power distributed integers

Suppose I have integers that follows a power distribution: $P(n) \propto 1/(n + 1)^\alpha, n \geq 0$ What hash function is a good choice to avoid collisions. The usecase is keys in an ...
user877329's user avatar
1 vote
1 answer
72 views

Efficient data structure for fast Insertions, lookups, and union operations on sets

I need data structure that is able to perform the following operations efficiently: Insert a new element into a set. Lookup element in set. Compute the union of two sets. Union operation should ...
Euler-Maskerony's user avatar
0 votes
2 answers
42 views

Search times for hash tables using open addressing for collision resolution

With regards to hash tables using open addressing as collision resolution mechanism, Introduction to Algorithms, Chapter 11, page 294 (4th edition, 2022 printing) states the following Deletion from ...
jam's user avatar
  • 15
3 votes
3 answers
113 views

How to select hash functions for cuckoo hashing?

In cuckoo hashing, an insertion failure occurs when there is an infinite loop of displacements. This is detected by a “max iterations” count on the insert function. When the insert fails, the table is ...
haz's user avatar
  • 131
0 votes
0 answers
46 views

What is the probability of no collision in two hash tables, where a key is hashed to both tables and chained to the shortest chain from the tables?

can someone help me with this problem? Consider a hashing scheme that uses r hash tables T1, . . . , Tr of size m, where collisions in each table are resolved by chaining. When a key k arrives, it is ...
Barud_77's user avatar
0 votes
0 answers
31 views

Create a class or structure like union of ranges

How to create a structure which acts as union of ranges. In that structure new ranges can be inserted beforehand and then some queries are asked to find out if the given point is covered by any of the ...
user166204's user avatar
1 vote
1 answer
59 views

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 ...
Dair's user avatar
  • 244
0 votes
1 answer
124 views

Find a substring length $k$ with maximum occurrences

Given a string length $S$, find a substring length $k$ that has the most occurrences in the given string. We want $O(S)$ time complexity in an average case. I think the solution lies in sophisticated ...
popcorn's user avatar
  • 183
0 votes
0 answers
73 views

Effect of Insertion order on number of collisions in Double Hashing

How is the number of collisions affected by the order of insertion of elements in a hash table using double hashing? I've tried uing different hash function for double hashing with different set of ...
user avatar
0 votes
1 answer
38 views

Collisions in hash table - Is this table wrong?

I have the following hash table with hashcodes being quadratic numbers. Why do 0, 16, and 64 have different number of collisions when they map to the same number (line %16). Also how is it possible ...
Rubus's user avatar
  • 123
1 vote
0 answers
103 views

How to properly save Zobrist Keys?

In a project of mine, I want to represent states as efficiently as possible. Initially, I went ahead with a BitBoard representation and some clever tricks to speed up the evaluation of the game tree. ...
J. M. Arnold's user avatar
1 vote
2 answers
59 views

Chord Ring with limited table size of 3

In the normal case of a chord ring the big O notation of the look up is O(logn) because of long haul pointers of the Finger Table (or Routing Table). In this question what if the Finger Table has a ...
DarkArtistry's user avatar
0 votes
1 answer
200 views

Simple Uniform hashing with chances of no collision

I know that if I have $n$ different values in an array of size $m$ (where $m>n$) under simple uniform hashing, the average probability of the total number of collisions is: $$\sum_{i=1}^{n-1}\frac{...
Mike's user avatar
  • 33
1 vote
2 answers
134 views

Order-preserving hashtable for integer tuples

There are integer tuples which index cells of a sparse multi-dimensional array (points inside n-parallelepiped), $n \le 32$. The array itself is a BST with keys formed as $key = (...((a_0 * S_1 + a_1) ...
Andrey Godyaev's user avatar
0 votes
0 answers
134 views

Slot implementation of LRU cache

Usually LRU cache is implemented with double linked list to fast remove oldest visited, push to front, and move from any place to front; also uses map to fast find element by key. In 64bit systems ...
Saku's user avatar
  • 141
1 vote
2 answers
436 views

How to deal with a very big hash table?

I'm building an implementation of the dynamo paper, yottastore. Given a key, I need to find which NVMe block stores the data. To do that I hash the key to find the shard where I have an in memory ...
Mascarpone's user avatar
1 vote
1 answer
65 views

Universal family of hash functions — dependent on table size?

Given the following family of hash functions: $$ \mathbb{H} = \{h_c(x) = (12x + c) \bmod m \mid c \in \mathbb{N} \}, $$ where $m$ is the key size. Prove that $\mathbb{H}$ is not a universal ...
blox2212's user avatar
0 votes
1 answer
150 views

Is there a hash-map implementation optimized to favor key lookups based on frequency (if key is referenced the most then it is searched first)?

I have started to play around with HTTP3 which relies on QUIC for transport. I have noticed that I very often have a finite number of Web Transport sessions stream data continuously along side burst-y ...
Liam Kelly's user avatar
1 vote
3 answers
945 views

What is a good load factor for seperate chaining (closed addressing)?

For open addressing, I know that once you have around 70% table being filled you should resize because more than that you get collision. But for closed addressing, I read that load factor should not ...
Bam's user avatar
  • 11
0 votes
1 answer
295 views

Consistent Hashing Algorithm Without Distribution / Load Balancing

I need some help finding or creating a consistent hashing algorithm with the following properties: Given N buckets, only distributes keys to bucket N. When number of buckets are increased from N to N+...
scroobius's user avatar
1 vote
2 answers
2k views

Averege time complexity of open addressing

I get that it depends from the number of probes, so by how many times the hash code has to be recalculeted, and that in the best case there will only be one computation of the hash code and the ...
Spyromancer's user avatar
11 votes
2 answers
3k views

Why is the Java HashMap load factor 0.75?

I can't understand why the Java HashMap load factor is 0.75. If I understand well, the formula for the load factor is n/m, where n is the number of key and m is the number of position in the hash ...
Bender's user avatar
  • 367
0 votes
1 answer
46 views

Confused about the appropriate slot in linear probing

The following paragraph is from the book CLRS: Given an ordinary hash function $h' : U \rightarrow \{0, 1, ..., m - 1\}$, which we refer to as an auxiliary hash function, the method of linear probing ...
Emad's user avatar
  • 421
1 vote
2 answers
175 views

Iterable hash table

I'm currently working on implementing all the major data structures from C++ to better understand them and I arrived at the unordered_map, which should be a hash table implementation (it's actually ...
Petok Lorand's user avatar
1 vote
3 answers
310 views

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<V> ...
nir shahar's user avatar
  • 11.7k
0 votes
0 answers
24 views

Unusual approach to tabulation algorithm

Consider simple tabulation algorithm firstly for Fibonacci numbers. We will use the dictionary as a cache (and Python as example PL): ...
lesobrod's user avatar
  • 111
2 votes
1 answer
185 views

Analysis of a calculation of expected number of collisions in hashing

For a formal problem statement, I quote from the text Introduction to Algorithms by Cormen et. al Suppose we use a hash function $h$ to hash $n$ distinct keys into an array $T$ of length $m$. ...
Abhishek Ghosh's user avatar
0 votes
0 answers
29 views

worst case time for adding values to a hash table

A certain hash table uses external chaining, and is resized each time its load factor exceeds 3. Also, if an addition does not cause the load factor to exceed 3, but does cause some bucket to exceed 6 ...
daniel's user avatar
  • 131
0 votes
0 answers
105 views

Does DHT (Distributed Hash Table) allow to list ALL (not only nearest) nodes?

As I know any local DHT keeps only some of nodes - if the network is small/very small then all nodes, otherwise only some of them (nearest?). So, when I checked different Golang implementations of DHT ...
RandomB's user avatar
  • 101
15 votes
4 answers
4k views

Why are graphs represented as adjacency lists instead of adjacency sets?

In answering this question, I was looking for references (textbooks, papers, or implementations) which represent a graph using a set (e.g. hashtable) for the adjacent vertices, rather than a list. ...
Caleb Stanford's user avatar
0 votes
3 answers
184 views

How do i delete one single unequal element from an array of equal elements without using hashing?

The rules of the question state that: Only one element is different. Rest are all same. Array A size is 8. I need to find the different element and remove it (Hashing cannot be used). I have not ...
Swarnava Chandra Bose's user avatar
1 vote
1 answer
296 views

A hash function for a 2D hash table with a scattering property?

I have an $n\times n$ matrix, and want to find a bijective function $h:[n^2] \to [n]\times [n]$ that can act as a hash function to map the numbers 1 through $n^2$ to row/column indices in my matrix. ...
RJL's user avatar
  • 11
0 votes
1 answer
675 views

Build a priority queue using dictionary

QUESTION: Can we Implementing priority queue with hash table please? As I understand, dictionary/hash table does not have sorting mechanism inside. It adds pairs of $<key,value>$ to hash table. ...
Avv's user avatar
  • 515
0 votes
2 answers
346 views

How does a hash table not require all the keys to be looked through to find a value, i.e. O(N)?

Before starting, I want to say that I understand time complexity, and I understand how a hash table is considered O(1) vs an array having a time comp. of O(N) in terms of what you learn. What I don't ...
Jake Jackson's user avatar
0 votes
1 answer
568 views

hash-tables - Expected-time for an unsuccessful search

The following question is from MIT-OCW 6.006, Spring-2008, Problem-Set 2, Q-3.c. Suppose you have a hash table where the load-factor $\alpha$ is related to the number $n$ of elements in the table by ...
x.projekt's user avatar
  • 101
1 vote
1 answer
103 views

How does the Go language implements maps?

To what extent is the MAP data type implementation language dependant??? If we know that C++ implements maps as Red Black Trees, unordered maps as hash tables, How C++ and alike maps are actually ...
ShAr's user avatar
  • 148
0 votes
1 answer
38 views

The interpretation of expected time bound for searches in a hash table

As CLRS book,page 260 stated, Thus, the total time required for a successful search is $\Theta{\left(2+\alpha/2-\alpha/2n\right)}=\Theta{(1+\alpha)}$ I wouldn't have any problem if the author says ...
absuu's user avatar
  • 103
1 vote
1 answer
548 views

If $(h_2(k),m) = 1$ then $h_1(k)+ih_2(k) \bmod{m}$ is a permutation of $0,\ldots,m-1$

The following question appears in Introduction to Algorithms (CLRS): Suppose that we use double hashing to resolve collisions; that is, we use the hash function $ h(k, i) = (h_1(k) + ih_2(k)) \bmod{m}...
Avv's user avatar
  • 515
0 votes
0 answers
62 views

Confused about a corollary in MIT.Introduction.to.Algorithms(CLRS), seek help

Desc' I was reading CLRS Book's chapter 11 Hash Tables, and encountering some problems. There is an corollary in CLRS book, in Page 275 (quoted on the bottom of post), which discussed the expected ...
absuu's user avatar
  • 103
1 vote
1 answer
613 views

Detecting and correcting collisions in (Zobrist) hashing to avoid errors in transposition table

Context Say I have a transposition table that uses keys produced by (e.g. Zobrist) hashing game positions. The table has a finite recycled memory (key % p is the <...
Vepir's user avatar
  • 117
1 vote
1 answer
79 views

Number of unique values in array in $\theta(n)$ average expected time

My idea is to initialize a hash table (with chaining) with $n$ cells, having load factor $\alpha = 1$ hence having $\theta(1)$ expected number of values in each cell in the hash table, then go cell by ...
user183748292's user avatar
0 votes
0 answers
55 views

The Most efficient algorithm for a program that returns true if the two strings only differ by one character

We have a list of strings with the same length. Each string only contains a, b and c.(For instance : aabcc) The program gets a string and returns true if the two strings(input and the list of strings) ...
emma funkhouser's user avatar
2 votes
2 answers
84 views

What kind of data structure should be used for working with dynamic sets where elements follow "normal distribution" and why?

I am wondering if Hash tables would be a good choice as it mentions dynamic sets to store data which follows normal distribution. I have doubt in this because normal distribution has bell shaped curve ...
Yukti Kumari's user avatar
0 votes
2 answers
134 views

Find distinict elements in an array in $O(n)$ time

Given this pseudo-code that finds the number of distinct elements in the given array: ...
Omri Braha's user avatar
2 votes
0 answers
123 views

Finding the longest power subsequence

A power sequence is a sequence containing consecutive powers of a number starting from power one. for example $3^1, 3^2, 3^3$ is a power sequence. The question is to find the length of the longest ...
user136515's user avatar
2 votes
1 answer
2k views

Time complexity of checking whether a string exists in a HashSet

From what I know hash sets generally have complexity of $O(1)$ (unless the hash function is bad, but let's just ignore that for this question). However, sets need to either read the full data so as to ...
asharpharp's user avatar
2 votes
1 answer
102 views

How do we pick and switch hash functions from a universal family?

When we have a universal family of hash functions, it gives us a few useful mathematical guarantees. But, if we pick a specific function from the family and use it all the time it's effectively like ...
snatchysquid's user avatar

1
2 3 4 5 6