 Hello everyone, my name is Nikhil Gadjum working as assistant professor in department of computer science and engineering in Valchand Institute of Technology, Solapur. In today's video, we will see hashing with linear probing as a collision resolution technique. These are the learning outcome at the end of this session, at the end of this video student will be able to apply linear probing technique on hashing. Now, this is a general hashing diagram we have already know is an input key input number that is given as a input to hash function, hash function which applies a function different function on the input number and returns a hash value which is nothing but a position where the input number is stored inside this hash table. Now, again collision we have already seen collision means if input number produces same hash number which is already present in the hash table in that case that situation we call it as collision. This is an example of collision, suppose I have used array of size 10 as a hash table and I want to insert these numbers inside a hash table and I have used hash function as mod means division function. So, first 11 is inserted at position 1 or index 1. Next number is 21, when I apply hash function mod size, so 21 mod 10 is 1, so 21 should be stored at index 1, but at index 1 already 11 is present, so 21 cannot be replaced 11, so in this situation we call it as collision because both 21 and 11 produces same hash key that is 1. Now, there are different techniques present how to resolve, how to handle this collision situation, mainly those are categorized into two methods, first one is separate chaining and second one is open addressing, we will see one by one. Separate chaining means at each index there is a linked list is created, so all the numbers which produces same hash key will be present in one linked list. So, linked list present at index 1 contains 11, 21 and 51 because when I apply hash function as mod 10, so all these numbers 11, 21 and 51 produces only one output that is 1, so all these numbers are stored in only one linked list and that linked list is present at index 1, 25 is another number we will create a new linked list that will stored at index 5, so this is separate chaining method. Second category we called as open addressing, in open addressing there are three categories or three subcategories, first one is linear probing, second one is quadratic probing and third one is double hashing, so in this video we will concentrate only on linear probing, so linear probing if collision occurs then that number is stored in the next free slot. So, general formula is given as once we apply hash function, so a new hash value will be hash value plus 1 mod size, mod size is if we apply division method as a hash function, so we will increment 1 by 1 into hash value if collision occurs and we will insert a new number in the next free slot. We will see an example, now suppose I want to stored 11, so 11 mod 10, 1, so 11 is stored at index 1, so next number is 21, so I have applied mod size mod 10 as a hash function to 21, so it produces output as 1, so 11 is already present at index 1, so we cannot stored 21 at index 1, now we will move forward to a next index, next index is second index, second index is free, so we will insert 21 at second index, similarly 31 again 31 produces 1 only, so collision occurs at index 1, so we will go to next slot, next slot is 21, so next 21 is also filled at index 2, we will go for next free slot, so 31 is inserted at index 3, next number is 54, 54 is stored at index 4 and 41, 41 again collision occurs at index 1, we will move forward till next free slot, so 41 is stored at index 5, so this is a linear probing technique. You can pause the video and you can answer what is the disadvantage of linear probing over chaining method, so answer for this is there are two disadvantage majorly, first one is clustering, second one is size limitation, clustering means if collision occurs you are storing that number to next free slot, so all the numbers which are producing same hash key are stored at one end of the array, so cluster occurs at that array because all similar number which produces same hash key for a particular hash function those are stored at one end or at one part, so cluster is created at that part. Second disadvantage is size limitation again, if you use chaining, inside chaining method you are using linked list, so there is no size limitation with chaining, but in linear probing you are using generally array as a hash table, so size limitation is one of the disadvantage of linear probing. We will see a C program for linear probing for collision resolution technique, now again in last video we have seen a hashing program in C language without collision, so I will run this program first, suppose I want to insert five numbers inside a hash table, those numbers are suppose 11, 22, 33, 44, 55, so this is a hash table of size 10, suppose I want to search 22, so it is saying that element is present, so this is a program, now I have not handled a collision resolution technique, now insert this program you are inserting directly at particular location, now I am not checking whether collision is occurring, if collision occurs I am not handling that collision, so I will make changes in this program only, I am using linear probing as a collision resolution technique now, once I have calculated index instead of storing element directly at that index, I will check whether that slot is free or not, now I am checking while array of index is not equal to 0, index equal to index plus 1, this is mod 10, now I am calculating new index till that index is free or that slot is free, after incrementing index I will insert a new element at particular index which is free now, so this is an insert method, similarly I will make changes in search, again in search you are directly calculating index of the element which is to be searched and I am checking directly at that index, now in linear probing if element is not present at particular index it is possible that it is present in the next index also, because if collision occurs you are storing the element which produces same hash key in the next free slot, so I am checking here while array of index this is not equal to 0, index equal to index plus 1, this index if this is double equal to temp, temp is a variable which contains element to be searched, I am printing printf element present found equal to 1, I will use one flag variable found, this is my else part, if this found double equal to 0, I am printing printf element is not present, I will execute this program, we will see whether this is working correctly or not, element is not present, I want to insert 5 numbers, so first one is 11, next one is 21, next one is 31, next one is 41 and last one is 51, now this is a hash table after inserting all those values, first 11 is inserted, I have applied mod 10 as a hash function so 11 should be stored at index 1, next number is 21, if I applied same hash function as mod 10, so it produces 1 only as a hash value, so at index 1, 11 is already present, so 21 should be stored in the next index, so 21 is stored in the index 2, again 31, again collision occurs at index 1, so 31 is stored in the next index, so next index 21 is already stored, so 31 is stored at index 3, similarly 41 is stored at index 4 and 51 is stored at index 5, now enter an element you want to search, suppose I want to search as 21, so element is present, first 21 is searched at index 11, because we have applied hash function as mod 10, so 21 mod 10 is 1, so 21 is searched at index 1, so at index 1, 21 is not present, we will search in the next index, so next index at index 2, 21 is present, so we have printed element is present and we are coming out of this while loop, so this is a while loop I have used for searching, so this is the C program for collision resolution technique using linear probing, we will again switch to our PPPT, these are the different references I have used for creation of this video, thank you.