<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Random Posts</title>
	<atom:link href="http://harithimanshu.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://harithimanshu.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Sat, 07 Jan 2012 21:18:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='harithimanshu.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/e428c410425dbf2c15378ae13c257c21?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Random Posts</title>
		<link>http://harithimanshu.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://harithimanshu.wordpress.com/osd.xml" title="Random Posts" />
	<atom:link rel='hub' href='http://harithimanshu.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Print variables without escaped HTML in Play! framework</title>
		<link>http://harithimanshu.wordpress.com/2011/05/15/print-variables-without-escaped-html-in-play-framework/</link>
		<comments>http://harithimanshu.wordpress.com/2011/05/15/print-variables-without-escaped-html-in-play-framework/#comments</comments>
		<pubDate>Sun, 15 May 2011 07:36:49 +0000</pubDate>
		<dc:creator>hhimanshu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://harithimanshu.wordpress.com/2011/05/15/print-variables-without-escaped-html-in-play-framework/</guid>
		<description><![CDATA[I just realized that when I was trying to embed the youtube videos on HTML I was getting the frame objects as Check the quotes in src=&#8221;"&#8221;", I wanted to remove that. After some googling I found how to do that in Play! Framework. Here are the two ways :- a.) use raw(). for example, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=harithimanshu.wordpress.com&amp;blog=6687860&amp;post=425&amp;subd=harithimanshu&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I just realized that when I was trying to embed the youtube videos on HTML I was getting the frame objects as</p>
<p>Check the quotes in src=&#8221;"&#8221;", I wanted to remove that. After some googling I found how to do that in Play! Framework.<br />
Here are the two ways :-</p>
<p>a.) use raw().<br />
for example, the URL value to render is src=&#8221;${video.get(&#8220;url&#8221;)}&#8221;, the use src=${video.get(&#8220;url&#8221;).raw()}</p>
<p>b.) use #verbatim tag<br />
for example, the URL value to render is src=&#8221;${video.get(&#8220;url&#8221;)}&#8221;, the use src=#{verbatim}${video.get(&#8220;url&#8221;)}#{/verbatim}</p>
<p>and you are good to go <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . The result now would be</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/harithimanshu.wordpress.com/425/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/harithimanshu.wordpress.com/425/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/harithimanshu.wordpress.com/425/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/harithimanshu.wordpress.com/425/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/harithimanshu.wordpress.com/425/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/harithimanshu.wordpress.com/425/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/harithimanshu.wordpress.com/425/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/harithimanshu.wordpress.com/425/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/harithimanshu.wordpress.com/425/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/harithimanshu.wordpress.com/425/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/harithimanshu.wordpress.com/425/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/harithimanshu.wordpress.com/425/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/harithimanshu.wordpress.com/425/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/harithimanshu.wordpress.com/425/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=harithimanshu.wordpress.com&amp;blog=6687860&amp;post=425&amp;subd=harithimanshu&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://harithimanshu.wordpress.com/2011/05/15/print-variables-without-escaped-html-in-play-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2a0b2959ff20e8654aabee4b7e49a6ed?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hhimanshu</media:title>
		</media:content>
	</item>
		<item>
		<title>2010 in review</title>
		<link>http://harithimanshu.wordpress.com/2011/01/02/2010-in-review/</link>
		<comments>http://harithimanshu.wordpress.com/2011/01/02/2010-in-review/#comments</comments>
		<pubDate>Sun, 02 Jan 2011 07:40:22 +0000</pubDate>
		<dc:creator>hhimanshu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://harithimanshu.wordpress.com/?p=421</guid>
		<description><![CDATA[The stats helper monkeys at WordPress.com mulled over how this blog did in 2010, and here&#8217;s a high level summary of its overall blog health: The Blog-Health-o-Meter™ reads This blog is doing awesome!. Crunchy numbers A helper monkey made this abstract painting, inspired by your stats. A Boeing 747-400 passenger jet can hold 416 passengers. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=harithimanshu.wordpress.com&amp;blog=6687860&amp;post=421&amp;subd=harithimanshu&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The stats helper monkeys at WordPress.com mulled over how this blog did in 2010, and here&#8217;s a high level summary of its overall blog health:</p>
<p><img style="border:1px solid #ddd;background:#f5f5f5;padding:20px;" src="http://s0.wp.com/i/annual-recap/meter-healthy2.gif" alt="Healthy blog!" width="250" height="183" /></p>
<p>The <em>Blog-Health-o-Meter™</em> reads This blog is doing awesome!.</p>
<h2>Crunchy numbers</h2>
<div style="width:288px;float:right;border:1px solid #ddd;background:#fff;margin:0 0 1em 1em;padding:6px;">
<p><img src="http://s0.wp.com/i/annual-recap/abstract-stats-5.png" alt="Featured image" /></p>
<p><em>A helper monkey made this abstract painting, inspired by your stats.</em></p>
</div>
<p>A Boeing 747-400 passenger jet can hold 416 passengers.  This blog was viewed about <strong>4,000</strong> times in 2010.  That&#8217;s about 10 full 747s.</p>
<p>&nbsp;</p>
<p>In 2010, there were <strong>32</strong> new posts, growing the total archive of this blog to 50 posts. There were <strong>3</strong> pictures uploaded, taking up a total of 609kb.</p>
<p>The busiest day of the year was October 20th with <strong>59</strong> views. The most popular post that day was <a style="color:#08c;" href="http://harithimanshu.wordpress.com/2010/09/02/java-finding-subarray-from-input-array-containing-all-integers-in-query-array/">Java : Finding subarray from input array containing all integers in query array</a>.</p>
<h2>Where did they come from?</h2>
<p>The top referring sites in 2010 were <strong>lmodules.com</strong>, <strong>linkedin.com</strong>, <strong>en.wordpress.com</strong>, <strong>google.co.in</strong>, and <strong>facebook.com</strong>.</p>
<p>Some visitors came searching, mostly for <strong>fibonacci series in java</strong>, <strong>java subarray</strong>, <strong>binary heap java</strong>, <strong>minimum number of coins</strong>, and <strong>implement memcpy in c</strong>.</p>
<h2>Attractions in 2010</h2>
<p>These are the posts and pages that got the most views in 2010.</p>
<div style="clear:left;float:left;font-size:24pt;line-height:1em;margin:-5px 10px 20px 0;">1</div>
<p><a style="margin-right:10px;" href="http://harithimanshu.wordpress.com/2010/09/02/java-finding-subarray-from-input-array-containing-all-integers-in-query-array/">Java : Finding subarray from input array containing all integers in query array</a> <span style="color:#999;font-size:8pt;">September 2010</span></p>
<div style="clear:left;float:left;font-size:24pt;line-height:1em;margin:-5px 10px 20px 0;">2</div>
<p><a style="margin-right:10px;" href="http://harithimanshu.wordpress.com/2010/09/03/java-find-union-and-intersection-of-two-sorted-arrays-2/">Java : find union and intersection of two sorted arrays</a> <span style="color:#999;font-size:8pt;">September 2010</span></p>
<div style="clear:left;float:left;font-size:24pt;line-height:1em;margin:-5px 10px 20px 0;">3</div>
<p><a style="margin-right:10px;" href="http://harithimanshu.wordpress.com/2009/10/02/dynamic-programming-finding-minimum-number-of-coins-for-a-given-sum/">Dynamic programming : Finding minimum number of coins for a given sum</a> <span style="color:#999;font-size:8pt;">October 2009</span></p>
<div style="clear:left;float:left;font-size:24pt;line-height:1em;margin:-5px 10px 20px 0;">4</div>
<p><a style="margin-right:10px;" href="http://harithimanshu.wordpress.com/2009/03/13/fibonacci-series-in-java/">Fibonacci Series in Java</a> <span style="color:#999;font-size:8pt;">March 2009</span><br />
8 comments</p>
<div style="clear:left;float:left;font-size:24pt;line-height:1em;margin:-5px 10px 20px 0;">5</div>
<p><a style="margin-right:10px;" href="http://harithimanshu.wordpress.com/2010/09/16/implementing-binary-heap-in-java/">Implementing Binary Heap in Java</a> <span style="color:#999;font-size:8pt;">September 2010</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/harithimanshu.wordpress.com/421/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/harithimanshu.wordpress.com/421/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/harithimanshu.wordpress.com/421/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/harithimanshu.wordpress.com/421/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/harithimanshu.wordpress.com/421/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/harithimanshu.wordpress.com/421/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/harithimanshu.wordpress.com/421/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/harithimanshu.wordpress.com/421/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/harithimanshu.wordpress.com/421/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/harithimanshu.wordpress.com/421/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/harithimanshu.wordpress.com/421/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/harithimanshu.wordpress.com/421/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/harithimanshu.wordpress.com/421/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/harithimanshu.wordpress.com/421/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=harithimanshu.wordpress.com&amp;blog=6687860&amp;post=421&amp;subd=harithimanshu&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://harithimanshu.wordpress.com/2011/01/02/2010-in-review/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2a0b2959ff20e8654aabee4b7e49a6ed?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hhimanshu</media:title>
		</media:content>

		<media:content url="http://s0.wp.com/i/annual-recap/meter-healthy2.gif" medium="image">
			<media:title type="html">Healthy blog!</media:title>
		</media:content>

		<media:content url="http://s0.wp.com/i/annual-recap/abstract-stats-5.png" medium="image">
			<media:title type="html">Featured image</media:title>
		</media:content>
	</item>
		<item>
		<title>Java : Finding top-K elements in unsorted array in linear time</title>
		<link>http://harithimanshu.wordpress.com/2010/10/17/java-finding-top-k-elements-in-unsorted-array-in-linear-time/</link>
		<comments>http://harithimanshu.wordpress.com/2010/10/17/java-finding-top-k-elements-in-unsorted-array-in-linear-time/#comments</comments>
		<pubDate>Sun, 17 Oct 2010 22:25:00 +0000</pubDate>
		<dc:creator>hhimanshu</dc:creator>
				<category><![CDATA[algorithms]]></category>
		<category><![CDATA[implementation]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[linear time]]></category>
		<category><![CDATA[selection]]></category>
		<category><![CDATA[top-k]]></category>

		<guid isPermaLink="false">http://harithimanshu.wordpress.com/?p=410</guid>
		<description><![CDATA[Complexity : O(N) Output: run:789 BUILD SUCCESSFUL (total time: 0 seconds)<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=harithimanshu.wordpress.com&amp;blog=6687860&amp;post=410&amp;subd=harithimanshu&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Complexity : O(N)</p>
<p><pre class="brush: css;">
public class Selection {
private static final int TOP_K = 3;
public static void main(String args[]) {
int[] _array = new int[]{9,7,8,2,1,3,5,6,4};
if (_array.length == 0) {
System.out.println(&quot;Empty Array&quot;);
System.exit(0);
} else if (_array.length == 1) {
System.out.println(&quot;Only one element, Array already sorted&quot;);
} else {
select(_array, 0, _array.length-1, _array.length-TOP_K);
}
for (int i = _array.length-TOP_K; i &lt;= _array.length - 1; i++) {
System.out.println(_array[i]);
}
}
public static int partition(int[] input, int p, int q) {
int x = input[p];
int i = p;
for (int j = (p + 1); j &lt;= q; j++) {
if (input[j] &lt;= x) {
i = i + 1;
if(i &lt; j){
int temp = input[j];
input[j] = input[i];
input[i] = temp;
}
}
}
int temp1 = input[p];
input[p] = input[i];
input[i] = temp1;
return i;
public static void select(int[] list, int left, int right, int k){
int pivotIndex = partition(list, left, right);
if(pivotIndex == k){
return;
}
else if(k &lt; pivotIndex){
select(list, left, pivotIndex -1, k);
}else{
select(list, pivotIndex +1 , right, k);
}
}
}
</pre></p>
<p>Output:<br />
run:789<br />
BUILD SUCCESSFUL (total time: 0 seconds)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/harithimanshu.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/harithimanshu.wordpress.com/410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/harithimanshu.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/harithimanshu.wordpress.com/410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/harithimanshu.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/harithimanshu.wordpress.com/410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/harithimanshu.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/harithimanshu.wordpress.com/410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/harithimanshu.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/harithimanshu.wordpress.com/410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/harithimanshu.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/harithimanshu.wordpress.com/410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/harithimanshu.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/harithimanshu.wordpress.com/410/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=harithimanshu.wordpress.com&amp;blog=6687860&amp;post=410&amp;subd=harithimanshu&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://harithimanshu.wordpress.com/2010/10/17/java-finding-top-k-elements-in-unsorted-array-in-linear-time/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2a0b2959ff20e8654aabee4b7e49a6ed?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hhimanshu</media:title>
		</media:content>
	</item>
		<item>
		<title>Python : finding substring in a string</title>
		<link>http://harithimanshu.wordpress.com/2010/10/06/python-finding-substring-in-a-string/</link>
		<comments>http://harithimanshu.wordpress.com/2010/10/06/python-finding-substring-in-a-string/#comments</comments>
		<pubDate>Wed, 06 Oct 2010 02:50:27 +0000</pubDate>
		<dc:creator>hhimanshu</dc:creator>
				<category><![CDATA[implementation]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[substring]]></category>

		<guid isPermaLink="false">http://harithimanshu.wordpress.com/?p=381</guid>
		<description><![CDATA[Output : [harit@harit-laptop scripts]$ python substr.py &#8217;123123113456456345123&#8242; &#8217;456&#8242; substring found at indexes :  9 substring found at indexes :  12 [harit@harit-laptop scripts]$ python substr.py &#8216;Hello world!&#8217; &#8216;orl&#8217; substring found at indexes : 7 [harit@harit-laptop scripts]$ python substr.py 12 12 substring found at indexes : 0 [harit@harit-laptop scripts]$ python substr.py 12 123 substring pattern is longer [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=harithimanshu.wordpress.com&amp;blog=6687860&amp;post=381&amp;subd=harithimanshu&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><pre class="brush: css;">
#!/usr/bin/python

import sys

def is_substring(actual_str, pattern_str):

    if actual_str is None or pattern_str is None:
        print &quot;empty string .. quitting&quot;
	return

    if len(pattern_str) &gt; len(actual_str):
        print &quot;substring pattern is longer than actual string&quot;
	return

    indexes = []
    for i in range(len(actual_str) - len(pattern_str) + 1):
 	if pattern_str[0] == actual_str[i] and\
	    pattern_str[len(pattern_str)-1] == actual_str[i + len(pattern_str)-1]:
	    indexes.append(i)

    if len(indexes) == 0:
        print &quot;Substring couldn't be found!&quot;
	return

    mismatch = False
    for j in range(len(indexes)):
        index = indexes[j]
        for k in range(len(pattern_str)):
	    if(actual_str[index] != pattern_str[k]):
	        #print &quot;Mismatch : %s - %s&quot;%(actual_str[index], pattern_str[k])
		mismatch = True
		break
 	    index += 1

	if mismatch == True:
	    mismatch = False
	    continue
        print &quot;substring found at indexes : &quot;, indexes[j]

if __name__== &quot;__main__&quot;:
    if len(sys.argv) != 3:
        is_substring('Hello world!', 'odl')
    else:
	is_substring(str(sys.argv[1]), str(sys.argv[2]))&lt;/div&gt;
</pre></p>
<p>Output :</p>
<div id="_mcePaste">[harit@harit-laptop scripts]$ python substr.py &#8217;123123113456456345123&#8242; &#8217;456&#8242;</div>
<div id="_mcePaste">substring found at indexes :  9</div>
<div id="_mcePaste">substring found at indexes :  12</div>
<p>[harit@harit-laptop scripts]$ python substr.py &#8216;Hello world!&#8217; &#8216;orl&#8217;</p>
<p>substring found at indexes :  7</p>
<p>[harit@harit-laptop scripts]$ python substr.py 12 12</p>
<p>substring found at indexes :  0</p>
<p>[harit@harit-laptop scripts]$ python substr.py 12 123</p>
<p>substring pattern is longer than actual string</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/harithimanshu.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/harithimanshu.wordpress.com/381/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/harithimanshu.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/harithimanshu.wordpress.com/381/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/harithimanshu.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/harithimanshu.wordpress.com/381/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/harithimanshu.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/harithimanshu.wordpress.com/381/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/harithimanshu.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/harithimanshu.wordpress.com/381/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/harithimanshu.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/harithimanshu.wordpress.com/381/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/harithimanshu.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/harithimanshu.wordpress.com/381/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=harithimanshu.wordpress.com&amp;blog=6687860&amp;post=381&amp;subd=harithimanshu&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://harithimanshu.wordpress.com/2010/10/06/python-finding-substring-in-a-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2a0b2959ff20e8654aabee4b7e49a6ed?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hhimanshu</media:title>
		</media:content>
	</item>
		<item>
		<title>Java : Reversing a singly linkedlist in linear time</title>
		<link>http://harithimanshu.wordpress.com/2010/09/17/java-reversing-a-singly-linkedlist-in-linear-time/</link>
		<comments>http://harithimanshu.wordpress.com/2010/09/17/java-reversing-a-singly-linkedlist-in-linear-time/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 17:42:02 +0000</pubDate>
		<dc:creator>hhimanshu</dc:creator>
				<category><![CDATA[data structures]]></category>
		<category><![CDATA[implementation]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[linear time]]></category>
		<category><![CDATA[linkedlist]]></category>
		<category><![CDATA[reverse]]></category>
		<category><![CDATA[singly]]></category>

		<guid isPermaLink="false">http://harithimanshu.wordpress.com/?p=361</guid>
		<description><![CDATA[Program: Reverse a singlylinked List complexity : O(n) Output: run: 0 1 2 3 4 5 6 7 7 6 5 4 3 2 1 0 BUILD SUCCESSFUL (total time: 0 seconds)<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=harithimanshu.wordpress.com&amp;blog=6687860&amp;post=361&amp;subd=harithimanshu&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong><span style="text-decoration:underline;">Program:</span></strong> Reverse a singlylinked List</p>
<p><strong><span style="text-decoration:underline;">complexity :</span></strong> O(n)</p>
<p><pre class="brush: css;">
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package careercup.google;

/**
 *
 * @author Harit
 */
public class SinglyLinkedListNode {
    private int value;
    private int next;

    public SinglyLinkedListNode(int v){
        this.value = v;
        this.next = -1;
    }

    public int getValue(){
        return this.value;
    }

    public int getNext(){
        return this.next;
    }

    public void setNext(int n){
        this.next = n;
    }
}</pre></p>
<div id="_mcePaste"><pre class="brush: css;">
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package careercup.google;

/**
 *
 * @author Harit
 */
public class ReverseSinglyLinkedList {
    private static int[] input = new int[]{0,1,2,3,4,5,6,7};
    private static SinglyLinkedListNode[] nodes = new SinglyLinkedListNode[input.length];
    private static int head = -1;
    private static int tail = -1;

    public static void main(String args[]){
        createList();
        printList(head);
        printList(reverseList(head));

    }

    private static void createList(){
        for(int i=0; i&lt;input.length; i++){
            SinglyLinkedListNode node = new SinglyLinkedListNode(input[i]);
            nodes[i] = node;
            if(i==0){
                head = i;
                tail = i;
                continue;
            }
            /* setting parent's next*/
            nodes[i-1].setNext(i);
            tail = i;
        }
    }

    private static int reverseList(int head){
        SinglyLinkedListNode next = null;
        SinglyLinkedListNode current = null;
        int result = -1;

        current = nodes[head];
        while(current != null){
            if(current.getNext() == -1){
                current.setNext(result);
                result = current.getValue();
                break;
            }
            next = nodes[current.getNext()];
            current.setNext(result);
            result = current.getValue();

            current = next;
        }
        return result;
    }

    private static void printList(int head){
        while(head != -1){
            System.out.print(nodes[head].getValue() + &quot; &quot;);
            head = nodes[head].getNext();
        }
        System.out.println(&quot;&quot;);

    }
}</pre></p>
<p><span style="text-decoration:underline;">Output:</span></p>
<pre>run:
0 1 2 3 4 5 6 7
7 6 5 4 3 2 1 0
BUILD SUCCESSFUL (total time: 0 seconds)</pre>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/harithimanshu.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/harithimanshu.wordpress.com/361/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/harithimanshu.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/harithimanshu.wordpress.com/361/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/harithimanshu.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/harithimanshu.wordpress.com/361/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/harithimanshu.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/harithimanshu.wordpress.com/361/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/harithimanshu.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/harithimanshu.wordpress.com/361/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/harithimanshu.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/harithimanshu.wordpress.com/361/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/harithimanshu.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/harithimanshu.wordpress.com/361/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=harithimanshu.wordpress.com&amp;blog=6687860&amp;post=361&amp;subd=harithimanshu&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://harithimanshu.wordpress.com/2010/09/17/java-reversing-a-singly-linkedlist-in-linear-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2a0b2959ff20e8654aabee4b7e49a6ed?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hhimanshu</media:title>
		</media:content>
	</item>
		<item>
		<title>Implementing Binary Heap in Java</title>
		<link>http://harithimanshu.wordpress.com/2010/09/16/implementing-binary-heap-in-java/</link>
		<comments>http://harithimanshu.wordpress.com/2010/09/16/implementing-binary-heap-in-java/#comments</comments>
		<pubDate>Thu, 16 Sep 2010 21:00:33 +0000</pubDate>
		<dc:creator>hhimanshu</dc:creator>
				<category><![CDATA[algorithms]]></category>
		<category><![CDATA[data structures]]></category>
		<category><![CDATA[implementation]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[heaps]]></category>

		<guid isPermaLink="false">http://harithimanshu.wordpress.com/?p=354</guid>
		<description><![CDATA[Output: run: 4 7 6 9 3 2 1 1 4 2 9 7 6 3 BUILD SUCCESSFUL (total time: 0 seconds)<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=harithimanshu.wordpress.com&amp;blog=6687860&amp;post=354&amp;subd=harithimanshu&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><pre class="brush: css;">
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package careercup.google;

/**
 *
 * @author Harit
 */
public class BinaryHeapNode {

    private int value;
    private int left;
    private int right;

    public BinaryHeapNode(int v){
        this.value = v;
        this.left = -1;
        this.right = -1;
    }

    public int getValue(){
        return this.value;
    }

    public void setChild(boolean left, int index){
        if(left){
            this.left = index;
        }else{
            this.right = index;
        }
    }

    public int getChild(boolean left){
        if(left){
            return this.left;
        }else{
            return this.right;
        }
    }
    public boolean isLeftChild(){
        return (this.left == -1);
    }

    public boolean isRightChild(){
        return (this.right == -1);
    }
}</pre></p>
<div id="_mcePaste"><pre class="brush: plain;">
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package careercup.google;

import java.util.ArrayList;

/**
 *
 * @author Harit
 */
public class BinaryHeap {

    //private static int[] input = new int[]{-1,3,2,1};
    private static int[] input = new int[]{-1,4,7,6,9,3,2,1};
    private static BinaryHeapNode[] nodes = new BinaryHeapNode[input.length];
    private static int MAX_NODES = 1;
    public static void main(String args[]){

        for(int i=1; i&lt;input.length; i++){
            System.out.print(input[i] + &quot; &quot;);
            BinaryHeapNode node = new BinaryHeapNode(i);
            nodes[MAX_NODES++] = node;
            if(i==1){
                continue;
            }
            setParent(i);
            insertNode(i, input[i]);
        }
        System.out.println(&quot; &quot;);
        /* final binary heap */
        for(int i=1; i&lt;input.length; i++){
            System.out.print(input[i] + &quot; &quot;);
        }
        System.out.println(&quot; &quot;);
    }

    private static void setParent(int index){
        while(true){
            BinaryHeapNode parent = nodes[index/2];
            if(parent.isLeftChild()){
                parent.setChild(true, index);
                return;
            }else if(parent.isRightChild()){
                parent.setChild(false, index);
                return;
            }
        }
    }

    private static void insertNode(int index, int value){
        ArrayList&lt;Integer&gt; indexes = new ArrayList&lt;Integer&gt;();
        indexes.add(index);
        int parent_index = index/2;
        while(parent_index &gt;= 1){
            if(input[parent_index] &gt; value){
                indexes.add(parent_index);
            }
            parent_index /= 2;
        }
        Integer[] replace = (Integer[])indexes.toArray(new Integer[0]);
        for(int i = 0; i &lt;replace.length-1; i++){
            input[replace[i]] = input[replace[i+1]];
        }
        input[replace[replace.length-1]] = value;
    }
}</pre></p>
<p><strong><span style="text-decoration:underline;">Output:</span></strong></p>
<pre>run:
4 7 6 9 3 2 1
1 4 2 9 7 6 3
BUILD SUCCESSFUL (total time: 0 seconds)</pre>
<div></div>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/harithimanshu.wordpress.com/354/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/harithimanshu.wordpress.com/354/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/harithimanshu.wordpress.com/354/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/harithimanshu.wordpress.com/354/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/harithimanshu.wordpress.com/354/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/harithimanshu.wordpress.com/354/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/harithimanshu.wordpress.com/354/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/harithimanshu.wordpress.com/354/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/harithimanshu.wordpress.com/354/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/harithimanshu.wordpress.com/354/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/harithimanshu.wordpress.com/354/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/harithimanshu.wordpress.com/354/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/harithimanshu.wordpress.com/354/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/harithimanshu.wordpress.com/354/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=harithimanshu.wordpress.com&amp;blog=6687860&amp;post=354&amp;subd=harithimanshu&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://harithimanshu.wordpress.com/2010/09/16/implementing-binary-heap-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2a0b2959ff20e8654aabee4b7e49a6ed?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hhimanshu</media:title>
		</media:content>
	</item>
		<item>
		<title>Selection sort in Java</title>
		<link>http://harithimanshu.wordpress.com/2010/09/16/selection-sort-in-java/</link>
		<comments>http://harithimanshu.wordpress.com/2010/09/16/selection-sort-in-java/#comments</comments>
		<pubDate>Thu, 16 Sep 2010 20:56:59 +0000</pubDate>
		<dc:creator>hhimanshu</dc:creator>
				<category><![CDATA[algorithms]]></category>
		<category><![CDATA[implementation]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[in-place]]></category>
		<category><![CDATA[selection]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://harithimanshu.wordpress.com/?p=344</guid>
		<description><![CDATA[In-place sorting Complexity: O(n^2) Output: run: 9 8 7 4 5 6 3 2 1 1 2 3 4 5 6 7 8 9 BUILD SUCCESSFUL (total time: 0 seconds)<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=harithimanshu.wordpress.com&amp;blog=6687860&amp;post=344&amp;subd=harithimanshu&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In-place sorting</p>
<p><strong><span style="text-decoration:underline;">Complexity: </span></strong>O(n^2)</p>
<p><pre class="brush: css;">
/** To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package careercup.google;
&lt;div id=&quot;_mcePaste&quot;&gt;/**
 *
 * @author Harit
 */
public class SelectionSort {
    //private static int[] input = new int[]{5,1,4,2,8};
    private static int[] input = new int[]{9,8,7,4,5,6,3,2,1};

    public static void main(String args[]){
        int last_index = 0;
        int swap_index = -1;

        printArray();

        for(int i=1; i&lt;input.length; i++){
            swap_index = returnIndex(i);
            if(input[last_index] &lt;= input[swap_index]){
                continue;
            }
            int temp = input[last_index];
            input[last_index] = input[swap_index];
            input[swap_index] = temp;
            last_index += 1;
        }
            printArray();
    }

    private static int returnIndex(int index){
        int rindex = index;
        int smallest = input[index];
        for(int i=index+1; i&lt;input.length; i++){
            if(input[i] &lt; smallest){
                rindex = i;
                smallest = input[i];
            }
        }
        return rindex;
    }

    private static void printArray(){
        for(int j=0; j&lt;input.length; j++){
            System.out.print(input[j] + &quot; &quot;);
        }
        System.out.println(&quot;&quot;);
    }
}</pre></p>
<div id="_mcePaste"><strong><span style="text-decoration:underline;">Output:</span></strong></div>
<div id="_mcePaste">run:</div>
<div>9 8 7 4 5 6 3 2 1</div>
<div>1 2 3 4 5 6 7 8 9</div>
<div>BUILD SUCCESSFUL (total time: 0 seconds)</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/harithimanshu.wordpress.com/344/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/harithimanshu.wordpress.com/344/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/harithimanshu.wordpress.com/344/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/harithimanshu.wordpress.com/344/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/harithimanshu.wordpress.com/344/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/harithimanshu.wordpress.com/344/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/harithimanshu.wordpress.com/344/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/harithimanshu.wordpress.com/344/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/harithimanshu.wordpress.com/344/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/harithimanshu.wordpress.com/344/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/harithimanshu.wordpress.com/344/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/harithimanshu.wordpress.com/344/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/harithimanshu.wordpress.com/344/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/harithimanshu.wordpress.com/344/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=harithimanshu.wordpress.com&amp;blog=6687860&amp;post=344&amp;subd=harithimanshu&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://harithimanshu.wordpress.com/2010/09/16/selection-sort-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2a0b2959ff20e8654aabee4b7e49a6ed?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hhimanshu</media:title>
		</media:content>
	</item>
		<item>
		<title>Java InsertionSort</title>
		<link>http://harithimanshu.wordpress.com/2010/09/16/java-insertionsort/</link>
		<comments>http://harithimanshu.wordpress.com/2010/09/16/java-insertionsort/#comments</comments>
		<pubDate>Thu, 16 Sep 2010 20:50:10 +0000</pubDate>
		<dc:creator>hhimanshu</dc:creator>
				<category><![CDATA[algorithms]]></category>
		<category><![CDATA[implementation]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[in-place]]></category>
		<category><![CDATA[insertion]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://harithimanshu.wordpress.com/?p=334</guid>
		<description><![CDATA[In-place sorting Complexity: O(n^2) Output: run: 5 1 2 4 8 1 2 4 5 8 BUILD SUCCESSFUL (total time: 0 seconds)<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=harithimanshu.wordpress.com&amp;blog=6687860&amp;post=334&amp;subd=harithimanshu&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In-place sorting</p>
<p><strong><span style="text-decoration:underline;">Complexity</span></strong>: O(n^2)</p>
<p><pre class="brush: plain;">/*
* To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package careercup.google;
/**
 *
 * @author Harit
 */
public class InsertionSort {
    private static int[] input = new int[]{5,1,2,4,8};

    public static void main(String args[]){
        printArray();

        for(int i=1; i&lt;input.length; i++){
            int key = input[i];
            int j = i-1;

            while(j&gt;=0 &amp;&amp; input[j]&gt;key){
                input[j+1] = input[j];
                j -= 1;
            }
            input[j+1] = key;
        }
        printArray();
    }

    private static void printArray(){
        for(int k=0; k&lt;input.length; k++){
            System.out.print(input[k] + &quot; &quot;);
        }
        System.out.println(&quot;&quot;);
    }
}</pre></p>
<div id="_mcePaste"><strong><span style="text-decoration:underline;">Output:</span></strong></div>
<div id="_mcePaste">run:</div>
<div>5 1 2 4 8</div>
<div>1 2 4 5 8</div>
<div>BUILD SUCCESSFUL (total time: 0 seconds)</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/harithimanshu.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/harithimanshu.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/harithimanshu.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/harithimanshu.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/harithimanshu.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/harithimanshu.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/harithimanshu.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/harithimanshu.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/harithimanshu.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/harithimanshu.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/harithimanshu.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/harithimanshu.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/harithimanshu.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/harithimanshu.wordpress.com/334/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=harithimanshu.wordpress.com&amp;blog=6687860&amp;post=334&amp;subd=harithimanshu&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://harithimanshu.wordpress.com/2010/09/16/java-insertionsort/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>40.907510 -73.108630</georss:point>
		<geo:lat>40.907510</geo:lat>
		<geo:long>-73.108630</geo:long>
		<media:content url="http://0.gravatar.com/avatar/2a0b2959ff20e8654aabee4b7e49a6ed?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hhimanshu</media:title>
		</media:content>
	</item>
		<item>
		<title>BubbleSort in Java</title>
		<link>http://harithimanshu.wordpress.com/2010/09/16/bubblesort-in-java/</link>
		<comments>http://harithimanshu.wordpress.com/2010/09/16/bubblesort-in-java/#comments</comments>
		<pubDate>Thu, 16 Sep 2010 20:42:10 +0000</pubDate>
		<dc:creator>hhimanshu</dc:creator>
				<category><![CDATA[algorithms]]></category>
		<category><![CDATA[implementation]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[bubblesort]]></category>
		<category><![CDATA[in-place]]></category>

		<guid isPermaLink="false">http://harithimanshu.wordpress.com/?p=326</guid>
		<description><![CDATA[In-place sorting Complexity : O(n^2) Output: run: 5 1 4 2 8 1 2 4 5 8 BUILD SUCCESSFUL (total time: 0 seconds)<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=harithimanshu.wordpress.com&amp;blog=6687860&amp;post=326&amp;subd=harithimanshu&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In-place sorting</p>
<p><strong><span style="text-decoration:underline;">Complexity : </span></strong> O(n^2)</p>
<p><pre class="brush: css;">
/*
* To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package careercup.google;
/**
 *
 * @author Harit
 */
public class BubbleSort {
    private static int[] input = new int[]{5,1,4,2,8};

    public static void main(String args[]){
        for(int i=0; i&lt;input.length; i++){
            System.out.print(input[i] + &quot; &quot;);
        }
        System.out.println(&quot;&quot;);

        for(int i=0; i&lt;input.length; i++){
            for(int j=1; j&lt;input.length; j++){
                if(input[j] &lt; input[j-1]){
                    int temp = input[j];
                    input[j] = input[j-1];
                    input[j-1] = temp;
                }
            }
        }
        for(int k =0; k&lt;input.length; k++){
            System.out.print(input[k] + &quot; &quot;);
        }
        System.out.println(&quot;&quot;);
    }
}</pre></p>
<p><strong><span style="text-decoration:underline;">Output:</span></strong></p>
<p>run:</p>
<p>5 1 4 2 8</p>
<p>1 2 4 5 8</p>
<p>BUILD SUCCESSFUL (total time: 0 seconds)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/harithimanshu.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/harithimanshu.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/harithimanshu.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/harithimanshu.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/harithimanshu.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/harithimanshu.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/harithimanshu.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/harithimanshu.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/harithimanshu.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/harithimanshu.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/harithimanshu.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/harithimanshu.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/harithimanshu.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/harithimanshu.wordpress.com/326/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=harithimanshu.wordpress.com&amp;blog=6687860&amp;post=326&amp;subd=harithimanshu&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://harithimanshu.wordpress.com/2010/09/16/bubblesort-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2a0b2959ff20e8654aabee4b7e49a6ed?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hhimanshu</media:title>
		</media:content>
	</item>
		<item>
		<title>Java : Print n-Tree level by level</title>
		<link>http://harithimanshu.wordpress.com/2010/09/10/java-print-n-tree-level-by-level/</link>
		<comments>http://harithimanshu.wordpress.com/2010/09/10/java-print-n-tree-level-by-level/#comments</comments>
		<pubDate>Fri, 10 Sep 2010 22:01:49 +0000</pubDate>
		<dc:creator>hhimanshu</dc:creator>
				<category><![CDATA[data structures]]></category>
		<category><![CDATA[implementation]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[arraylist]]></category>
		<category><![CDATA[in]]></category>
		<category><![CDATA[level]]></category>
		<category><![CDATA[print]]></category>
		<category><![CDATA[queue]]></category>
		<category><![CDATA[Tree]]></category>

		<guid isPermaLink="false">http://harithimanshu.wordpress.com/?p=311</guid>
		<description><![CDATA[Problem: for a n-tree where each node contains any no of nodes print the nodes in level order and each level must contain a line with a gap Reference : http://www.careercup.com/question?id=3756903 Program : Output: run: 0 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; 1 2 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; 3 4 5 6 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; 7 8 9 10 11 12 13 14 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; BUILD [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=harithimanshu.wordpress.com&amp;blog=6687860&amp;post=311&amp;subd=harithimanshu&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong><span style="text-decoration:underline;">Problem:</span></strong> for a n-tree where each node contains any no of nodes print the nodes in level order and each level must contain a line with a gap</p>
<p><strong><span style="text-decoration:underline;">Reference :</span></strong> <a href="http://www.careercup.com/question?id=3756903">http://www.careercup.com/question?id=3756903</a></p>
<p><strong><span style="text-decoration:underline;">Program : </span></strong></p>
<p><pre class="brush: css;">
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package careercup.google;
import java.util.ArrayList;
/**
 *
 * @author Harit
 */
public class NTreeNode {
    private int value;
    private ArrayList&lt;NTreeNode&gt; child;

    public NTreeNode(int v){
        this.value = v;
    }

    public void addChild(NTreeNode n){
        if(child == null){
            child = new ArrayList&lt;NTreeNode&gt;();
        }
        child.add(n);
    }

    public int getValue(){
        return this.value;
    }

    public ArrayList&lt;NTreeNode&gt; getChild(){
        return this.child;
    }
}</pre></p>
<p><pre class="brush: css;">
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package careercup.google;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;

/**
 *
 * @author Harit
 */
public class PrintNTree {

    private static final int INCREMENT = 2; // controls the tree size
    private static int start = 1;
    private static int end = INCREMENT;
    private static Queue&lt;NTreeNode&gt; one = new LinkedList&lt;NTreeNode&gt;();
    private static Queue&lt;NTreeNode&gt; two = new LinkedList&lt;NTreeNode&gt;();

    public static void main(String args[]){
        NTreeNode root = new NTreeNode(0);
        addChildren(root, start,end);
        increment();

        // level one filling
        Iterator l1 = root.getChild().iterator();
        while(l1.hasNext()){
            addChildren((NTreeNode)l1.next(), start, end );
            increment();
        }

        // level two filling
        Iterator l2 = root.getChild().iterator();
        while(l2.hasNext()){
            Iterator l21 = ((NTreeNode)l2.next()).getChild().iterator();
            while(l21.hasNext()){
                addChildren((NTreeNode)l21.next(), start, end);
                increment();
            }
        }
        printLevelList(root);
    }

    private static void addChildren(NTreeNode parent, int start, int end){
        for(int i=start; i&lt;=end; i++){
            NTreeNode node = new NTreeNode(i);
            parent.addChild(node);
        }
    }

    private static void printLevelList(NTreeNode root){
       if(root == null){
           System.out.println(&quot;Empty tree&quot;);
           return;
       }
       System.out.println( root.getValue() + &quot;&quot;);
       System.out.println(&quot;-----------------------&quot;);
       if(root.getChild() == null){
           System.out.println(&quot;No Children&quot;);
           return;
       }
       addtoQueue(root.getChild());
       copyQueue();
       while(true){
           while(!one.isEmpty()){
                NTreeNode node = one.remove();
                System.out.print(node.getValue() + &quot; &quot;);
                addtoQueue(node.getChild());
           }
           System.out.println(&quot;&quot;);
           System.out.println(&quot;---------------------------&quot;);
           copyQueue();
           if(one.isEmpty() &amp;&amp; two.isEmpty()){
               return;
           }

       }
    }

    private static void addtoQueue(ArrayList&lt;NTreeNode&gt; n){
        if(n == null){
            return;
        }
        Iterator iter = n.iterator();
        while(iter.hasNext()){
            two.add((NTreeNode)iter.next());
        }
    }

    private static void copyQueue(){
        while(!two.isEmpty()){
            one.add(two.remove());
        }
    }
    private static void increment(){
        start = end + 1;
        end = start + (INCREMENT - 1);
    }
}</pre></p>
<p><strong><span style="text-decoration:underline;">Output:</span></strong></p>
<div id="_mcePaste">run:</div>
<div id="_mcePaste">0</div>
<div id="_mcePaste">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</div>
<div id="_mcePaste">1 2</div>
<div id="_mcePaste">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</div>
<div id="_mcePaste">3 4 5 6</div>
<div id="_mcePaste">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</div>
<div id="_mcePaste">7 8 9 10 11 12 13 14</div>
<div id="_mcePaste">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</div>
<div id="_mcePaste">BUILD SUCCESSFUL (total time: 0 seconds)</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/harithimanshu.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/harithimanshu.wordpress.com/311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/harithimanshu.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/harithimanshu.wordpress.com/311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/harithimanshu.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/harithimanshu.wordpress.com/311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/harithimanshu.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/harithimanshu.wordpress.com/311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/harithimanshu.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/harithimanshu.wordpress.com/311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/harithimanshu.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/harithimanshu.wordpress.com/311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/harithimanshu.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/harithimanshu.wordpress.com/311/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=harithimanshu.wordpress.com&amp;blog=6687860&amp;post=311&amp;subd=harithimanshu&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://harithimanshu.wordpress.com/2010/09/10/java-print-n-tree-level-by-level/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2a0b2959ff20e8654aabee4b7e49a6ed?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hhimanshu</media:title>
		</media:content>
	</item>
	</channel>
</rss>
