• edited by
46,231 views
122 122 votes

A hash table of length $10$ uses open addressing with hash function $h(k) = k \: \mod \: 10$, and linear probing. After inserting $6$ values into an empty hash table, the table is shown as below
$$\begin{array}{|l|l|}\hline \text{0}  &  \text{} \\ \hline \text{1} & \text{} \\\hline  \text{2} & \text{42} \\ \hline  \text{3} & \text{23} \\\hline   \text{4} & \text{34} \\\hline   \text{5} & \text{52} \\\hline   \text{6} & \text{46} \\\hline   \text{7} & \text{33} \\\hline   \text{8} & \text{} \\\hline   \text{9} & \text{}  \\\hline \end{array}$$

How many different insertion sequences of the key values using the same hash function and linear probing will result in the hash table shown above?

  1. $10$
  2. $20$
  3. $30$
  4. $40$

13 Answers

Best answer
121 121 votes

Option (C).

Slots $3,4,5$ and $6$ must be filled before $33$ comes. Similarly slots $2,3$ and $4$ must be filled before $52$ comes. And $52$ must come before $33$, as it is not occupying slot $2$. So, $33$ must be at the end and $52$ can come at position $4$ or $5$.

Let $52$ come at position $4$. Slots $2, 3$ and $4$ must be filled before $52$ leaving only slot $6$ left for the element coming at position $5$ which should be $46$. So, the first $3$ elements can come in any order giving $3! = 6$ ways.

Let $52$ come at position $5$. Now, the first four elements can come in any order. So, $4! = 24$ ways.

So, total number of different insertion sequences possible $= 24 + 6 = 30$

• edited by
110 110 votes

answer = option C

the element $33$ has managed to hold position at slot #7 it means elements should occupy slot #3 to slot #6 before it in the sequence. Currently, it seems like all element except $42$ should come before $33$ in the sequence.

But, element $52$ requires that $42$ comes before it. and $33$ requires that $52$ comes before it. This means that $42$ has to come before $33$. this makes element $33$ to occupy last position in the sequence.

now for element $52$ to occupy its place these can be two cases :

  • Case 1 : $\boxed{\{42,23,34\}}, 52$ 
  • Case 2: $\boxed{\{42,23,34,46\}}, 52$ 

Case 1 means that those three elements comes before $52$ = $3! = 6$ways
Case 2 means that those four elements comes before $52$ = $4! = 24$ways

Combining all info we get,
Total number of sequences possible that will form the same hash table as above $= (6 + 24) \times 1 = 30$

• edited by
96 96 votes

there are 6 elements,

__ __ __ __ __ __

1  2  3  4  5  6

1) we can clearly observe that, 33 is always last, therefore fix it ===> 1 choice only for 33

 

Now we have 5 elements

__ __ __ __ __

1  2  3  4  5

46 can insert it any where ===> 5C1 = 5 choices

 

remaining 4 elements

__ __ __ __

1  2  3  4

clearly we can observe that, 52 is the las element ===> fix it ==> 1 choice

 

remaining 3 elements

__ __ __

1  2  3

 

there is no conflict between them ===> 3! possibles

 

Totally = 1 * 5 * 1 * 3! = 5*6=30


Blog: https://gateoverflow.in/blog/16797/permutations-and-combinations-specific-to-dag


Practice: 

 https://gateoverflow.in/253496/

 https://gateoverflow.in/243402/hashing

https://gateoverflow.in/240941/topological-sort

https://gateoverflow.in/243285/avl-tree

https://gateoverflow.in/245897/hashing-with-linear-probing?show=245926#c245926

https://gateoverflow.in/118640/gate-cse-2017-set-2-question-44?show=289691#a289691

• edited by
25 25 votes
Convention Followed here:-Those things in ( ) can be permute in any order. Except bracket all no. are fixed

Here 2 cases occur

Case1:-->>(42,23,34,46),52, 33

(Means first 4 item permutable  and last 2 item fixed)

Due to mod 10 function they will always go to their unit position Bucket

so 4!=24 Insertion Sequence possible.

Case2:-->>(42,23,34),52,46,33

Case2 Explanation...

To get more insertion sequence we compulsory put 52 as 4th item in insertion sequence which will be different from above 24 insertion sequence bcz in those 24 sequence 52 always comes as 5th item of insertion sequence where as here it comes as 4th item of insertion Sequence.

So 3!= 6 possibilities

So total case1+case2=24+6= 30 possibilities.
17 17 votes

In the above expression, 3! is for elements 42, 23 and 34 as they can appear in any order, and 5 is for element 46 as it can appear at 5 different places.

so  Total number of different sequences = 3! x 5 = 30

10 10 votes
As in previous we found sequence 46,34,42,23 are added in to hash table as we add 52 now ,2nd position is already occupied and now to enter 52 there are 6 possibilities ,now when we add 33 ,as 3 position is already occupied now to enter 33 there are 5 possibilities

so total different possibilities = 6*5= 30

so option c is correct
Answer:
Position:
Show:

Related questions

32 32 votes
3 answers 3 answers
10.5k
10.5k views
go_editor asked Sep 30, 2014
10,520 views
A hash table of length $10$ uses open addressing with hash function $h(k) = k \mod 10$, and linear probing. After inserting $6$ values into an empty hash table, the table...
60 60 votes
4 answers 4 answers
25.1k
25.1k views
Arjun asked Feb 12, 2020
25,071 views
Consider a double hashing scheme in which the primary hash function is $h_1(k)= k \text{ mod } 23$, and the secondary hash function is $h_2(k)=1+(k \text{ mod } 19)$. Ass...
63 63 votes
4 answers 4 answers
18.2k
18.2k views
go_editor asked Sep 30, 2014
18,212 views
The following C function takes a singly-linked list as input argument. It modifies the list by moving the last element to the front of the list and returns the modified l...
88 88 votes
14 answers 14 answers
30.3k
30.3k views
go_editor asked Sep 29, 2014
30,342 views
In a binary tree with $n$ nodes, every node has an odd number of descendants. Every node is considered to be its own descendant. What is the number of nodes in the tree ...