Intro into #Hashing ?
Published: 2021-01-20 15:12:03

<!-- wp:paragraph -->
<p>Hello, this blog contains the basic concept of hashing, hashing terminologies, various hashing functions, various collision resolution strategies, chaining with and without replacement, chaining using linked list and extendible hashing.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>At the end it contains link to a GitHub repository, along with my another blog on encryption and decryption. </p>
<!-- /wp:paragraph -->

<!-- wp:heading {"textAlign":"center","level":3} -->
<h3 class="has-text-align-center"><em>Concept of Hashing:</em></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>To search for a specific element, we will look at just a specific position. The element will be found there if it was kept there in the first place. Hence, to place an element, we will first calculate its location, place it there so that it can be retrieved from that position.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong><em>In hashing, the address or location of an identifier X is obtained by using some function f(X) which gives the address of X in a table.&nbsp;</em></strong></p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","width":539,"height":393,"sizeSlug":"large"} -->
<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2Fthumb%2F7%2F7d%2FHash_table_3_1_1_0_1_0_0_SP.svg%2F1200px-Hash_table_3_1_1_0_1_0_0_SP.svg.png&amp;f=1&amp;nofb=1" alt="" width="539" height="393"/></figure></div>
<!-- /wp:image -->

<!-- wp:heading {"level":5} -->
<h5><strong><em>Hashing Terminology:</em></strong></h5>
<!-- /wp:heading -->

<!-- wp:list {"ordered":true} -->
<ol><li><strong><em>Hash Function:</em></strong>&nbsp; A function that transforms a key X into a table index is called a hash function.&nbsp;</li><li><strong><em>Hash address: </em></strong>The address of X computed by the hash function is called the hash address or home address of X.&nbsp;</li><li><strong><em>Hash Table:&nbsp; </em></strong>The hash table is the sequential memory used to store identifiers.&nbsp;&nbsp;&nbsp;</li><li><strong><em>Bucket: </em></strong>Each hash table is partitioned into <strong><em>‘b’</em></strong> buckets ht[0]……ht[b-1].<ol><li>Each bucket is capable of holding ‘s’ records.&nbsp; Thus, a bucket consists of ‘s’ <strong><em>slots</em></strong>.&nbsp; When&nbsp; s = 1, each bucket can hold 1 record.&nbsp;&nbsp;</li><li>The function f(X) maps an identifier X into one of the ‘b’ buckets i.e from 0 to b-1.</li></ol></li><li><strong><em>Synonyms: </em></strong>Usually, the total&nbsp; number of possible values for identifier X is much larger than the hash table size.&nbsp; Therefore the hash function f(X) must map several identifiers into the same bucket.&nbsp;<ol><li>Two identifiers I<sub>1</sub> and I<sub>2</sub> are synonyms if f(I<sub>1</sub>) = f(I<sub>2</sub>)</li></ol></li><li><strong><em>Collision: </em></strong>When two non identical identifiers are mapped into the same bucket, a collision is said to occur, i.e. f (I<sub>1</sub>) = f(I<sub>2</sub>). Hence all synonyms occupy the same bucket.&nbsp;</li><li><strong><em>Overflow: </em></strong>An overflow is said to occur when an identifier gets mapped onto a full bucket.&nbsp;<ol><li>When s = 1, i.e., a bucket contains only one record, collision and overflow occur simultaneously.&nbsp; Such a situation is called a <strong><em>Hash clash</em></strong>.&nbsp;</li></ol></li><li><strong><em>Load factor:</em></strong>&nbsp; If n is the total number of identifiers in the table and t is the table size, the load factor is :&nbsp;&nbsp;&nbsp;<ol><li><strong>lf&nbsp; =&nbsp; n/t </strong>It represents the fraction of the table that is occupied.&nbsp;</li></ol></li><li><strong><em>Perfect Hash Function</em></strong> <strong><em>:</em></strong> Given a set of keys <em>k1, k2, … kn</em>, a perfect hash function<em>, f</em>,&nbsp; is such that f(<em>ki</em>) != f(<em>kj</em>) for all distinct i and j.</li></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>For an example, Let us consider a hash table with b= 26 buckets (from 1 to 26) each having 2 slots, i.e. s = 2.&nbsp; Assume that there are 10 distinct identifiers each beginning with a letter<strong>.&nbsp;</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Hash function f(X) = Number corresponding to the first letter of identifier i.e. if X = ‘A’, then f(X) = 1.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"left","id":3543,"width":185,"height":307,"sizeSlug":"large","linkDestination":"none"} -->
<div class="wp-block-image"><figure class="alignleft size-large is-resized"><img src="https://programmerprodigycode.files.wordpress.com/2021/01/image-1.png?w=319" alt="" class="wp-image-3543" width="185" height="307"/></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph {"align":"left"} -->
<p class="has-text-align-left">If the identifiers are GA, D, A, G, L, A2, A1, A3, A4, E . Their hash addresses will be&nbsp; 7,4,1,7,12,1,1,1,1,5 respectively.&nbsp; GA and G are : </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph {"align":"left"} -->
<p class="has-text-align-left"><strong>synonyms.&nbsp;A, A2, A1, A3 and A4 are synonyms</strong>.&nbsp;&nbsp;When G gets hashed into bucket 7, a <strong>collision</strong> is said to occur.&nbsp; When A1 gets hashed into bucket 1, which already contains A and A2, an <strong>overflow occurs.&nbsp;</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:heading {"textAlign":"center","level":3} -->
<h3 class="has-text-align-center"><em><strong>Hash Function</strong>:</em></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p><strong>Desirable Characteristics of a Hashing Function</strong></p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>It should be easily computable. </li><li>It should minimize the number of collisions.&nbsp;</li><li>The hash function should compute the address, which depends on all or most of the characters in the identifier.&nbsp;</li><li>It should yield uniform bucket addresses for random inputs.&nbsp; Such a function is called a uniform hash function.</li></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p><strong><em>1.Mid Square hash function:</em></strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This is a very widely used function in symbol table applications. It is the “middle of square” function, which is computed by squaring the identifiers and using an appropriate number of bits from the middle to obtain the bucket address.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">Example: (the size of the hash table = 100), If X = 225, X<sup>2</sup> = 050625&nbsp;then hash address = 06</pre>
<!-- /wp:preformatted -->

<!-- wp:paragraph -->
<p><strong>For more information,</strong></p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li><a href="https://research.cs.vt.edu/AVresearch/hashing/midsquare.php" target="_blank" rel="noreferrer noopener">https://research.cs.vt.edu/AVresearch/hashing/midsquare.php</a></li></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p><strong><em>2.Division hash function</em></strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The modulus operator can be used as a hash function.&nbsp; The identifier X is divided by some number M and the remainder is used as the hash address of X. &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>f(x) = X mod M.</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The best choice for M is that it should be a prime number.</p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted"><em>Example</em>: If&nbsp;X = 134 and M = 31 then f(X)= X mod M&nbsp;=&nbsp;<strong>134 mod 31&nbsp;=10</strong></pre>
<!-- /wp:preformatted -->

<!-- wp:paragraph -->
<p><strong><em>3.Folding hash function:</em></strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In this method, the identifier X is partitioned into several parts all of the same length except the last. These parts are added to obtain the hash address.<strong>&nbsp;&nbsp;</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><em><strong>Addition is done in two ways.</strong></em></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>1.Shift Folding: </strong>All parts except the last are shifted so that their least significant bits correspond to each other.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>For example, the hash function could form groups of three from the key 12320324111220. To determine the index to which the key is mapped the hash function “shifts” each set of digits under the other and adds them</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>2.Folding on the boundaries: </strong>The identifier is folded at the part boundaries and the bits falling together are added.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Group the digits in the search key as in shift folding but the middle numbers are folded on the boundary between the first group and the middle group and they are thus reversed.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":3550,"sizeSlug":"large","linkDestination":"none"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><img src="https://programmerprodigycode.files.wordpress.com/2021/01/image-3.png?w=852" alt="" class="wp-image-3550"/></figure></div>
<!-- /wp:image -->

<!-- wp:nextpage -->
<!--nextpage-->
<!-- /wp:nextpage -->

<!-- wp:heading {"textAlign":"center","level":3} -->
<h3 class="has-text-align-center"><strong>COLLISION RESOLUTION STRATEGIES</strong></h3>
<!-- /wp:heading -->

<!-- wp:heading {"level":5} -->
<h5><strong><em>1.Open Addressing:</em></strong></h5>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In an open addressing hashing system, if a collision occurs, alternative locations are tried until an empty location is found. Three techniques are commonly used for open addressing.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Features :</strong></p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>All the identifiers are stored in the hash table itself</li><li>Each slot contains an identifier or it is empty</li><li>Requires a bigger table for open addressing</li></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>1. <strong><em>Linear Probing or Linear Open Addressing </em></strong>:</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In this method, the hash address of identifier X is obtained.&nbsp; If the slot in its bucket is empty, the identifier is placed there. &nbsp;If an overflow occurs the identifier is placed in the next empty slot after its bucket.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","width":618,"height":463,"sizeSlug":"large"} -->
<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img src="https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Fimages.myshared.ru%2F17%2F1172365%2Fslide_18.jpg&amp;f=1&amp;nofb=1" alt="" width="618" height="463"/></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p><strong><em>Advantage</em></strong></p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>It is a simple method of overflow handling.</li><li>The method can be easily implemented using simple data structures like arrays.</li></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p><strong>&nbsp;</strong><strong><em>Disadvantage</em></strong></p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>An identifier whose bucket is full, will occupy the valid hash address of another identifier.&nbsp; Thus, one overflow will lead to many more.&nbsp;&nbsp;</li><li>If an identifier is not found at its computed address, a series of comparisons will have to be made in order to retrieve it.&nbsp;</li><li>If an identifier is not present in the bucket, the search will be terminated only the entire bucket is searched.</li><li>It creates a cluster of identifiers i.e. identifiers are concentrated in some parts of the table.&nbsp;</li><li>There is a possibility of the table becoming full.&nbsp;&nbsp;</li></ol>
<!-- /wp:list -->

<!-- wp:heading {"level":5} -->
<h5>2.<strong>Quadratic Probing</strong>:</h5>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In Quadratic Probing a quadratic function of <em>i</em> is used as the increment. when the identifier is not found in its bucket , we search in successive buckets using an increment <em>i</em>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The hash function is quadratic:<strong> </strong>this method checks the buckets number computed using a quadratic equation.&nbsp; This ensures that the identifiers are fairly spread out in the table.<strong>&nbsp;</strong></p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","width":409,"height":339,"sizeSlug":"large"} -->
<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2F4.bp.blogspot.com%2F_W4OZaaRtxGU%2FTPysr6xmG7I%2FAAAAAAAAA2s%2F2d-GF5Yl7zM%2Fs1600%2Fquadratic-probing.JPG&amp;f=1&amp;nofb=1" alt="" width="409" height="339"/></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p><strong>Advantages :</strong></p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>Avoids the clustering problem in linear probing to some extent</li><li>Faster insertion and deletion</li></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p><strong>Disadvantages:</strong></p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>There is no guarantee of finding an empty slot once the table becomes more than half full if the table size is not prime.</li><li>Although this method eliminates primary clustering, it does not eliminate another phenomenon called “secondary clustering” in which different keys that hash to the same value follow the same rehash path.</li></ol>
<!-- /wp:list -->

<!-- wp:heading {"level":5} -->
<h5>3.<strong><em>Rehashing</em></strong>:</h5>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In this method, if an overflow occurs, a new address is computed by using another hash function.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>A series of hash functions f<sub>1</sub>, f<sub>2</sub>, …..f<sub>n</sub> are used.&nbsp; To place an identifier X, f<sub>1</sub>(X) , f<sub>2</sub>(X) …..f<sub>m</sub> (X) are computed till an empty slot is found to place the identifier.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To search for identifier X, they are used in the same order to search the identifier.&nbsp;If all the hash functions have been used and the identifier is not found, it means that the identifier is not there in the table.&nbsp;&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","width":505,"height":378,"sizeSlug":"large"} -->
<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fimage1.slideserve.com%2F2555031%2Fan-example-rehashing1-l.jpg&amp;f=1&amp;nofb=1" alt="" width="505" height="378"/></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p><strong>Advantages</strong></p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>Does not lead to clustering</li></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p><strong>Disadvantages</strong></p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>The process may loop forever. This may happen when some rehash function results in the same hash address for an identifier.</li><li>It is difficult to find a series of hash functions yielding different addresses for the same identifier.</li><li>Rehashing is costly as each rehash function takes a finite amount of time.</li></ol>
<!-- /wp:list -->

<!-- wp:nextpage -->
<!--nextpage-->
<!-- /wp:nextpage -->

<!-- wp:heading {"textAlign":"center"} -->
<h2 class="has-text-align-center"><strong>Chaining</strong>:</h2>
<!-- /wp:heading -->

<!-- wp:heading {"level":5} -->
<h5><strong><em>1.Chaining without Replacement:</em></strong></h5>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The hash address of an identifier X is computed.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>If this position is vacant, it is placed there.</li><li>It its position is occupied by another identifier Y, the identifier X is put in the next vacant position and a chain is formed to the new position i.e. from Y to X.</li></ol>
<!-- /wp:list -->

<!-- wp:image {"align":"right","id":3558,"sizeSlug":"large","linkDestination":"none"} -->
<div class="wp-block-image"><figure class="alignright size-large"><img src="https://programmerprodigycode.files.wordpress.com/2021/01/image-5.png?w=150" alt="" class="wp-image-3558"/></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p><em>Example</em>:&nbsp;&nbsp;&nbsp; Identifier is <strong>11, 32, 41, 54, 33.</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Hash function:&nbsp;&nbsp;&nbsp; <strong>f(x) = X mod 10</strong> and Table size = 10</p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>Identifier 11 and 32 get hashed into positions 1 and 2 respectively.&nbsp;</li><li>The hash address of 41 is 1 but its position is occupied, hence it is put at position 3 and a chain is formed. &nbsp;&nbsp;&nbsp;</li><li>54 stored at position 4</li><li>The hash address of 33 is 3 but it is occupied.&nbsp; So 3 is placed at position 5 and a chain is formed from position 3 to 5 as shown.&nbsp;</li></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p><strong><em>Advantage:</em></strong></p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>Since identifiers are chained, we have to only use the chains to locate an identifier.</li><li>It is more efficient as compared to the previous methods.</li></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p><strong><em>Disadvantage:&nbsp;</em></strong></p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>The main idea is to chain all identifiers having same hash address (synonyms). However, when an overflow occurs,&nbsp; an identifier occupies the position of another identifier. Hence, even non-synonyms get chained together thereby increasing complexity.&nbsp;</li></ol>
<!-- /wp:list -->

<!-- wp:heading {"level":5} -->
<h5><strong><em>2.Chaining with Replacement:</em></strong></h5>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>This is an improvement over the above method. As we saw above, even non synonyms get chained.&nbsp;To avoid this from happening, if we find that another identifier Y which is a non-synonym, is occupying the position of an identifier X, X replaces Y and then Y is relocated to a new position.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>It will not make a difference to Y since Y was anyway not in its own bucket. But by placing X in its own bucket, we are improving the efficiency.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"right","id":3561,"sizeSlug":"large","linkDestination":"none"} -->
<div class="wp-block-image"><figure class="alignright size-large"><img src="https://programmerprodigycode.files.wordpress.com/2021/01/image-6.png?w=169" alt="" class="wp-image-3561"/></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Let us consider the same example as earlier.&nbsp; Here, 11, 32, 41 and 54 get placed in the same way as before.&nbsp; </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>However, when 33 has to be placed, its position is occupied by 41.&nbsp;Thus, 33 replaces 41 and 41 is now put into the next empty slot i.e 5 and the chain from element 11 at position 1 is modified.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>11,41===1</li><li>33===3</li><li>We will swap 41 &amp; 33</li></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p><strong>Advantages:&nbsp;</strong></p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>Most of the identifiers occupy their valid positions.&nbsp;</li><li>Searching becomes easier since only the synonyms are chained.&nbsp;</li></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p><strong>Disadvantages:&nbsp;</strong></p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>Insertions and deletions take more time.&nbsp;</li></ol>
<!-- /wp:list -->

<!-- wp:heading {"level":5} -->
<h5><strong><em>3.Chaining using linked lists</em></strong>:</h5>
<!-- /wp:heading -->

<!-- wp:image {"align":"right","sizeSlug":"large"} -->
<div class="wp-block-image"><figure class="alignright size-large"><img src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftse2.mm.bing.net%2Fth%3Fid%3DOIP.3_S5UuUOdPyF3o78iz_fvQHaG6%26pid%3DApi&amp;f=1" alt=""/></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>All of the above methods suffer from a variety of problems.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>Limited amount of space, due to which the table can become full.</li><li>&nbsp;The complexity of chaining which results in poor efficiency.<strong>&nbsp;</strong></li></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>Obviously the best method would be to have unlimited amount of space for each bucket so that we could put in as many identifiers as we want without any overflow taking place.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong><em>Advantages&nbsp;</em></strong></p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>Most efficient method to resolve collision.&nbsp;</li><li>There is no limit on the number of identifiers.&nbsp;</li><li>Searching, Insertion and Deletions are done efficiently.&nbsp;</li><li>The hash table will never be ‘full’.&nbsp;</li></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p><strong><em>Disadvantages</em></strong></p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>If many identifiers are put into a single list, searching time within a bucket will increase.</li><li>Handling of the pointer array and linked lists is more complex as compared to simple arrays.&nbsp;&nbsp;</li></ol>
<!-- /wp:list -->

<!-- wp:heading {"textAlign":"center","level":3} -->
<h3 class="has-text-align-center"><strong>EXTENDIBLE HASHING</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p><strong>Reason for Extendible hashing :</strong></p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>&nbsp;Most records have to be stored in disk</li><li>Disk read/write operations much more expensive than operations in main memory</li><li>Regular hash tables need to examine several disk blocks when collisions occur</li><li>We want to limit number of disk accesses for find/insert operations</li></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p><strong><em>Concept :</em></strong></p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>Retrieval to be performed in two disk accesses and Insertion also in&nbsp; few accesses.&nbsp;</li><li>This can be achieved by using a tree structure.&nbsp;</li><li>The tree is an M-ary tree (degree M) which allows M-way branching.&nbsp;</li><li>This means that as the branching increases, depth of the tree decreases.&nbsp;</li><li>A complete Binary tree has height (log<sub>2</sub>N) whereas a complete M-ary tree&nbsp; has height of (log <sub>M/2</sub> N). <strong>As M </strong>increases, the depth decreases.&nbsp;</li></ol>
<!-- /wp:list -->

<!-- wp:image {"sizeSlug":"large"} -->
<figure class="wp-block-image size-large"><img src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fhldingzydong.github.io%2Fimg%2FDataBase%2FExtendibleHashing.jpeg&amp;f=1&amp;nofb=1" alt=""/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p><strong><em>Procedure:</em></strong></p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>Hash the key of each record into a reasonably long integer to avoid collision</li><li>Adding 0’s to the left so they have the same length</li><li>Build a directory</li><li>The directory is stored in the primary memory</li><li>Each entry in the directory points to a leaf&nbsp;</li><li>Directory is extensible</li><li>Each leaf contains M records,&nbsp;</li><li>Stored in one disk block&nbsp;&nbsp;</li><li>Share the same D number of leading digits</li></ol>
<!-- /wp:list -->

<!-- wp:heading {"level":5} -->
<h5><em>For more information on hashing, </em></h5>
<!-- /wp:heading -->

<!-- wp:list {"ordered":true} -->
<ol><li><a rel="noreferrer noopener" href="http://cse.uaa.alaska.edu/~afkjm/csce311/fall2018/handouts/hashing-drozdek.pdf" target="_blank">http://cse.uaa.alaska.edu/~afkjm/csce311/fall2018/handouts/hashing-drozdek.pdf</a></li><li><a href="https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-006-introduction-to-algorithms-fall-2011/lecture-videos/MIT6_006F11_lec08.pdf" target="_blank" rel="noreferrer noopener">https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-006-introduction-to-algorithms-fall-2011/lecture-videos/MIT6_006F11_lec08.pdf</a></li></ol>
<!-- /wp:list -->

<!-- wp:list {"ordered":true} -->
<ol><li><strong><em>GitHub Repository for code: <a rel="noreferrer noopener" href="https://github.com/kakabisht/Data-structures" target="_blank">https://github.com/kakabisht/Data-structures</a></em></strong></li><li><a href="https://programmerprodigy.code.blog/2020/04/10/encryption-and-decryption/" target="_blank" rel="noreferrer noopener">https://programmerprodigy.code.blog/2020/04/10/encryption-and-decryption/</a></li></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->