Hashing Hashing is the transformation of a string of character into a usually shorter fixed- length value or key that represents the original string. Hashing is used to index and retrieve items in a database because it is faster to find the item using the shortest hashed key than to find it using the original value. It is also used in many encryption algorithms. A hash code is generated by using a key, which is a unique value. Hashing is a technique in which given key field value is converted into the address of storage location of the record by applying the same operation on it. The advantage of hashing is that allows the execution time of basic operation to remain constant even for the larger side. Why we need Hashing? Suppose we have 50 employees, and we have to give 4 digit key to each employee (as for security), and we want after entering a key, direct user map to a particular position where data is stored. If we give the location number according to 4 digits, we will have to reserve 0000 to 9999 addresses because anybody can use anyone as a key. There is a lot of wastage. In order to solve this problem, we use hashing which will produce a smaller value of the index of the hash table corresponding to the key of the user. Universal Hashing Let H be a finite collection of hash functions that map a given universe U of keys into the range. Such a collection is said to be universal if for each pair of distinct keys k,l∈U, the number of hash functions h∈ H for which h(k)= h(l) is at most |H|/m. In other words, with a hash function randomly chosen from H, the chance of a collision between distinct keys k and l is no more than the chance 1/m of a collision if h(k) and h(l)were randomly and independently chosen from the set . Rehashing If any stage the hash table becomes nearly full, the running time for the operations of will start taking too much time, insert operation may fail in such situation, the best possible solution is as follows: 1. Create a new hash table double in size. 2. Scan the original hash table, compute new hash value and insert into the new hash table. 3. Free the memory occupied by the original hash table. Example: Consider inserting the keys 10, 22, 31,4,15,28,17,88 and 59 into a hash table of length m = 11 using open addressing with the primary hash function h' (k) = k mod m .Illustrate the result of inserting these keys using linear probing, using quadratic probing with c1=1 and c2=3, and using double hashing with h2(k) = 1 + (k mod (m-1)). Solution: Using Linear Probing the final state of hash table would be:.
[Audio] Hashing is a powerful tool used in various applications, including database management systems. One of the ways hashing is implemented is through the use of probing techniques. There are two main types of probing techniques: quadratic probing and double hashing. Both methods aim to resolve collisions that occur when multiple keys hash to the same index in the hash table. Quadratic probing uses a formula to calculate the next index to search for a key that has collided with another key. The formula involves adding a constant value to the current index and squaring the result. This approach helps to distribute the colliding keys evenly across the hash table. Double hashing, on the other hand, uses two hash functions to generate two different indices. If a collision occurs, the second hash function is used to generate a new index. This approach ensures that the colliding keys are distributed randomly across the hash table. Both quadratic probing and double hashing are effective methods for resolving collisions in hash tables. They help to maintain the efficiency and performance of the hash table by minimizing the likelihood of collisions and ensuring that the keys are stored in a way that makes them easily retrievable..
[Audio] In this slide, we discuss hash tables, which are collections of items stored in a manner that enables easy retrieval later. Each position in the hash table is referred to as a slot, capable of holding an item identified by an integer value commencing from zero. The mapping between an item and a slot where the item resides in a hash table is termed a hash function. This function accepts a key and returns its hash coding or hash value. We utilize a set of integers, comprising 54, 26, 93, 17, 77, and 31, to illustrate how our initial hash function operates. We employ the "remainder method," dividing the item by the table size and returning the remainder as its hash value. For instance, assuming the table size is 11, we obtain the hash values 10 for 54, 4 for 26, 5 for 93, 6 for 17, 0 for 77, and 9 for 31. These hash values enable rapid location of corresponding items within the hash table..
[Audio] When we need to search any element, we simply divide it by the table size, and we obtain the hash value. As a result, we achieve an O(1) search time. However, if we consider an additional element, such as 44, when we apply the hash function on 44, we get 44 modulo 11 equals 0. But 0 hash value already has an element 77. This problem is known as a collision. A collision occurs when two or more items require the same slot according to the hash function. This is referred to as a collision. We use HashTables because if the universe of keys is large, storing a table of size [U] may be impossible. Additionally, if the set of keys is small relative to the universe, the space allocated for the table will be wasted. Therefore, HashTables require less storage. Indirect addressing of an element with a key k is stored in slot k, with hashing being stored in h(k), where h is a hash function and hash(k) is the value of key k. The hash function requires an array range..
[Audio] Hashing is the transformation of a string of characters into a usually shorter fixed-length value or key that represents the original string. Hashing is used to index and retrieve items in a database because it is faster to find the item using the shortest hashed key than to find it using the original value. It is also used in many encryption algorithms. A hash code is generated by using a key, which is a unique value. Hashing is a technique in which given key field value is converted into the address of storage location of the record by applying the same operation on it. The advantage of hashing is that it allows the execution time of basic operations to remain constant even for the larger size. Suppose we have 50 employees, and we have to give a 4-digit key to each employee (as for security), and we want after entering a key, direct users map to a particular position where data is stored. If we give the location number according to 4 digits, we will access the data quickly. Hashing is used in various applications such as databases, file systems, and web servers. It is also used in many encryption algorithms. Hashing is a technique in which given key field value is converted into the address of storage location of the record by applying the same operation on it. The advantage of hashing is that it allows the execution time of basic operations to remain constant even for the larger size. Hashing is used in various applications such as databases, file systems, and web servers. It is also used in many encryption algorithms. Hashing is a technique in which given key field value is converted into the address of storage location of the record by applying the same operation on it. The advantage of hashing is that it allows the execution time of basic operations to remain constant even for the larger size. Hashing is used in various applications such as databases, file systems, and web servers. It is also used in many encryption algorithms. Hashing is a technique in which given key field value is converted into the address of storage location of the record by applying the same operation on it. The advantage of hashing is that it allows the execution time of basic operations to remain constant even for the larger size. Hashing is used in various applications such as databases, file systems, and web servers. It is also used in many encryption algorithms. Hashing is a technique in which given key field value is converted into the address of storage location of the record by applying the same operation on it. The advantage of hashing is that it allows the execution time of basic operations to remain constant even for the larger size. Hashing is used in various applications such as databases, file systems, and web servers. It is also used in many encryption algorithms. Hashing is a technique in which given key field value is converted into the address of storage location of the record by applying the same operation on it. The advantage of hashing is that it allows the execution time of basic operations to remain constant even for the larger size. Hashing is used in various applications such as databases, file systems, and web servers. It is also used in many encryption algorithms. Hashing is a technique in which given key field value is converted into the address of storage location of the record by applying the same operation on it. The advantage of hashing is that it allows the execution time.
[Audio] A good hash function is crucial to minimize collisions in the first place. It should distribute keys uniformly across the hash table and be fast to compute. When the hash table becomes too full, resizing it to a larger size can significantly improve performance. This involves creating a new, larger hash table and rehashing all existing keys into the new table. The choice of collision resolution technique depends on the specific application requirements, such as memory constraints, performance needs, and the expected number of collisions. There are two main methods used to implement hashing: hashing with chaining and hashing with open addressing. Hashing with chaining stores elements in linked lists at each index, while hashing with open addressing probes for the next available slot. Both techniques have their advantages and disadvantages, and the choice between them depends on the specific requirements of the application..
[Audio] When we use chaining as a collision resolution method, we create a linked list for each slot in the hash table. This means that all elements that hash to the same slot are stored in the same linked list. We can see this illustrated in the figure provided, where slot j contains a pointer to the head of the list of all stored elements that hash to j. If there are no elements that hash to j, then slot j simply contains NIL. Each hash-table slot T[j] contains a linked list of all the keys whose hash value is j. For instance, we might have h(k1) = h(k4) and h(k5) = h(k7) = h(K2). The linked list can be either singly or doubly linked, but we show it as doubly linked because deletion is faster that way. By analyzing hashing with chaining, we can see that it provides a simple and effective way to resolve collisions in a hash table..
[Audio] The load factors alpha for a hash table T with m slots that stores n elements is defined as n/m, which represents the average number of elements stored in a chain. The worst-case running time for searching is theta(n) plus the time to compute the hash function, which is no better than if we used one linked list for all the elements. The average performance of hashing relies on how well the hash function h distributes the set of keys to be stored among the m slots, on average. For instance, let's consider the insertion of elements 5, 28, 19, 15, 20, 33, 12, 17, 10 into a chained hash table. Assuming the hash table has 9 slots and the hash function is h(k) = k mod 9, we create a linked list for each slot and store values accordingly. The initial state of the chained hash table is formed by inserting these elements. We begin by inserting 5, which creates a linked list for T[5] and stores the value 5 in it. Next, we insert 28, which creates a linked list for T[1] and stores the value 28 in it. Then, we insert 19, which inserts the value 19 at the beginning of the linked list for T[1], and so on..
[Audio] The hash table continues to be built by inserting additional values. The process begins with the insertion of the value 15, yielding a hash value of 6. A link list is created for T[6] and the value 15 is stored within it. Subsequently, the values 20, 33, 12, 17, and 10 are inserted, resulting in hash values of 2, 6, 3, 8, and 1, respectively. These values are then stored in the linked lists for T[2], T[6], T[3], T[8], and T[1]. Following the insertion of these values, the chained-hash-table depicted below is obtained. This serves as an illustration of how chaining operates in hashing, wherein multiple values can be accommodated within a single bucket..
[Audio] In open addressing, the main advantage is that it avoids the use of pointers. This means that we do not share pointers between different parts of the hash table, which frees up more memory. As a result, we can expect fewer collisions and faster retrieval times. The process of examining locations in the hash table is called probing. We require that for every key, the probe sequence is a permutation of the possible indices, ensuring that we always find the correct location in the hash table. The hash function maps the key to a specific index in the hash table. The hash-insert procedure inserts a new key-value pair into the hash table, while the hash-search procedure searches for a key in the hash table and returns its corresponding value if found. If the key is not found, it returns NIL..