 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 session, we will see hashing and different hash function. Now, these are the learning outcomes. At the end of this session, student will be able to find out hash key for an input value using appropriate hash function. We will just revise what is hashing again. Hashing is a process of indexing or storing and retrieving an element from the data structure with faster way to find out an element using hash key. Here, hash key is a value which provides an index value where to store the input value inside a hash table. So, hash key is different from the input value. Hash key is a value generated from a hash function which is actually a location where to store the input value inside a data structure we call it as hash table. Now, this is generalized diagram of hashing. This is a key or input value. We want to insert this input value key inside this hash table. Hash table, it is nothing but a data structure which stores multiple input values inside this data structure so that searching should be done efficiently. Now, there are two extra terms called as hash function and hash value. What is hash function? Hash function takes input as input element and generates output as a hash value of this input element. This hash value is nothing but a location where to store this input element inside this hash table. So, there may be a multiple hash function present so that it will map this input value with the actual data structure we call it as hash table. What is hash table? Hash table is just an array which maps input data to the data structure with the help of hash function such that insertion, deletion and search should be performed with a big of one time. Big of one time means there is only one comparison required for searching an element from the given data structure. Now, what is hash function? Hash function is a function which takes input data that is key as an input and generates an output which is an integer we call it as hash value which maps input data to a particular index inside hash table called as data structure. Again, we will go to a diagram. This is an hash function which takes input data as an input which generates a hash value. Hash value it is an integer value which is based on input data. This hash value is nothing but index of this hash table where to store this input data or key inside this hash table. So, hash value is nothing but a location where to store this input data inside this hash table. These are characteristics of good hash function. So, hash function which directly affects the complexity of a hashing. An ideal complexity of searching an element for hashing we call it as big of one but in general it is not possible every time to search an element with big of one complexity because of this hash function. So, these are different characteristics of good hash function. A hash function should have following properties. We will see one by one these characteristics. A hash value is fully determined by a data being hashed. So, whatever hash value is generated by the hash function should be fully determined by only a input data not by any other factors. Second one hash function uses all the input data. Now hash function is used to find out hash key from the input data and it should use all the data which is inputted to this hash function. It should not use a partial data for generating a hash value or hash key. So, it should use a complete data for generating a hash key. Hash function uniformly distributes the data across the entire set of possible hash values. Now meaning of this is hash function should distributes all the input data across the data structure or we call it as hash table. It should not generate a nearby hash keys or hash values so that cluster will form inside a data structure. If a hash function is generating a nearby values for different input values so all these different input values are stored at one part of the data structure. So, a cluster may form inside a data structure which affects on searching complexity of hashing. So, hash function should uniformly distributes the input data across the entire set of data structure or hash table. And last one hash function generates a different hash value for similar string though a strings are similar in nature the hash function should generate a different hash values for similar string. But it should generate a same hash value for same string but for similar string even if a small change inside a string it should generate a different hash value. But for if two strings are same it should generate a same hash value. Now these are different hash functions used for hashing. Now in general these are three hash functions used for finding out the hash key from the given input value. First one is folding. Inside folding it begins by dividing an item into equal size pieces. These pieces are then added together to give a resulting hash value for an example. Suppose input value is 1, 2, 3, 4, 5, 6 so using folding the input value is divided into three equal parts that is 1, 2, next part is 3, 4, next part is 5, 6. Then addition is performed on all these small pieces so 12 plus 34 plus 56 generating 102 mod 10. In this case I have used size of an array as 10 so it generates as a hash value as a 2. So this input value should be stored at index 2. So folding inside a folding you are dividing the input value into equal size pieces. A size may not be fixed but a size of piece should be a less than size of an array so that it will not stored out of bound index inside an array. So in general it should be a less than array size. Now we will see a second hash function that is mid square. Inside mid square first we square the input item and then we will extract some portion of a resulting digits. So inside a mid square first of all you are multiplying input element with the same number means you are squaring that input number and then you are retrieving some portion of the result as an hash key. So you are storing the input number at that position that is generated by mid square function. Third one is division this is a common and simple hash function mostly used hash function is division only. In this division function you are using mod operation and remainder will be used as an index for storing input value inside a hash function. So remainder will be your key retrieved by dividing input with the size of an array. So this is a generalized or general simple method division where you are performing mod operation with a size of an array. Now we will see an example suppose I have an array of size 10. So this array of size 10 I have used as a hash table as a data structure and I am storing input values inside this hash table using division method. So division method you are performing mod operation with a size of an array. Now in this example size of an array is 10. So you are performing hash function as mod 10. Suppose first number I want to insert is 52. So 52 mod 10 is 2. So 2 will be an index where to store 52 inside this an array of size 5. So 52 is stored at index 2. Next element I want to insert is 84. So 84 mod 10 is 4. So 84 will be stored at index 4. Next element is 68. 68 mod 10 is 8. So 68 should be stored at index 8. 99 is the next element. 99 mod 10 is 9. So 99 should be stored at index 9. Now there is one special situation we call it as collision inside an hashing. If we insert an element and it hashes to a same value which is already present at that location we call it as a collision. Collision means if two input values, two different input values generated same hash key inside in this case two values cannot be stored at same location. So only one value can be stored at one location. So second value cannot be stored at same location because two values are generating same hash key, same location. So in this case we call it as collusion. There are different collusion resolution technique how to handle if collusion occurs during hashing. So these are different collusion resolution technique. We will see one by one these collusion resolution techniques in the next session. So first one chaining, next one is open addressing. In open addressing there are different three methods are there. We call it as linear probing, quadratic probing and double hashing. Now this is an example again previous example where already 52, 84, 68 and 99 these four values are already stored inside this data structure we call it as hash table. Now suppose we want to insert a new element as 62. So again we have used division method. So division method 62 mod 10 which generates output as 2. So 62 should be stored at index 2. What happens is at index 2 already 52 is present. So you cannot store 62 at index 2 because of 52 is already present at that location. So this situation we call it as collision. So this is an example of collision. Now you can pause the video and you can answer what will be the value of hash key for an input element 999 having size of an array as 1000 using division method. You can pause the video and you can answer. So answer is 999. So input value is 999 and size of an array is 1000. So 999 mod 1000 will be a 999. So 999 is an index where you are storing an element input value 999. These are the references I have used for creation of this video. Thank you.