Lab#01: Hashing SSUET/QR/114 LAB # 04 Hashing With Collision Resolution Object To hash an array of n-number using hash function h (k) =k mod n Theory An array in which records are not stored consecutively - their place of storage is calculated using the key and hash function h maps keys of a given type to integers: h (k) = key mod N is a hash function for integer keys The integer h (k) is called the hash value of key k Algorithm HashFunc (Key, N) Hkey=key mod N Return Hkey Iscollision (HT, Hkey) If HT [Hkey] =NULL Return 0 Else Return 1 LinearProb (HT, Hkey, N) Set Newkey= (HKey+1) mod N, HTstatus=0 Repeat while Newkey ≠Hkey OR isCollision (HT, Newkey) =0 Newkey=Newkey+1 If Newkey=Hkey than HTstatus=1 Return NewHkey, HTstatus CE-205: Data Structures and Algorithms Page 1 Lab#01: Hashing SSUET/QR/114 ColResolution (HT, Hkey, key, N) Call LinearProb (HT, Hkey, N, NewHkey, HTstatus) If HTstatus=1 Than Print “No space Hash Table is overflow” Else HT [NewHkey] =Key Return updated HT Insert (HT, Key) Hkey= HashFunc (Key, N) If IsCollision (HT, Hkey) =0 HT [Hkey] =key Else Call ColResololution (HT, Hkey, Key, N) Return updated HT Search (HT, Key, N, Loc) Hkey=HashFunc (HT, Key), temp=Hkey Repeat while HT[HKey]≠Key Hkey= (Hkey+1) mod N If Hkey=temp than Hkey=-1 Loc=Hkey and Return Delete (HT, Key, N) Loc=Search (HT, Key, N) If Loc=-1 than Print “Key not available “ Else HT [loc] =Null Task 1. Enter data of a cricket team 11 players which is supposed to be a hash table value and insert runs of each player as a data, find out key treat is Rank# of a player. For example: Runs are 30 mod by 11 which is index no 8; rank#8 is a rank of a team member. CE-205: Data Structures and Algorithms Page 2