<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ankit Jain &#187; computer science</title>
	<atom:link href="http://ankitjain.info/ankit/tag/computer-science/feed/" rel="self" type="application/rss+xml" />
	<link>http://ankitjain.info/ankit</link>
	<description>» It’s all about Ankit and Web! «</description>
	<lastBuildDate>Thu, 02 Jun 2011 16:54:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Linear Hashing</title>
		<link>http://ankitjain.info/ankit/2008/09/22/data-structure-linear-dynamic-hashing/</link>
		<comments>http://ankitjain.info/ankit/2008/09/22/data-structure-linear-dynamic-hashing/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 09:31:23 +0000</pubDate>
		<dc:creator>Ankit</dc:creator>
				<category><![CDATA[Tutorial/Links]]></category>
		<category><![CDATA[computer science]]></category>
		<category><![CDATA[hashing]]></category>

		<guid isPermaLink="false">http://ankitjain.info/ankit/2008/09/22/data-structure-linear-dynamic-hashing</guid>
		<description><![CDATA[Hash table is a data structure that associates keys with values. To know more about liner hashing refer Wikipedia. Here are main points that summarizes linear hashing. Full buckets are not necessarily split Buckets split are not necessarily full Every bucket will be split sooner or later and so all Overflows will be reclaimed and [...]]]></description>
			<content:encoded><![CDATA[<p style="margin-left: 19pt">Hash table is a data structure that associates keys with values. To know more about <a target="_blank" href="http://en.wikipedia.org/wiki/Linear_hash">liner hashing refer Wikipedia</a>. Here are main points that summarizes linear hashing.</p>
<ul>
<li>Full buckets are not necessarily split</li>
<li>Buckets split are not necessarily full</li>
<li>Every bucket will be split sooner or later and so all Overflows will be reclaimed and rehashed.</li>
<li>
<div>Split pointer s decides which bucket to split</div>
<ul>
<li><em>s</em> is independent to overflowing bucket</li>
<li>At level <em>i</em>, <em>s</em> is between 0 and 2<em><sup>i</sup></em></li>
<li><em>s</em> is incremented and if at end, is reset to 0.</li>
</ul>
</li>
</ul>
<ul>
<li>h<sub>i</sub> (k)= h(k) mod(2<sup>i</sup> n)</li>
<li>h<sub>i+1</sub> doubles the range of  h<sub>i</sub></li>
</ul>
<p style="margin-left: 19pt"><span id="more-117"></span> <strong>Insertion and Overflow condition</strong></p>
<p style="margin-left: 19pt">Algorithm for inserting &#8216;k&#8217;:</p>
<p style="margin-left: 19pt">1.    b = h0(k)</p>
<p style="margin-left: 19pt">2.    if b &lt; split-pointer  then</p>
<p style="margin-left: 19pt">3.         b = h1(k)</p>
<p style="margin-left: 19pt"><em>Searching</em> in the hash table for &#8216;k&#8217;:</p>
<p style="margin-left: 19pt">1.     b = h0(k)</p>
<p style="margin-left: 19pt">2.     if b &lt; split-pointer then</p>
<p style="margin-left: 19pt">3.         b = h1(k)</p>
<p style="margin-left: 19pt">4.     read bucket b and search there</p>
<p style="margin-left: 19pt"><span style="font-weight: bold">Example:</span></p>
<ul>
<li>In the following M=3 (initial # of buckets)</li>
<li>Each bucket has 2 keys. One extra key for overflow.</li>
<li>s is a pointer, pointing to the split location. This is the place where next split should take place.</li>
<li>Insert Order: 1,7,3,8,12,4,11,2,10,13</li>
</ul>
<p style="margin-left: 19pt">After insertion till 12:</p>
<p style="margin-left: 19pt"><img src="http://ankitjain.info/ankit/wp-content/092208_0950_LinearHashi1.png" /></p>
<p style="margin-left: 19pt">When 4 inserted overflow occurred. So we split the bucket (no matter it is full or partially empty). And  increment pointer.</p>
<p style="margin-left: 19pt"><img src="http://ankitjain.info/ankit/wp-content/092208_0950_LinearHashi2.png" /></p>
<p style="margin-left: 19pt">So we split bucket 0 and rehashed all keys in it. Placed 3 to new bucket as (3 mod 6 = 3 ) and (12 mod 6 =  0 ). Then 11 and 2 are inserted. And now overflow. <em>s</em> is pointing to  bucket 1, hence split bucket 1 by re- hashing it.</p>
<p style="margin-left: 19pt"><img src="http://ankitjain.info/ankit/wp-content/092208_0950_LinearHashi3.png" /></p>
<p style="margin-left: 19pt">After split:</p>
<p style="margin-left: 19pt"><img src="http://ankitjain.info/ankit/wp-content/092208_0950_LinearHashi4.png" /></p>
<p style="margin-left: 19pt">Insertion of 10 and 13: as (10 mod 3 = 1) and bucket 1 &lt; s, we need to hash 10 again using h1(10) = 10 mod 6 = 4th bucket.</p>
<p style="margin-left: 19pt">When 13 is inserted same process is done, but it end up to the same bucket. But here is an overflow, we need to split 2nd bucket.</p>
<p style="margin-left: 19pt"><img src="http://ankitjain.info/ankit/wp-content/092208_0950_LinearHashi5.png" /></p>
<p style="margin-left: 19pt">Here is the final hash table.</p>
<p style="margin-left: 19pt"><img src="http://ankitjain.info/ankit/wp-content/092208_0950_LinearHashi6.png" /></p>
<p style="margin-left: 19pt"><em>s</em> is moved to the top again as one cycle is completed. Now <em>s</em> will travel from 0 to 5th bucket, then 0 to 12, etc;</p>
]]></content:encoded>
			<wfw:commentRss>http://ankitjain.info/ankit/2008/09/22/data-structure-linear-dynamic-hashing/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

