{"id":3192,"date":"2025-06-06T02:37:05","date_gmt":"2025-06-06T02:37:05","guid":{"rendered":"https:\/\/diznr.com\/?p=3192"},"modified":"2025-06-06T02:37:05","modified_gmt":"2025-06-06T02:37:05","slug":"gate-cseit-database-hashing-introduction-with-hashing-function-and-table-hashing","status":"publish","type":"post","link":"https:\/\/www.reilsolar.com\/pdf\/gate-cseit-database-hashing-introduction-with-hashing-function-and-table-hashing\/","title":{"rendered":"GATE CSEIT\/Database\/ Hashing introduction with hashing function and hashing table"},"content":{"rendered":"<p>GATE CSEIT\/Database\/ Hashing introduction with hashing function and hashing table<\/p>\n<p>[fvplayer id=&#8221;293&#8243;]<\/p>\n<h3 data-start=\"0\" data-end=\"45\"><strong data-start=\"2\" data-end=\"43\">\u00a0Hashing in Databases \u2013 GATE CSE\/IT<\/strong><\/h3>\n<h3 data-start=\"47\" data-end=\"75\"><strong data-start=\"50\" data-end=\"73\">\u00a0What is Hashing?<\/strong><\/h3>\n<p data-start=\"76\" data-end=\"277\">Hashing is a technique used in <strong data-start=\"107\" data-end=\"151\">databases, data structures, and indexing<\/strong> to store and retrieve data efficiently. It uses a <strong data-start=\"202\" data-end=\"219\">hash function<\/strong> to map keys to a specific location in a <strong data-start=\"260\" data-end=\"274\">hash table<\/strong>.<\/p>\n<p data-start=\"279\" data-end=\"311\"><strong data-start=\"281\" data-end=\"309\">Key Benefits of Hashing:<\/strong><\/p>\n<ul data-start=\"312\" data-end=\"560\">\n<li data-start=\"312\" data-end=\"380\"><strong data-start=\"314\" data-end=\"337\">Fast data retrieval<\/strong> \u2013 O(1) time complexity in the best case.<\/li>\n<li data-start=\"381\" data-end=\"472\"><strong data-start=\"383\" data-end=\"404\">Efficient storage<\/strong> \u2013 Reduces search time compared to linear search or binary search.<\/li>\n<li data-start=\"473\" data-end=\"560\"><strong data-start=\"475\" data-end=\"500\">Indexing in databases<\/strong> \u2013 Used in <strong data-start=\"511\" data-end=\"557\">B-Trees, hash indexes, and NoSQL databases<\/strong>.<\/li>\n<\/ul>\n<h3 data-start=\"567\" data-end=\"595\"><strong data-start=\"570\" data-end=\"593\">\u00a0Hashing Function<\/strong><\/h3>\n<p data-start=\"597\" data-end=\"699\">A <strong data-start=\"599\" data-end=\"616\">hash function<\/strong> is a mathematical function that converts a key into a unique index (hash value).<\/p>\n<p data-start=\"701\" data-end=\"736\"><strong data-start=\"704\" data-end=\"734\">Formula for Hash Function:<\/strong><\/p>\n<p><span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\">h(K)=Kmod\u2009\u2009Mh(K) = K \\mod M<\/span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"mord mathnormal\">h<\/span><span class=\"mopen\">(<\/span><span class=\"mord mathnormal\">K<\/span><span class=\"mclose\">)<\/span><span class=\"mrel\">=<\/span><\/span><span class=\"base\"><span class=\"mord mathnormal\">K<\/span><\/span><span class=\"base\"><span class=\"mord\"><span class=\"mord mathrm\">mod<\/span><\/span><span class=\"mord mathnormal\">M<\/span><\/span><\/span><\/span><\/span><\/p>\n<p data-start=\"761\" data-end=\"769\">where:<\/p>\n<ul data-start=\"770\" data-end=\"848\">\n<li data-start=\"770\" data-end=\"785\"><strong data-start=\"772\" data-end=\"777\">K<\/strong> = Key<\/li>\n<li data-start=\"786\" data-end=\"848\"><strong data-start=\"788\" data-end=\"793\">M<\/strong> = Size of the hash table (number of available slots)<\/li>\n<\/ul>\n<h3 data-start=\"850\" data-end=\"868\"><strong data-start=\"854\" data-end=\"866\">Example:<\/strong><\/h3>\n<p data-start=\"869\" data-end=\"957\">If we insert the key <strong data-start=\"890\" data-end=\"896\">25<\/strong> into a hash table of size <strong data-start=\"923\" data-end=\"929\">10<\/strong>, using <code data-start=\"937\" data-end=\"954\">h(K) = K mod 10<\/code>:<\/p>\n<p><span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\">h(25)=25mod\u2009\u200910=5h(25) = 25 \\mod 10 = 5<\/span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"mord mathnormal\">h<\/span><span class=\"mopen\">(<\/span><span class=\"mord\">25<\/span><span class=\"mclose\">)<\/span><span class=\"mrel\">=<\/span><\/span><span class=\"base\"><span class=\"mord\">25<\/span><\/span><span class=\"base\"><span class=\"mord\"><span class=\"mord mathrm\">mod<\/span><\/span><span class=\"mord\">10<\/span><span class=\"mrel\">=<\/span><\/span><span class=\"base\"><span class=\"mord\">5<\/span><\/span><\/span><\/span><\/span><\/p>\n<p data-start=\"989\" data-end=\"1041\">So, <strong data-start=\"993\" data-end=\"1020\">25 is stored at index 5<\/strong> in the hash table.<\/p>\n<p data-start=\"1043\" data-end=\"1179\"><strong data-start=\"1045\" data-end=\"1076\">Good Hash Functions Should:<\/strong><br data-start=\"1076\" data-end=\"1079\" \/>\u00a0Be fast to compute.<br data-start=\"1100\" data-end=\"1103\" \/>\u00a0Distribute keys <strong data-start=\"1121\" data-end=\"1134\">uniformly<\/strong> across the table.<br data-start=\"1152\" data-end=\"1155\" \/>\u00a0Minimize collisions.<\/p>\n<h3 data-start=\"1186\" data-end=\"1208\"><strong data-start=\"1189\" data-end=\"1206\">\u00a0Hash Table<\/strong><\/h3>\n<p data-start=\"1210\" data-end=\"1315\">A <strong data-start=\"1212\" data-end=\"1226\">hash table<\/strong> is a data structure that stores <strong data-start=\"1259\" data-end=\"1278\">key-value pairs<\/strong> and uses hashing for fast lookups.<\/p>\n<p data-start=\"1317\" data-end=\"1543\"><strong data-start=\"1319\" data-end=\"1350\">Operations on a Hash Table:<\/strong><br data-start=\"1350\" data-end=\"1353\" \/><strong data-start=\"1357\" data-end=\"1370\">Insertion<\/strong> \u2013 Store data at the index calculated by the hash function.<br data-start=\"1429\" data-end=\"1432\" \/><strong data-start=\"1436\" data-end=\"1446\">Search<\/strong> \u2013 Retrieve data using the hash function.<br data-start=\"1487\" data-end=\"1490\" \/><strong data-start=\"1494\" data-end=\"1506\">Deletion<\/strong> \u2013 Remove data from the hash table.<\/p>\n<h3 data-start=\"1545\" data-end=\"1591\"><strong data-start=\"1549\" data-end=\"1589\">Example of a Hash Table (Size = 10):<\/strong><\/h3>\n<div class=\"overflow-x-auto contain-inline-size\">\n<table data-start=\"1592\" data-end=\"1743\">\n<thead data-start=\"1592\" data-end=\"1614\">\n<tr data-start=\"1592\" data-end=\"1614\">\n<th data-start=\"1592\" data-end=\"1600\">Index<\/th>\n<th data-start=\"1600\" data-end=\"1614\">Key Stored<\/th>\n<\/tr>\n<\/thead>\n<tbody data-start=\"1639\" data-end=\"1743\">\n<tr data-start=\"1639\" data-end=\"1648\">\n<td>0<\/td>\n<td>&#8211;<\/td>\n<\/tr>\n<tr data-start=\"1649\" data-end=\"1658\">\n<td>1<\/td>\n<td>&#8211;<\/td>\n<\/tr>\n<tr data-start=\"1659\" data-end=\"1669\">\n<td>2<\/td>\n<td>32<\/td>\n<\/tr>\n<tr data-start=\"1670\" data-end=\"1680\">\n<td>3<\/td>\n<td>23<\/td>\n<\/tr>\n<tr data-start=\"1681\" data-end=\"1691\">\n<td>4<\/td>\n<td>44<\/td>\n<\/tr>\n<tr data-start=\"1692\" data-end=\"1702\">\n<td>5<\/td>\n<td>25<\/td>\n<\/tr>\n<tr data-start=\"1703\" data-end=\"1712\">\n<td>6<\/td>\n<td>&#8211;<\/td>\n<\/tr>\n<tr data-start=\"1713\" data-end=\"1722\">\n<td>7<\/td>\n<td>&#8211;<\/td>\n<\/tr>\n<tr data-start=\"1723\" data-end=\"1732\">\n<td>8<\/td>\n<td>&#8211;<\/td>\n<\/tr>\n<tr data-start=\"1733\" data-end=\"1743\">\n<td>9<\/td>\n<td>39<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p data-start=\"1745\" data-end=\"1870\">\u00a0If we need to search for key <strong data-start=\"1777\" data-end=\"1783\">25<\/strong>, we compute <code data-start=\"1796\" data-end=\"1807\">h(25) = 5<\/code>, and directly access <strong data-start=\"1829\" data-end=\"1840\">index 5<\/strong> \u2192 <strong data-start=\"1843\" data-end=\"1867\">O(1) time complexity<\/strong>.<\/p>\n<h3 data-start=\"1877\" data-end=\"1912\"><strong data-start=\"1880\" data-end=\"1910\">\u00a0Types of Hash Functions<\/strong><\/h3>\n<p data-start=\"1914\" data-end=\"1956\"><strong data-start=\"1916\" data-end=\"1954\">1. Division Method (Modulo Method)<\/strong><\/p>\n<p><span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\">h(K)=Kmod\u2009\u2009Mh(K) = K \\mod M<\/span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"mord mathnormal\">h<\/span><span class=\"mopen\">(<\/span><span class=\"mord mathnormal\">K<\/span><span class=\"mclose\">)<\/span><span class=\"mrel\">=<\/span><\/span><span class=\"base\"><span class=\"mord mathnormal\">K<\/span><\/span><span class=\"base\"><span class=\"mord\"><span class=\"mord mathrm\">mod<\/span><\/span><span class=\"mord mathnormal\">M<\/span><\/span><\/span><\/span><\/span><\/p>\n<p data-start=\"1981\" data-end=\"2067\">\u00a0Simple and commonly used.<br data-start=\"2008\" data-end=\"2011\" \/>\u00a0M should be <strong data-start=\"2025\" data-end=\"2043\">a prime number<\/strong> to reduce collisions.<\/p>\n<p data-start=\"2069\" data-end=\"2101\"><strong data-start=\"2071\" data-end=\"2099\">2. Multiplication Method<\/strong><\/p>\n<p><span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\">h(K)=\u230aM(K\u00d7Amod\u2009\u20091)\u230bh(K) = \\lfloor M (K \\times A \\mod 1) \\rfloor<\/span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"mord mathnormal\">h<\/span><span class=\"mopen\">(<\/span><span class=\"mord mathnormal\">K<\/span><span class=\"mclose\">)<\/span><span class=\"mrel\">=<\/span><\/span><span class=\"base\"><span class=\"mopen\">\u230a<\/span><span class=\"mord mathnormal\">M<\/span><span class=\"mopen\">(<\/span><span class=\"mord mathnormal\">K<\/span><span class=\"mbin\">\u00d7<\/span><\/span><span class=\"base\"><span class=\"mord mathnormal\">A<\/span><\/span><span class=\"base\"><span class=\"mord\"><span class=\"mord mathrm\">mod<\/span><\/span><span class=\"mord\">1<\/span><span class=\"mclose\">)\u230b<\/span><\/span><\/span><\/span><\/span><\/p>\n<p data-start=\"2155\" data-end=\"2254\">where <code data-start=\"2161\" data-end=\"2164\">A<\/code> is a fractional constant (e.g., <strong data-start=\"2197\" data-end=\"2206\">0.618<\/strong>).<br data-start=\"2208\" data-end=\"2211\" \/>\u00a0Works well with power-of-2 table sizes.<\/p>\n<p data-start=\"2256\" data-end=\"2365\"><strong data-start=\"2258\" data-end=\"2279\">3. Folding Method<\/strong><br data-start=\"2279\" data-end=\"2282\" \/>\u00a0Splits key into parts, applies arithmetic operations, and combines the results.<\/p>\n<p data-start=\"2367\" data-end=\"2461\"><strong data-start=\"2369\" data-end=\"2393\">4. Mid-Square Method<\/strong><br data-start=\"2393\" data-end=\"2396\" \/>\u00a0Squares the key and extracts middle digits as the hash value.<\/p>\n<p data-start=\"2463\" data-end=\"2559\"><strong data-start=\"2465\" data-end=\"2489\">5. Universal Hashing<\/strong><br data-start=\"2489\" data-end=\"2492\" \/>\u00a0Uses <strong data-start=\"2499\" data-end=\"2533\">randomly chosen hash functions<\/strong> to minimize collisions.<\/p>\n<h3 data-start=\"2566\" data-end=\"2598\"><strong data-start=\"2569\" data-end=\"2596\">\u00a0Collision in Hashing<\/strong><\/h3>\n<p data-start=\"2600\" data-end=\"2728\"><strong data-start=\"2603\" data-end=\"2627\">What is a Collision?<\/strong><br data-start=\"2627\" data-end=\"2630\" \/>A <strong data-start=\"2632\" data-end=\"2645\">collision<\/strong> occurs when <strong data-start=\"2658\" data-end=\"2680\">two different keys<\/strong> hash to the <strong data-start=\"2693\" data-end=\"2707\">same index<\/strong> in the hash table.<\/p>\n<p data-start=\"2730\" data-end=\"2860\">Example:<br data-start=\"2738\" data-end=\"2741\" \/>For <code data-start=\"2745\" data-end=\"2753\">M = 10<\/code>, if keys <strong data-start=\"2763\" data-end=\"2769\">25<\/strong> and <strong data-start=\"2774\" data-end=\"2780\">35<\/strong> both hash to <strong data-start=\"2794\" data-end=\"2805\">index 5<\/strong> (<code data-start=\"2807\" data-end=\"2818\">h(25) = 5<\/code>, <code data-start=\"2820\" data-end=\"2831\">h(35) = 5<\/code>), we have a <strong data-start=\"2844\" data-end=\"2857\">collision<\/strong>.<\/p>\n<p data-start=\"2862\" data-end=\"3023\"><strong data-start=\"2864\" data-end=\"2898\">Collision Handling Techniques:<\/strong><br data-start=\"2898\" data-end=\"2901\" \/><strong data-start=\"2903\" data-end=\"2922\">Open Addressing<\/strong> (Linear Probing, Quadratic Probing, Double Hashing)<br data-start=\"2974\" data-end=\"2977\" \/><strong data-start=\"2979\" data-end=\"3000\">Separate Chaining<\/strong> (Using Linked Lists)<\/p>\n<h3 data-start=\"3030\" data-end=\"3095\"><strong data-start=\"3033\" data-end=\"3093\">\u00a0Example GATE Question (Hashing Function &amp; Hash Table)<\/strong><\/h3>\n<p data-start=\"3097\" data-end=\"3245\"><strong data-start=\"3097\" data-end=\"3110\">Question:<\/strong> A hash function is defined as <code data-start=\"3141\" data-end=\"3157\">h(K) = K mod 7<\/code>. Given keys <strong data-start=\"3170\" data-end=\"3197\">50, 700, 76, 85, 92, 73<\/strong>, insert them into a hash table of size <strong data-start=\"3237\" data-end=\"3242\">7<\/strong>.<\/p>\n<p data-start=\"3247\" data-end=\"3292\"><strong data-start=\"3247\" data-end=\"3260\">Solution:<\/strong><br data-start=\"3260\" data-end=\"3263\" \/>\u00a0Compute the hash values.<\/p>\n<div class=\"overflow-x-auto contain-inline-size\">\n<table data-start=\"3294\" data-end=\"3679\">\n<thead data-start=\"3294\" data-end=\"3345\">\n<tr data-start=\"3294\" data-end=\"3345\">\n<th data-start=\"3294\" data-end=\"3300\">Key<\/th>\n<th data-start=\"3300\" data-end=\"3332\">Hash Value (<code data-start=\"3314\" data-end=\"3330\">h(K) = K mod 7<\/code>)<\/th>\n<th data-start=\"3332\" data-end=\"3345\">Placement<\/th>\n<\/tr>\n<\/thead>\n<tbody data-start=\"3382\" data-end=\"3679\">\n<tr data-start=\"3382\" data-end=\"3418\">\n<td>50<\/td>\n<td><code data-start=\"3389\" data-end=\"3403\">50 mod 7 = 1<\/code><\/td>\n<td>Slot <strong data-start=\"3411\" data-end=\"3416\">1<\/strong><\/td>\n<\/tr>\n<tr data-start=\"3419\" data-end=\"3457\">\n<td>700<\/td>\n<td><code data-start=\"3427\" data-end=\"3442\">700 mod 7 = 0<\/code><\/td>\n<td>Slot <strong data-start=\"3450\" data-end=\"3455\">0<\/strong><\/td>\n<\/tr>\n<tr data-start=\"3458\" data-end=\"3494\">\n<td>76<\/td>\n<td><code data-start=\"3465\" data-end=\"3479\">76 mod 7 = 6<\/code><\/td>\n<td>Slot <strong data-start=\"3487\" data-end=\"3492\">6<\/strong><\/td>\n<\/tr>\n<tr data-start=\"3495\" data-end=\"3568\">\n<td>85<\/td>\n<td><code data-start=\"3502\" data-end=\"3516\">85 mod 7 = 1<\/code><\/td>\n<td><strong data-start=\"3519\" data-end=\"3532\">Collision<\/strong> (Use Linear Probing) \u2192 Slot <strong data-start=\"3561\" data-end=\"3566\">2<\/strong><\/td>\n<\/tr>\n<tr data-start=\"3569\" data-end=\"3642\">\n<td>92<\/td>\n<td><code data-start=\"3576\" data-end=\"3590\">92 mod 7 = 1<\/code><\/td>\n<td><strong data-start=\"3593\" data-end=\"3606\">Collision<\/strong> (Use Linear Probing) \u2192 Slot <strong data-start=\"3635\" data-end=\"3640\">3<\/strong><\/td>\n<\/tr>\n<tr data-start=\"3643\" data-end=\"3679\">\n<td>73<\/td>\n<td><code data-start=\"3650\" data-end=\"3664\">73 mod 7 = 3<\/code><\/td>\n<td>Slot <strong data-start=\"3672\" data-end=\"3677\">4<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p data-start=\"3681\" data-end=\"3729\"><strong data-start=\"3683\" data-end=\"3727\">Final Hash Table (Using Linear Probing):<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre\"><span class=\"hljs-section\">Index:  0   1   2   3   4   5   6  <\/span><br \/>\n<span class=\"hljs-section\">Keys:  700  50  85  92  73  -   76  <\/span><br \/>\n<\/code><\/div>\n<\/div>\n<h3 data-start=\"3817\" data-end=\"3836\"><strong data-start=\"3820\" data-end=\"3834\">\u00a0Summary<\/strong><\/h3>\n<p data-start=\"3838\" data-end=\"4231\"><strong data-start=\"3840\" data-end=\"3851\">Hashing<\/strong> is a technique for <strong data-start=\"3871\" data-end=\"3911\">efficient data storage and retrieval<\/strong>.<br data-start=\"3912\" data-end=\"3915\" \/><strong data-start=\"3917\" data-end=\"3935\">Hash functions<\/strong> map keys to hash values.<br data-start=\"3960\" data-end=\"3963\" \/><strong data-start=\"3965\" data-end=\"3979\">Collisions<\/strong> occur when multiple keys map to the <strong data-start=\"4016\" data-end=\"4030\">same index<\/strong>.<br data-start=\"4031\" data-end=\"4034\" \/><strong data-start=\"4036\" data-end=\"4069\">Collision handling techniques<\/strong> (Open Addressing &amp; Separate Chaining) prevent data loss.<br data-start=\"4126\" data-end=\"4129\" \/><strong data-start=\"4131\" data-end=\"4156\">Common GATE questions<\/strong> test hashing functions, collision resolution, and hash table operations.<\/p>\n<p data-start=\"4233\" data-end=\"4309\" data-is-last-node=\"\" data-is-only-node=\"\">\u00a0<strong data-start=\"4236\" data-end=\"4293\">Need more GATE practice questions or coding examples?<\/strong> Let me know!<\/p>\n<h3 data-start=\"4233\" data-end=\"4309\"><a href=\"https:\/\/gatecse.in\/w\/images\/4\/4c\/Hashng.pdf\" target=\"_blank\" rel=\"noopener\">GATE CSEIT\/Database\/ Hashing introduction with hashing function and hashing table<\/a><\/h3>\n<h3 class=\"LC20lb MBeuO DKV0Md\"><a href=\"https:\/\/web.suffieldacademy.org\/cs\/ap\/assignments\/bhadra-mahler-introduction_to_hashing.pdf\" target=\"_blank\" rel=\"noopener\">Introduction to Hash Table and Hash Function<\/a><\/h3>\n<h3 class=\"LC20lb MBeuO DKV0Md\"><a href=\"https:\/\/www.kdkce.edu.in\/pdf\/YDC-4IT-ADS-Hashing%20Techniques.pdf\" target=\"_blank\" rel=\"noopener\">Hashing in Data Structure<\/a><\/h3>\n<p data-start=\"0\" data-end=\"87\">Here&#8217;s a focused introduction to <strong data-start=\"33\" data-end=\"44\">Hashing<\/strong> for <strong data-start=\"49\" data-end=\"76\">GATE CSE\/IT \u2013 Databases<\/strong>, covering:<\/p>\n<ul data-start=\"89\" data-end=\"215\">\n<li data-start=\"89\" data-end=\"108\">\n<p data-start=\"91\" data-end=\"108\">What hashing is<\/p>\n<\/li>\n<li data-start=\"109\" data-end=\"127\">\n<p data-start=\"111\" data-end=\"127\">Hash functions<\/p>\n<\/li>\n<li data-start=\"128\" data-end=\"143\">\n<p data-start=\"130\" data-end=\"143\">Hash tables<\/p>\n<\/li>\n<li data-start=\"144\" data-end=\"193\">\n<p data-start=\"146\" data-end=\"193\">Types of collisions and resolution techniques<\/p>\n<\/li>\n<li data-start=\"194\" data-end=\"215\">\n<p data-start=\"196\" data-end=\"215\">Key points for GATE<\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"217\" data-end=\"220\" \/>\n<h2 data-start=\"222\" data-end=\"251\">\ud83d\udd10 Introduction to Hashing<\/h2>\n<p data-start=\"253\" data-end=\"373\"><strong data-start=\"253\" data-end=\"264\">Hashing<\/strong> is a technique used to <strong data-start=\"288\" data-end=\"307\">map data (keys)<\/strong> to a <strong data-start=\"313\" data-end=\"346\">fixed-size table (hash table)<\/strong> using a <strong data-start=\"355\" data-end=\"372\">hash function<\/strong>.<\/p>\n<h3 data-start=\"375\" data-end=\"390\">\ud83c\udfaf Purpose:<\/h3>\n<p data-start=\"391\" data-end=\"471\">To support <strong data-start=\"402\" data-end=\"430\">efficient data retrieval<\/strong> in average <strong data-start=\"442\" data-end=\"455\">O(1) time<\/strong>, especially in:<\/p>\n<ul data-start=\"472\" data-end=\"545\">\n<li data-start=\"472\" data-end=\"486\">\n<p data-start=\"474\" data-end=\"486\"><strong data-start=\"474\" data-end=\"486\">Indexing<\/strong><\/p>\n<\/li>\n<li data-start=\"487\" data-end=\"506\">\n<p data-start=\"489\" data-end=\"506\"><strong data-start=\"489\" data-end=\"506\">Symbol tables<\/strong><\/p>\n<\/li>\n<li data-start=\"507\" data-end=\"522\">\n<p data-start=\"509\" data-end=\"522\"><strong data-start=\"509\" data-end=\"522\">Databases<\/strong><\/p>\n<\/li>\n<li data-start=\"523\" data-end=\"545\">\n<p data-start=\"525\" data-end=\"545\"><strong data-start=\"525\" data-end=\"545\">Hash-based joins<\/strong><\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"547\" data-end=\"550\" \/>\n<h2 data-start=\"552\" data-end=\"571\">\ud83e\udde0 Hash Function<\/h2>\n<p data-start=\"573\" data-end=\"640\">A <strong data-start=\"575\" data-end=\"596\">hash function (h)<\/strong> maps a key <code data-start=\"608\" data-end=\"611\">k<\/code> to an index in a hash table:<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none rounded-t-[5px]\">scss<\/div>\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-sidebar-surface-primary text-token-text-secondary dark:bg-token-main-surface-secondary flex items-center rounded-sm px-2 font-sans text-xs\"><button class=\"flex gap-1 items-center select-none px-4 py-1\" aria-label=\"Copy\">Copy<\/button><span class=\"\" data-state=\"closed\"><button class=\"flex items-center gap-1 px-4 py-1 select-none\">Edit<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre!\"><span class=\"hljs-built_in\">h<\/span>(k) \u2192 index (<span class=\"hljs-number\">0<\/span> to m\u2212<span class=\"hljs-number\">1<\/span>)<br \/>\n<\/code><\/div>\n<\/div>\n<p data-start=\"675\" data-end=\"681\">Where:<\/p>\n<ul data-start=\"682\" data-end=\"759\">\n<li data-start=\"682\" data-end=\"692\">\n<p data-start=\"684\" data-end=\"692\"><code data-start=\"684\" data-end=\"687\">k<\/code>: key<\/p>\n<\/li>\n<li data-start=\"693\" data-end=\"729\">\n<p data-start=\"695\" data-end=\"729\"><code data-start=\"695\" data-end=\"701\">h(k)<\/code>: hash value (bucket number)<\/p>\n<\/li>\n<li data-start=\"730\" data-end=\"759\">\n<p data-start=\"732\" data-end=\"759\"><code data-start=\"732\" data-end=\"735\">m<\/code>: size of the hash table<\/p>\n<\/li>\n<\/ul>\n<h3 data-start=\"761\" data-end=\"787\">Common Hash Functions:<\/h3>\n<ol data-start=\"789\" data-end=\"1153\">\n<li data-start=\"789\" data-end=\"897\">\n<p data-start=\"792\" data-end=\"897\"><strong data-start=\"792\" data-end=\"811\">Division Method<\/strong><br data-start=\"811\" data-end=\"814\" \/><code data-start=\"817\" data-end=\"837\">h(k) = k mod m<\/code><br data-start=\"837\" data-end=\"840\" \/><code data-start=\"843\" data-end=\"846\">m<\/code> should be a <strong data-start=\"859\" data-end=\"875\">prime number<\/strong> to reduce collisions.<\/p>\n<\/li>\n<li data-start=\"899\" data-end=\"1018\">\n<p data-start=\"902\" data-end=\"972\"><strong data-start=\"902\" data-end=\"927\">Multiplication Method<\/strong><br data-start=\"927\" data-end=\"930\" \/><code data-start=\"933\" data-end=\"970\">h(k) = floor(m * (k * A mod 1))<\/code><\/p>\n<ul data-start=\"976\" data-end=\"1018\">\n<li data-start=\"976\" data-end=\"1018\">\n<p data-start=\"978\" data-end=\"1018\"><code data-start=\"978\" data-end=\"981\">A<\/code>: constant (0 &lt; A &lt; 1), often \u2248 0.618<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li data-start=\"1020\" data-end=\"1090\">\n<p data-start=\"1023\" data-end=\"1046\"><strong data-start=\"1023\" data-end=\"1044\">Mid-Square Method<\/strong><\/p>\n<ul data-start=\"1050\" data-end=\"1090\">\n<li data-start=\"1050\" data-end=\"1090\">\n<p data-start=\"1052\" data-end=\"1090\">Square the key and take middle digits.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li data-start=\"1092\" data-end=\"1153\">\n<p data-start=\"1095\" data-end=\"1115\"><strong data-start=\"1095\" data-end=\"1113\">Folding Method<\/strong><\/p>\n<ul data-start=\"1119\" data-end=\"1153\">\n<li data-start=\"1119\" data-end=\"1153\">\n<p data-start=\"1121\" data-end=\"1153\">Divide key into parts, add them.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<hr data-start=\"1155\" data-end=\"1158\" \/>\n<h2 data-start=\"1160\" data-end=\"1176\">\ud83d\udce6 Hash Table<\/h2>\n<p data-start=\"1178\" data-end=\"1233\">A <strong data-start=\"1180\" data-end=\"1194\">hash table<\/strong> is an array-like data structure where:<\/p>\n<ul data-start=\"1234\" data-end=\"1309\">\n<li data-start=\"1234\" data-end=\"1262\">\n<p data-start=\"1236\" data-end=\"1262\">Each index is a <strong data-start=\"1252\" data-end=\"1262\">bucket<\/strong><\/p>\n<\/li>\n<li data-start=\"1263\" data-end=\"1309\">\n<p data-start=\"1265\" data-end=\"1309\">Buckets can store keys or (key, value) pairs<\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"1311\" data-end=\"1314\" \/>\n<h2 data-start=\"1316\" data-end=\"1332\">\u26a0\ufe0f Collisions<\/h2>\n<p data-start=\"1334\" data-end=\"1375\">When two keys hash to the <strong data-start=\"1360\" data-end=\"1374\">same index<\/strong>:<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none rounded-t-[5px]\"><\/div>\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-sidebar-surface-primary text-token-text-secondary dark:bg-token-main-surface-secondary flex items-center rounded-sm px-2 font-sans text-xs\"><button class=\"flex gap-1 items-center select-none px-4 py-1\" aria-label=\"Copy\">Copy<\/button><span class=\"\" data-state=\"closed\"><button class=\"flex items-center gap-1 px-4 py-1 select-none\">Edit<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre!\">h(k1) = h(k2), but k1 \u2260 k2<br \/>\n<\/code><\/div>\n<\/div>\n<h3 data-start=\"1412\" data-end=\"1452\">\ud83d\udee0\ufe0f Collision Resolution Techniques:<\/h3>\n<h4 data-start=\"1454\" data-end=\"1491\">1. <strong data-start=\"1462\" data-end=\"1489\">Open Hashing (Chaining)<\/strong><\/h4>\n<ul data-start=\"1492\" data-end=\"1583\">\n<li data-start=\"1492\" data-end=\"1538\">\n<p data-start=\"1494\" data-end=\"1538\">Each bucket holds a <strong data-start=\"1514\" data-end=\"1529\">linked list<\/strong> of keys.<\/p>\n<\/li>\n<li data-start=\"1539\" data-end=\"1583\">\n<p data-start=\"1541\" data-end=\"1583\">Multiple keys can go into the same bucket.<\/p>\n<\/li>\n<\/ul>\n<h4 data-start=\"1585\" data-end=\"1631\">2. <strong data-start=\"1593\" data-end=\"1629\">Closed Hashing (Open Addressing)<\/strong><\/h4>\n<ul data-start=\"1632\" data-end=\"1737\">\n<li data-start=\"1632\" data-end=\"1686\">\n<p data-start=\"1634\" data-end=\"1686\">All elements are stored <strong data-start=\"1658\" data-end=\"1685\">within the table itself<\/strong>.<\/p>\n<\/li>\n<li data-start=\"1687\" data-end=\"1737\">\n<p data-start=\"1689\" data-end=\"1737\">If a collision happens, find the next free slot.<\/p>\n<\/li>\n<\/ul>\n<p data-start=\"1739\" data-end=\"1767\"><strong data-start=\"1739\" data-end=\"1766\">Open Addressing Methods<\/strong>:<\/p>\n<ul data-start=\"1768\" data-end=\"1967\">\n<li data-start=\"1768\" data-end=\"1826\">\n<p data-start=\"1770\" data-end=\"1826\"><strong data-start=\"1770\" data-end=\"1788\">Linear Probing<\/strong>:<br data-start=\"1789\" data-end=\"1792\" \/><code data-start=\"1794\" data-end=\"1826\">h(k, i) = (h(k) + i) mod m<\/code><\/p>\n<\/li>\n<li data-start=\"1827\" data-end=\"1899\">\n<p data-start=\"1829\" data-end=\"1899\"><strong data-start=\"1829\" data-end=\"1850\">Quadratic Probing<\/strong>:<br data-start=\"1851\" data-end=\"1854\" \/><code data-start=\"1856\" data-end=\"1899\">h(k, i) = (h(k) + c1*i + c2*i\u00b2) mod m<\/code><\/p>\n<\/li>\n<li data-start=\"1900\" data-end=\"1967\">\n<p data-start=\"1902\" data-end=\"1967\"><strong data-start=\"1902\" data-end=\"1920\">Double Hashing<\/strong>:<br data-start=\"1921\" data-end=\"1924\" \/><code data-start=\"1926\" data-end=\"1967\">h(k, i) = (h1(k) + i * h2(k)) mod m<\/code><\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"1969\" data-end=\"1972\" \/>\n<h2 data-start=\"1974\" data-end=\"2002\">\ud83d\udcd8 GATE Concepts and Tips<\/h2>\n<ul data-start=\"2004\" data-end=\"2326\">\n<li data-start=\"2004\" data-end=\"2132\">\n<p data-start=\"2006\" data-end=\"2132\"><strong data-start=\"2006\" data-end=\"2025\">Load Factor (\u03b1)<\/strong>:<br data-start=\"2026\" data-end=\"2029\" \/><code data-start=\"2031\" data-end=\"2046\">\u03b1 = n \/ m<\/code><br data-start=\"2046\" data-end=\"2049\" \/>Where <code data-start=\"2057\" data-end=\"2077\">n = number of keys<\/code>, <code data-start=\"2079\" data-end=\"2095\">m = table size<\/code><br data-start=\"2095\" data-end=\"2098\" \/>Affects performance; ideal \u03b1 &lt; 1<\/p>\n<\/li>\n<li data-start=\"2134\" data-end=\"2248\">\n<p data-start=\"2136\" data-end=\"2169\">Understand <strong data-start=\"2147\" data-end=\"2168\">time complexities<\/strong>:<\/p>\n<ul data-start=\"2172\" data-end=\"2248\">\n<li data-start=\"2172\" data-end=\"2203\">\n<p data-start=\"2174\" data-end=\"2203\">Average case search: <strong data-start=\"2195\" data-end=\"2203\">O(1)<\/strong><\/p>\n<\/li>\n<li data-start=\"2206\" data-end=\"2248\">\n<p data-start=\"2208\" data-end=\"2248\">Worst case (due to collisions): <strong data-start=\"2240\" data-end=\"2248\">O(n)<\/strong><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li data-start=\"2250\" data-end=\"2326\">\n<p data-start=\"2252\" data-end=\"2326\">Know how <strong data-start=\"2261\" data-end=\"2275\">hash joins<\/strong> work in DBMS (especially in GATE-level questions).<\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"2328\" data-end=\"2331\" \/>\n<h2 data-start=\"2333\" data-end=\"2345\">\u2705 Example<\/h2>\n<p data-start=\"2347\" data-end=\"2353\">Given:<\/p>\n<ul data-start=\"2354\" data-end=\"2434\">\n<li data-start=\"2354\" data-end=\"2378\">\n<p data-start=\"2356\" data-end=\"2378\">Keys: <code data-start=\"2362\" data-end=\"2378\">23, 43, 13, 27<\/code><\/p>\n<\/li>\n<li data-start=\"2379\" data-end=\"2400\">\n<p data-start=\"2381\" data-end=\"2400\">Table size: <code data-start=\"2393\" data-end=\"2400\">m = 7<\/code><\/p>\n<\/li>\n<li data-start=\"2401\" data-end=\"2434\">\n<p data-start=\"2403\" data-end=\"2434\">Hash function: <code data-start=\"2418\" data-end=\"2434\">h(k) = k mod 7<\/code><\/p>\n<\/li>\n<\/ul>\n<p data-start=\"2436\" data-end=\"2448\">Hash values:<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none rounded-t-[5px]\">csharp<\/div>\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-sidebar-surface-primary text-token-text-secondary dark:bg-token-main-surface-secondary flex items-center rounded-sm px-2 font-sans text-xs\"><button class=\"flex gap-1 items-center select-none px-4 py-1\" aria-label=\"Copy\">Copy<\/button><span class=\"\" data-state=\"closed\"><button class=\"flex items-center gap-1 px-4 py-1 select-none\">Edit<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre!\">h(<span class=\"hljs-number\">23<\/span>) = <span class=\"hljs-number\">2<\/span><br \/>\nh(<span class=\"hljs-number\">43<\/span>) = <span class=\"hljs-number\">1<\/span><br \/>\nh(<span class=\"hljs-number\">13<\/span>) = <span class=\"hljs-number\">6<\/span><br \/>\nh(<span class=\"hljs-number\">27<\/span>) = <span class=\"hljs-number\">6<\/span> \u2192 collision <span class=\"hljs-keyword\">with<\/span> <span class=\"hljs-number\">13<\/span><br \/>\n<\/code><\/div>\n<\/div>\n<p data-start=\"2518\" data-end=\"2593\">If using <strong data-start=\"2527\" data-end=\"2539\">chaining<\/strong>, both 13 and 27 are stored in bucket 6\u2019s linked list.<\/p>\n<hr data-start=\"2595\" data-end=\"2598\" \/>\n<p data-start=\"2600\" data-end=\"2723\" data-is-last-node=\"\" data-is-only-node=\"\">Would you like <strong data-start=\"2615\" data-end=\"2637\">practice questions<\/strong>, <strong data-start=\"2639\" data-end=\"2672\">previous GATE MCQs on hashing<\/strong>, or <strong data-start=\"2677\" data-end=\"2697\">visuals\/diagrams<\/strong> for easier understanding?<\/p>\n<h3 data-start=\"2600\" data-end=\"2723\"><a href=\"https:\/\/www.jntua.ac.in\/gate-online-classes\/registration\/downloads\/material\/a159143764882.pdf\" target=\"_blank\" rel=\"noopener\">GATE CSEIT\/Database\/ Hashing introduction with hashing function and hashing table<\/a><\/h3>\n<h3 class=\"LC20lb MBeuO DKV0Md\"><a href=\"https:\/\/www.cs.cmu.edu\/~guna\/15-123S11\/Lectures\/Lecture17.pdf\" target=\"_blank\" rel=\"noopener\">Lecture 17 Introduction to Hashing<\/a><\/h3>\n","protected":false},"excerpt":{"rendered":"<p>GATE CSEIT\/Database\/ Hashing introduction with hashing function and hashing table [fvplayer id=&#8221;293&#8243;] \u00a0Hashing in Databases \u2013 GATE CSE\/IT \u00a0What is Hashing? Hashing is a technique used in databases, data structures, and indexing to store and retrieve data efficiently. It uses a hash function to map keys to a specific location in a hash table. Key [&hellip;]<\/p>\n","protected":false},"author":66,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[77],"tags":[],"class_list":["post-3192","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/posts\/3192","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/users\/66"}],"replies":[{"embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/comments?post=3192"}],"version-history":[{"count":0,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/posts\/3192\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/media?parent=3192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/categories?post=3192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/tags?post=3192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}