You are on page 1of 7

ASSAIGNEMENT 1

1 Open addressing
a)Let us consider a simple hash function ”key mod 7” and sequence of keys as
50,700,76,85,92,73,101. Inset the values into hash table using liner probing.

50%7=1

700%7=0

76%7=6

85%7=1

92%7=1

73%7=3

101%7=3

0 700
1 50
2 85
3 92

4 73
5 101

6 76

b)concider a simple hash function with table sige of 7, insert the sequence of keys
76,40,48,5,20 into hash table using quadratic probing.
Keys={76,40,48,5,20}
T.S=7
76%7=6
40%7=5
48%7=6
h(key)=(h(ky)+i2)mod7.5
=(48+(1*1))mod7
=49mod7
=>5%7=5=>full (1)
h(key)=(h(key)+i2)mod T.S
=(5+(71))mod7
=6 mod7
=6=>full(2)
h(key)=(6+(2*2))mod7
=10mod 7
=3
=>20%7=6=>full(3)
H(key)=(20+(3+3))mod7
=(20+9)mod 7
=29mod7
=1

0 48
1 20
2
3 5
4
5 49

6 76
2)open addressing
(a)double hashing
Keys={19,27,36,10}

T.S=13
Hash 1(key)=key+13

Hash2(key)=7-(key%7)

19%13=6

27%13=1

36%13=10

10%13=10

7-key(%7)=7-(10%7)

=7-3

=4

0
1 27
2
3
4 10
5
6 19
7
8
9
10 36
11
12

(b)key={5,2,6,3,11,3,1}
T.S=10

Hash 1(key)=key%10

Hash 2(key)=5-(key%5)

5%10=5

2%10=2

6%10=6

8%10=8

11%10=1
2%10=3

1%10=1

5-(key%5)=5-(1%5)

=5-1

=4

0
1 11
2 2
3 3
4 1
5 5
6 6
7
8 8
9

3) Rehashing
T.S=10

Key={7,84,31,57,44,17,14,64}

0 1 2 3 4 5 6 7 8 9

4(x)=x used 10

7%10=7

84%10=4

31%10=1

57%10=7

44%10=4

19%10=9

27%10=27

14%110=4

64%10=4
=n/N =9/10=0.9*0.5

Newsinge=2N(Pvime)

=2*10

=20(23)

h(7)=7%23=7 h(19)=19%23=19

h(84)84%23=15 h(27)=27%23=3

h(31)31%23=8 h(27)=27%23=14

h(57)57%23=11 h(14)=14%23=18

h(44)=44%23=21

=n/N =9/23 =0.34205

27 7 31 57 14 24 64 19 44
0

4)extendible hashing
Keys 16,4,6,22,24,20,31,7,9,20,26

Bucket size=3

Key h(k)=k mod

Num binary form

16 10000

4 00100

22 10110

24 11000

12 01010

31 11111

7 00111

9 01001

20 10100
26 01101

Inserting 16 LSB of 16 is 0

You might also like