212 views
1 1 vote

You are designing a Hash Table using Chaining (also known as "Open Hashing") to handle collisions. In this system, multiple keys that hash to the same index are stored in a Singly Linked List at that specific bucket.

Suppose your hash function is $h(k)=k(\bmod 7)$. You insert the following keys in this order$: 14, 21, 28,$ and $35.$ After these insertions, what is the length of the longest linked list in the table?

1 Answer

0 0 votes

The hash function provided is $h(k)=k(\bmod 7)$. This means we divide the key by $7$ and look at the remainder to determine which "bucket" the key belongs to.

  • Key $\mathbf{14:} ~14 \div 7=2$ with remainder $\mathbf{0}$. $($Bucket $0)$
     
  • Key $\mathbf{21:} ~ 21 \div 7=3$ with remainder $\mathbf{0}$. $($Bucket $0)$
     
  • Key $\mathbf{28:} ~ 28 \div 7=4$ with remainder $\mathbf{0}$. $($Bucket $0)$
     
  • Key $\mathbf{35:} ~ 35 \div 7=5$ with remainder $\mathbf{0}$. $($Bucket $0)$

Because all four keys produce a remainder of $0$, they are all stored in the same bucket. In a chaining system, they form a linked list at index $0$ with a length of $\mathbf{4}$.

Answer:
Position:
Show:

Related questions

4 4 votes
1 1 answer
211
211 views
GO Classes asked Jan 8
211 views
Consider the following two functions $f(n)$ and $g(n)$ :$f(n)=\sum_{i=1}^n \log (i)$ $g(n)$ is defined by the recurrence relation: $T(n)=8 T(n / 2)+n^2$, where $g(n)=T(n)...
0 0 votes
1 1 answer
198
198 views
GO Classes asked Jan 8
198 views
In a Binary Search Tree, for any given node, the value of the left child must be less than the parent, and the value of the right child must be greater than the parent.If...
2 2 votes
1 1 answer
193
193 views
GO Classes asked Jan 8
193 views
In Python, the $\verb|.get()|$ method is often used to avoid $\verb|KeyError|$ exceptions. Examine the code below:counts = {"apples": 10, "bananas": 5} result = counts.ge...
1 1 vote
1 1 answer
213
213 views
GO Classes asked Jan 8
213 views
Suppose you have a list of strings representing transaction amounts, some of which contain non-numeric characters $($e.g., "$\$$"$)$. You need to clean the data, convert ...