0

A hash table of length 10 uses open addressing with hash function h(k)=k mod 10, and linear probing. After inserting 8 values into an empty hash table, the table is as shown below

0 |
1 | 91
2 | 2
3 | 13
4 | 24
5 | 12
6 | 62
7 | 77
8 | 82
9 |

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?

ANSWER - 128.

I know for 91,2,13,24,77 its 5! = 120 but i can't figure out what are the other 8 combinations ?

Ved sinha
  • 69
  • 3
  • 9
  • 1
    How can inserting 6 values into an empty hash table create 8 items in the table? Also, your calculation of the number of insertion sequences only shows 5 values. Where is the 6th? As written, your question can't be answered because it makes no sense. Are we working with 5 values? 6? 8? – Jim Mischel Jan 17 '19 at 03:07
  • Sorry it is 8. I mistyped. – Ved sinha Jan 17 '19 at 18:05
  • I corrected the error @JimMischel, Thanks for pointing out. – Ved sinha Jan 17 '19 at 18:06
  • The order will change if you enter 82 before you enter 2, for example. – Jim Mischel Jan 17 '19 at 19:11
  • Obviously @JimMischel even if you enter 62 after 82 order will change , Here 2->12->62->82 is fixed order and 91,2,13,24,77 can occur in any order and they will get there respective slots. so 5! ways , they can come in. Now i was asking what are other arrangements as 77 may come after 12 or 62. But 77 can't come after 82 as then 82 will be placed in 77's slot. – Ved sinha Jan 18 '19 at 18:59

2 Answers2

1

The answer given is wrong, Actualy it was a mocktest and answer provided by the source is wrong. The real answer is 168.

It can be done in 2 ways -

1) 91,2,13,24,12,62,77,82 - Here if you see and filter out details

  _,91,_,2_,13,_,24,_,12,_,62,_,82 

In all the available gaps we could fill 77 it will always result in 7th slot so total number of ways 77 can come - any of 7 places i.e 7.

Now 91,2,13,24 can come in any order and can be arranged as above so total ways - 4! and for every of the 4! arrangements 77 can come at any of the 7 places so answer is - 4!*7 = 168.

2) Second way is - There are 3 possible sequence only

i) 91,2,13,24,77,12,62,82

 Here 91,2,13,24,77 can come in any order, They will get there respective 
 slots so total 5! ways.

ii) 91,2,13,24,12,77,62,82

  Here 91,2,13,24 can come in any order and we have fixed 77 after 12 so total 
  4! ways.

iii) 91,2,13,24,12,62,77,82

   same here with 4! ways 91,2,13,and 24 can come and 77 is fixed after 62.

so total 5!+4!+4!=168.

Ved sinha
  • 69
  • 3
  • 9
0

After giving it a thought I came up with this. First of all 12,62,82 are the values whose order we must not disturb, the reason behind this is they are eager for the same position. So for example, if 62 or 82 came earlier than 12 then they will take the position of 12 and end up in a different hashtable state.

So we will take them as a single entity "12,62,82" named DND(DO NOT DISTURB).

1- Now we have 91,2,13,24,77 they all are independent of each other as they are seeking different hash positions, let's call them "Freebies". Meanwhile, DND is sitting quietly after Freebies combinations.

Total combinations -> 5! => 120.

2- Now we will take elements one by one from DND without disturbing their own order and settle with others -

I -> 12 before 77 -> [comb(91,2,13,24), 12, 77, 62, 82] -> 4!

II -> 12,62 before 77 -> [comb(91,2,13,24), 12, 62, 77, 82] -> 4!

Total combinations -> 4! * 2.

3- Now 91 is the number that will not disturb the DNDs. Putting 91 after DND we have three cases -

I -> DNDs between 77 and 91 -> [comb(2, 13, 24, 77), DNDs, 91] -> 4!.

II -> Now let's disturb DNDs and take element 12 from them and put it before 77 -> [comb(2,13,24), 12, 77, 62, 82, 91] -> 3!

But I can put 91 before 82 and 62 as well which will add up to 3 combinations with 3! Which takes sum to 3! * 3.

III -> Now taking 62 from DNDs and putting it between 12 and 77 -> [comb(2, 13, 24), 12, 62, 77, 82, 91] -> 3!

Again here I can put 91 before 82 which will add all to 2 combinations with 2! ->3! * 2.

Total Combinations -> 4! + 3!*5

**Now the answer that came into the picture is -> 5! + 4!2 + 4! + 3!5 -> 222. That's all that I can figure out. Please tell me if I did something wrong.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 11 '23 at 05:16