 Hello everyone, my name is Nikhil Gadjam working as assistant professor in department of computer science and engineering in Valchan Institute of Technology, Holapur. In this video we will see hashing with quadratic probing as a collision resolution technique. The learning outcome of this video is at the end of this session student will be able to apply quadratic probing technique for hashing. Now there are two collision resolution technique broadly classified as separate chaining and open addressing. As we know collision occurs when two input values produces same hash key by the hash function. So if value is already present at particular slot, we cannot insert a next value at that particular slot. In that case we call it as collision occurs. For handling this collision situation there are two mainly broadly classified methods are separate chaining and open addressing. Now this is a diagram for separate chaining. I have taken hash table of size array 10, so indexing from 0 to 9 and suppose I want to insert 11, 21, 51 and 25, so a separate link list is created and elements are stored in a particular link list which are producing same hash value. So in this case 11, 21 and 51 are stored in separate link list because all are producing a same hash key that is 1 assuming that I am using hash function as mod size. So in this case mod size is mod 10, so 11 mod 10 is 1, 21 mod 10 is 1, 51 mod 10 is 1. So all the values which are producing same hash key or same hash value those are stored in a single same link list. So this is separate chaining, advantage of separate chaining we have already seen, there is no size limit because memory allocated in link list are dynamically. So size is not limited when you are using separate chaining. If we talk about open addressing, again there are three functions related to open addressing or three sub methods related to open addressing those are linear probing, quadratic probing and double hashing. In previous video we have seen the implementation of linear probing for collision resolution technique where if collision occurs then a value, new value will be inserted in the next free slot. So in this video we will concentrate on quadratic probing. Using quadratic probing hash key is calculated using following formula, hash key is equal to hash key plus i square mod size because of this i square the method name is given as quadratic probing value of i ranging from 1 to n. So initially if collision occurs in that case hash value plus 1 square mod size, if that slot is also full in that case hash value plus 2 square mod size like this wise we will see an example. If collision occurs then element will be inserted at hash key of x plus 1 into 1 because i starting from 1 to n. So initially value of i will be 1 mod size if that slot is also full in that case again the element will be inserted at hash of x plus 2 square mod size. So on the i will start from 1 to n, we will see an example. Now suppose I am using a hash table of size 10 and I want to insert 11, 21, 31, 54 and 41 and assuming that if collision occurs I am resolving that collision using quadratic probing method. So formula for calculating quadratic probing as we know hash key of value is equal to hash key of value plus i square mod size. So first element I want to insert is 11. So I will calculate hash key of 11 is equal to 11 mod 10. So I am using division method for calculating hash value for the input element. So hash value calculated as 1. So first slot or element I want to insert at index 1 that is free. So 11 will be inserted directly at index 1. Next element is 21. So first I will calculate 21 mod 10. So it calculates as 1. So 1 is already occupied by element 11. So collision occurs. So I will use quadratic probing now. So hash key of 21 is equal to 21 mod 10 that is 1 square is equal to 2. So 1 plus 1 square is equal to 2 mod 10 is 2. So 21 will be inserted at index 2. Now next element I want to insert is 31. Now again initially 31 mod 10 is 1. So 1 is already full. So I will use quadratic probing. So hash key of 31 is equal to 31 mod 10 plus 1 plus 2 square. 2 square is 4. 1 plus 4 is 5. So 5 mod 10 is 5. So 31 will be inserted at index 5. Now next element I want to insert is 54. So 54 mod 10 is 4. So at 4th index there is no element. The slot is free. So 54 is directly inserted at index 4. Next element I want to insert is 41. So 41 mod 10 is 1. So at 1 index already 11 element is present. So I am using quadratic probing. I have already used value 1 and 2 for i. So I will use value 3 for i here. So it is hash value of 41 is 1. So 1 plus 3 square 3 square is 9. So 1 plus 9 is 10. 10 mod 10 is 0. So 41 will be inserted at index 0. So like this wise element is inserted using this formula where i value ranges from 1 to n. Now you can pause the video and you can answer what is the advantage of using quadratic probing over linear probing. So answer for this is no clustering. We will go to same example here. Suppose now in this case suppose I am using linear probing for this example again linear probing means you are inserting a next element in the next free slot if collision occurs. So first element 11 I will inserted at index 1. I am assuming that I am using mod size as a hash function. Next element is 21. So 21 will be inserted in the next free slot. So 21 will be inserted at index 2. Next element I want to insert is 31. So 31 will be inserted in the next free slot. That is 31 will be inserted in the index 3. So like this wise all the elements which are producing same hash key those are stored in the same part of the hash table. So this disadvantage of this linear probing we call it as clustering. Clustering means most of the elements are stored at the same part of the array or hash table. So this disadvantage is overcome in the quadratic probing. Suppose we are assuming the same example 11 will be stored in the index 1, 21 will be stored at the index 2. Now 31 will not be stored in the index 3 as of linear probing. Now 31 will be stored at index 5 because you are using i square value. So initially i will be 1, next time i will be 2, next time i will be 3. So all the elements which are producing same hash key will not be stored in the same part of the array. Those are distributed equally along with the array. So this is an advantage of using quadratic probing over linear probing. Now again we will see the difference between open addressing and chaining. So we have already seen there are two broadly classified methods for collusion resolution techniques. Those are open addressing and chaining. Now in open addressing size limitation is there because you are not using dynamic memory allocation. So size limitation is there. Whatever element you want to store, you have to store inside that hash table only. But in chaining there is no size limitation is there because at each index you are generating or you are creating a linked list. So all the elements which are producing same hash key will be stored in a same linked list. So there are n number of linked lists will be created in chaining and each linked list may have infinite number of nodes. So size limitation is not there in chaining. Second difference is open addressing, collusion resolution technique is easy to implement and chaining for collusion resolution technique is somewhat complicated or complex implementation as compared to open addressing. Third difference is open addressing is used when frequency and number of keys is known to a user or programmer. Because based on number of keys you can define a size of an hash table. If input numbers are not known to a programmer in that case you are generally using chaining and when you are using chaining the size restriction for input numbers is not defined. So you can enter number of different number of inputs and you can store in chaining method. So chaining is mostly used when unknown how many numbers and how many frequency of keys are inserted and deleted. So apart from complex implementation chaining is more advantageous than open addressing. Now these are the references I have used for creation of this video. Thank you.