147 views
0 0 votes

Consider a custom Python-style hash table implementation using Linear Probing to resolve collisions. The hash table has a size of $m=11$ $($indices $0$ to $10 )$ and uses the hash function $h(k)=(3 k+5) \bmod 11$.

The following keys are inserted into an initially empty table in the given order: $\mathbf{1 2}, \mathbf{2 3}, \mathbf{1}, \mathbf{3 4}$

After these four insertions, what is the index of the key $\mathbf{34}$?

1 Answer

0 0 votes
Solve hash table problem

 

Step 1: Insert key 12

 

The hash function is $h(k) = (3k + 5) \pmod{11}$. For key 12, the initial index is $h(12) = (3 \times 12 + 5) \pmod{11} = (36 + 5) \pmod{11} = 41 \pmod{11}$. Since $41 = 3 \times 11 + 8$, $41 \pmod{11} = 8$. Index 8 is empty, so 12 is placed at index 8.

 

Step 2: Insert key 23

 

For key 23, the initial index is $h(23) = (3 \times 23 + 5) \pmod{11} = (69 + 5) \pmod{11} = 74 \pmod{11}$. Since $74 = 6 \times 11 + 8$, $74 \pmod{11} = 8$. Index 8 is occupied by 12. Using linear probing, we check the next index: $(8 + 1) \pmod{11} = 9$. Index 9 is empty, so 23 is placed at index 9.

 

Step 3: Insert key 1

 

For key 1, the initial index is $h(1) = (3 \times 1 + 5) \pmod{11} = (3 + 5) \pmod{11} = 8 \pmod{11} = 8$. Index 8 is occupied by 12. Using linear probing, we check the next index: $(8 + 1) \pmod{11} = 9$. Index 9 is occupied by 23. Using linear probing, we check the next index: $(9 + 1) \pmod{11} = 10$. Index 10 is empty, so 1 is placed at index 10.

 

Step 4: Insert key 34

 

For key 34, the initial index is $h(34) = (3 \times 34 + 5) \pmod{11} = (102 + 5) \pmod{11} = 107 \pmod{11}$. Since $107 = 9 \times 11 + 8$, $107 \pmod{11} = 8$. Index 8 is occupied by 12. Using linear probing, we check the next index: $(8 + 1) \pmod{11} = 9$. Index 9 is occupied by 23. Using linear probing, we check the next index: $(9 + 1) \pmod{11} = 10$. Index 10 is occupied by 1. Using linear probing, we check the next index: $(10 + 1) \pmod{11} = 0$. Index 0 is empty, so 34 is placed at index 0.

 

Answer: The key 34 is at index 0.
Answer:
Position:
Show:

Related questions

2 2 votes
1 1 answer
172
172 views
GO Classes asked Feb 3
172 views
Consider the following Python function $\verb|mystery_ds|$ that processes a list of integers:def mystery_ds(arr): stack = [] result = [0] * len(arr) for i in ...
0 0 votes
1 1 answer
157
157 views
GO Classes asked Feb 3
157 views
A binary tree $T$ is constructed such that for every node $N$, the number of nodes in its left subtree $L(N)$ and right subtree $R(N)$ satisfy the condition: $\mid \opera...
1 1 vote
1 1 answer
401
401 views
GO Classes asked Feb 3
401 views
In a binary search tree (BST) where all keys are distinct, which of the following properties are TRUE regarding tree traversals and structure?The In-order traversal of an...
0 0 votes
1 1 answer
178
178 views
GO Classes asked Feb 3
178 views
Consider an Adjacency List representation of a directed graph $G=(V, E)$ with $n$ vertices and $m$ edges, implemented using Python's $\verb|dict|$ where keys are vertex I...