<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;DkcBQn49eSp7ImA9WhRbGUg.&quot;"><id>tag:blogger.com,1999:blog-7486773803503258327</id><updated>2012-02-11T01:54:13.061-08:00</updated><category term="tanenbaum" /><category term="merging" /><category term="andrew ng" /><category term="pathway" /><category term="books" /><category term="grace" /><category term="rotated" /><category term="adobe" /><category term="lcrs" /><category term="subset" /><category term="subsequence" /><category term="array" /><category term="binary" /><category term="sum" /><category term="anagram" /><category term="sorted" /><category term="intelligence" /><category term="manjot" /><category term="distance" /><category term="classes" /><category term="searching" /><category term="ancestor" /><category term="professional" /><category term="combinations" /><category term="increasing" /><category term="integer" /><category term="reverse" /><category term="young" /><category term="sort" /><category term="facebook" /><category term="of" /><category term="heap" /><category term="llife" /><category term="algorithm" /><category term="machine" /><category term="game" /><category term="maximum" /><category term="levenstein" /><category term="stacking" /><category term="artificial" /><category term="online" /><category term="tableau" /><category term="interview" /><category term="edit" /><category term="thrun" /><category term="insertion" /><category term="selection" /><category term="pahwa" /><category term="tree" /><category term="knapsack" /><category term="google" /><category term="recursion" /><category term="cormen" /><category term="median" /><category term="list" /><category term="dynamic" /><category term="pratt" /><category term="box" /><category term="nsit" /><category term="conway" /><category term="breadth" /><category term="keypad" /><category term="postorder" /><category term="graph" /><category term="conference" /><category term="grid" /><category term="string" /><category term="longest" /><category term="hopper" /><category term="stanford" /><category term="code" /><category term="linked" /><category term="matching" /><category term="learning" /><category term="traversal" /><category term="common" /><category term="merge" /><category term="karp" /><category term="process" /><category term="programming" /><category term="rabin" /><category term="sorting" /><category term="lowest" /><category term="implementation" /><category term="norvig" /><category term="knuth" /><category term="preorder" /><category term="first" /><category term="question" /><category term="trie" /><category term="print" /><category term="matrix" /><category term="morris" /><category term="search" /><category term="structure" /><category term="microsoft" /><category term="writing" /><category term="data" /><category term="questions" /><category term="inorder" /><title>A Dreamer's Blog</title><subtitle type="html" /><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://manjotpahwa.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://manjotpahwa.blogspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Manjot Pahwa</name><uri>http://www.blogger.com/profile/01321615468772658065</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/-yvlwnl1IC58/Tu3IyRTw0tI/AAAAAAAAB5Q/efTRLy7YTMg/s220/IMG_1804000.jpg" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>39</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/blogspot/KiwTH" /><feedburner:info uri="blogspot/kiwth" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>blogspot/KiwTH</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><entry gd:etag="W/&quot;DkYAQ38-eyp7ImA9WhRVFk0.&quot;"><id>tag:blogger.com,1999:blog-7486773803503258327.post-7173093845257039076</id><published>2012-01-14T21:09:00.000-08:00</published><updated>2012-01-14T21:09:02.153-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-14T21:09:02.153-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="keypad" /><category scheme="http://www.blogger.com/atom/ns#" term="question" /><category scheme="http://www.blogger.com/atom/ns#" term="combinations" /><category scheme="http://www.blogger.com/atom/ns#" term="print" /><title>Keypad Question</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;This question has been asked in interviews of many giant tech companies. The statement is:&lt;br /&gt;
Given a string in the form of numbers on a keypad of a mobile phone, print all the combinations of alphabets that are possible if the numbers are typed on a phone. Assume that the numbers 0 and 1 are not typed.&lt;br /&gt;
e.g.&lt;br /&gt;
input = 3&lt;br /&gt;
output = {d, e, f}&lt;br /&gt;
input = 24&lt;br /&gt;
output = {ag, bg, cg, ah, bh, ch, ai, bi, ci}&lt;br /&gt;
The algorithm I used is a simple recursive one in which the characters are chosen according to the input alphabet and the current character being observed as shown below:&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;#include&amp;lt;iostream&amp;gt;&lt;br /&gt;
#include&amp;lt;cstdlib&amp;gt;&lt;br /&gt;
#include&amp;lt;cmath&amp;gt;&lt;br /&gt;
#include&amp;lt;cstring&amp;gt;&lt;br /&gt;
#include&amp;lt;stdio.h&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
&lt;br /&gt;
char digitmap[8][5] = {"abc","def","ghi", "jkl","mno","pqrs","tuv","wxyz"};&lt;br /&gt;
&lt;br /&gt;
int lengths[] = {3, 3, 3, 3, 3, 4, 3, 4};&lt;br /&gt;
&lt;br /&gt;
void PrintCombos(int N, int curr, char input[], char str[])&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; if(curr==N){&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //cout&amp;lt;&amp;lt;"1"&amp;lt;&amp;lt;endl;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; str[curr] = '\0';&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf("%s\n", str);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; else{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //cout&amp;lt;&amp;lt;"2"&amp;lt;&amp;lt;"\n"&amp;lt;&amp;lt;curr&amp;lt;&amp;lt;"\n";&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for(int i=0; i&amp;lt;lengths[input[curr]-'0'-2] ; i++){&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; str[curr] = digitmap[input[curr]-'0'-2][i];&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PrintCombos(N, curr+1, input, str);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; char input[] = "23";&lt;br /&gt;
&amp;nbsp; &amp;nbsp; char str[100];&lt;br /&gt;
&amp;nbsp; &amp;nbsp; PrintCombos(2, 0, input, str);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7486773803503258327-7173093845257039076?l=manjotpahwa.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/T4EvPqfZ5wtmJClW4tjGXX0Zpvk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/T4EvPqfZ5wtmJClW4tjGXX0Zpvk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/T4EvPqfZ5wtmJClW4tjGXX0Zpvk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/T4EvPqfZ5wtmJClW4tjGXX0Zpvk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/KiwTH/~4/lYcGNI1v4G4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manjotpahwa.blogspot.com/feeds/7173093845257039076/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7486773803503258327&amp;postID=7173093845257039076&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/7173093845257039076?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/7173093845257039076?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/KiwTH/~3/lYcGNI1v4G4/keypad-question.html" title="Keypad Question" /><author><name>Manjot Pahwa</name><uri>http://www.blogger.com/profile/01321615468772658065</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/-yvlwnl1IC58/Tu3IyRTw0tI/AAAAAAAAB5Q/efTRLy7YTMg/s220/IMG_1804000.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://manjotpahwa.blogspot.com/2012/01/keypad-question.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0EMSHw8cCp7ImA9WhRVFEs.&quot;"><id>tag:blogger.com,1999:blog-7486773803503258327.post-7666755317912499150</id><published>2012-01-13T06:34:00.000-08:00</published><updated>2012-01-13T07:48:09.278-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-13T07:48:09.278-08:00</app:edited><title>Vision</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;For quite some time, I had been struggling with choosing a name for this blog mainly because of a lack of vision as to what I want it to be. I could not point to my blog and say that this is what differentiates it from the gazillion other blogs out there on the internet.&lt;br /&gt;
But now, I have decided to give it a more concrete shape, an identity. This blog will continue to discuss algorithmic questions but I won't limit it to that only - this blog will also be a motivational blog. Thanks to my friend Pragya Agarwal for giving me the inspiration to take this step.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7486773803503258327-7666755317912499150?l=manjotpahwa.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/R60nPxErx4b2wbNHHVJMf7CCH3o/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/R60nPxErx4b2wbNHHVJMf7CCH3o/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/R60nPxErx4b2wbNHHVJMf7CCH3o/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/R60nPxErx4b2wbNHHVJMf7CCH3o/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/KiwTH/~4/Tla7sW_jZxg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manjotpahwa.blogspot.com/feeds/7666755317912499150/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7486773803503258327&amp;postID=7666755317912499150&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/7666755317912499150?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/7666755317912499150?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/KiwTH/~3/Tla7sW_jZxg/vision.html" title="Vision" /><author><name>Manjot Pahwa</name><uri>http://www.blogger.com/profile/01321615468772658065</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/-yvlwnl1IC58/Tu3IyRTw0tI/AAAAAAAAB5Q/efTRLy7YTMg/s220/IMG_1804000.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://manjotpahwa.blogspot.com/2012/01/vision.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkMER3g6cCp7ImA9WhRWE0U.&quot;"><id>tag:blogger.com,1999:blog-7486773803503258327.post-2969301356434736227</id><published>2011-12-31T19:26:00.000-08:00</published><updated>2011-12-31T19:26:46.618-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-31T19:26:46.618-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="reverse" /><category scheme="http://www.blogger.com/atom/ns#" term="linked" /><category scheme="http://www.blogger.com/atom/ns#" term="list" /><category scheme="http://www.blogger.com/atom/ns#" term="print" /><title>How To Print a Linked List in Reverse Order</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;The question is simple, print the contents of a linked list in reverse order. The question can be easily solved, the trick (as always) is to solve it efficiently. Let's first analyze the minimum time complexity that can be achieved. Since we have to print the contents of the list, the tie complexity cannot be lesser than O(n) where n is the number of nodes. The minimum space complexity can be O(1) which will be achieved as I move further and further.&lt;br /&gt;
&lt;br /&gt;
The first and easiest way to think about solving this problem is recursion. Observe the following code (warning - all untested code):&lt;br /&gt;
&lt;br /&gt;
void printRev(Node * root)&lt;br /&gt;
{&lt;br /&gt;
if(root==NULL)&lt;br /&gt;
return;&lt;br /&gt;
printRev(root-&amp;gt;next);&lt;br /&gt;
printf("%d", &amp;amp;root-&amp;gt;info);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
But the usual problem with recursion - it uses stack space which we don't want it to. Moreover you might run out of space.&lt;br /&gt;
&lt;br /&gt;
So a method I could come up with of O(n) tie complexity and O(1) space complexity is reversing the linked list, printing the info in the normal order and then reversing the linked list again (to ensure you've not changed your actual data). Since we are reversing and want to have O(1) space complexity obviously we cannot use a method for reversing that utilizes space greater than O(1). Hence I'm using the three pointer method to reverse the linked list.&lt;br /&gt;
The code for reversing and then printing:&lt;br /&gt;
&lt;br /&gt;
void RevLL(Node * head)&lt;br /&gt;
{&lt;br /&gt;
Node *p, *q, *r;&lt;br /&gt;
if(head == NULL)&lt;br /&gt;
{&lt;br /&gt;
return;&lt;br /&gt;
}&lt;br /&gt;
p = head;&lt;br /&gt;
q = p-&amp;gt;next;&lt;br /&gt;
p-&amp;gt;next = NULL;&lt;br /&gt;
while (q != NULL)&lt;br /&gt;
{&lt;br /&gt;
r = q-&amp;gt;next;&lt;br /&gt;
q-&amp;gt;next = p;&lt;br /&gt;
p = q;&lt;br /&gt;
q = r;&lt;br /&gt;
}&lt;br /&gt;
head = p;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void printLL(Node * head)&lt;br /&gt;
{&lt;br /&gt;
if(head==NULL)&lt;br /&gt;
return;&lt;br /&gt;
Node * tmp= head;&lt;br /&gt;
while(tmp!=NULL){&lt;br /&gt;
printf("%d", tmp-&amp;gt;info);&lt;br /&gt;
tmp=tmp-&amp;gt;next;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
void printRev(Node * head)&lt;br /&gt;
{&lt;br /&gt;
RevLL(head);&lt;br /&gt;
printLL(head);&lt;br /&gt;
RevLL(head);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Again a warning, the above code is untested and there will probably be bugs in it but my main intention was to develop the algorithm.&lt;br /&gt;
If someone has an idea to print the contents in reverse order without reversing the linked list and in one pass, they're very welcome.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7486773803503258327-2969301356434736227?l=manjotpahwa.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/mPz925M9A0jbxYnZ3-lqXJp5iiY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/mPz925M9A0jbxYnZ3-lqXJp5iiY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/mPz925M9A0jbxYnZ3-lqXJp5iiY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/mPz925M9A0jbxYnZ3-lqXJp5iiY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/KiwTH/~4/ySQo0MLGmXs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manjotpahwa.blogspot.com/feeds/2969301356434736227/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7486773803503258327&amp;postID=2969301356434736227&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/2969301356434736227?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/2969301356434736227?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/KiwTH/~3/ySQo0MLGmXs/how-to-print-linked-list-in-reverse.html" title="How To Print a Linked List in Reverse Order" /><author><name>Manjot Pahwa</name><uri>http://www.blogger.com/profile/01321615468772658065</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/-yvlwnl1IC58/Tu3IyRTw0tI/AAAAAAAAB5Q/efTRLy7YTMg/s220/IMG_1804000.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://manjotpahwa.blogspot.com/2011/12/how-to-print-linked-list-in-reverse.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkMER3w9fip7ImA9WhRVE0s.&quot;"><id>tag:blogger.com,1999:blog-7486773803503258327.post-5270105688681364230</id><published>2011-12-31T01:45:00.000-08:00</published><updated>2012-01-12T02:33:26.266-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-12T02:33:26.266-08:00</app:edited><title>The Year in Retrospect</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;As this year comes to a dramatic end, I’d like to say it has been a year of great personal learning.&lt;br /&gt;
I would like to thank everyone instrumental in helping me realize certain very important things in life, the first of which is –you can’t always get what you want but remember that you might just deserve better. Don’t ever doubt yourself, especially not for people who don’t understand you. Don’t let them break you.&lt;br /&gt;
Measure your own worth and don't let anyone underestimate that.&lt;br /&gt;
Don't make anyone a priority if you're just an option for them. Let this line sink in, before it gets late. &lt;br /&gt;
Sure it hurts to see your commitment and your fidelity to someone or something go to waste. But learn from it, analyze where you went wrong. Learn how to not repeat the same mistakes. Your faith deserves to be in better hands.&lt;br /&gt;
Take care of your character and your reputation will take care of itself.&lt;br /&gt;
Learn to look at life from another person's perspective. You cannot look at another's actions from a tainted glass just to prove your point. What might be moral for you, might be immoral for another human being.&lt;br /&gt;
Don't emulate false idols. Obsessing over the phonies doesn't teach you anything and ignoring people who matter for those phonies is atrocious.&lt;br /&gt;
If you believe you will have a deep and meaningful association with someone, pursue it and don't hesitate to take the first step. Sometimes, you meet true friends around unexpected corners. Value them.&lt;br /&gt;
Life teaches a lot, learn from it. Everything plays its part even if something appears to be for the worse or a failure. Holding on to a broken past will only pinch more. Let the pain subside and wisdom derived from it prevail. You'll not be moving on with a baggage of failure but a life of wisdom and experience.&lt;br /&gt;
As I said last year, there’s a lot remaining, a lot to be achieved, a lot to be done, a lot to be learnt and a lot of fun :-)&lt;br /&gt;
Lastly, thank you all the followers of this blog and apologies for not posting more often. :-)&lt;br /&gt;
Happy New Year!&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;object class="BLOGGER-youtube-video" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" data-thumbnail-src="http://0.gvt0.com/vi/XIX0ZDqDljA/0.jpg" height="266" width="320"&gt;&lt;param name="movie" value="http://www.youtube.com/v/XIX0ZDqDljA&amp;fs=1&amp;source=uds" /&gt;&lt;param name="bgcolor" value="#FFFFFF" /&gt;&lt;embed width="320" height="266"  src="http://www.youtube.com/v/XIX0ZDqDljA&amp;fs=1&amp;source=uds" type="application/x-shockwave-flash"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7486773803503258327-5270105688681364230?l=manjotpahwa.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ixqHCHU85uplZotGizeSwxTy-d0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ixqHCHU85uplZotGizeSwxTy-d0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ixqHCHU85uplZotGizeSwxTy-d0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ixqHCHU85uplZotGizeSwxTy-d0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/KiwTH/~4/AK_G-CxRUpk" height="1" width="1"/&gt;</content><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/5270105688681364230?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/5270105688681364230?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/KiwTH/~3/AK_G-CxRUpk/year-in-retrospect.html" title="The Year in Retrospect" /><author><name>Manjot Pahwa</name><uri>http://www.blogger.com/profile/01321615468772658065</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/-yvlwnl1IC58/Tu3IyRTw0tI/AAAAAAAAB5Q/efTRLy7YTMg/s220/IMG_1804000.jpg" /></author><feedburner:origLink>http://manjotpahwa.blogspot.com/2011/12/year-in-retrospect.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkQMRnk5eip7ImA9WhRXF0k.&quot;"><id>tag:blogger.com,1999:blog-7486773803503258327.post-9195123676413987477</id><published>2011-12-24T08:30:00.001-08:00</published><updated>2011-12-24T08:33:07.722-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-24T08:33:07.722-08:00</app:edited><title>An Enlightening Thought</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span style="font-family: arial, sans-serif; font-size: 13px; text-align: -webkit-auto;"&gt;From some blog I follow:&lt;/span&gt;&lt;br /&gt;
&lt;div style="font-family: arial, sans-serif; font-size: 13px; text-align: -webkit-auto;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="font-family: arial, sans-serif; font-size: 13px; text-align: -webkit-auto;"&gt;A failure is a project that doesn't work, an initiative that teaches you something at the same time the outcome doesn't move you directly closer to your goal.&lt;/div&gt;&lt;div style="font-family: arial, sans-serif; font-size: 13px; text-align: -webkit-auto;"&gt;A mistake is either a failure repeated, doing something for the second time when you should have known better, or a misguided attempt (because of carelessness, selfishness or hubris) that hindsight reminds you is worth avoiding.&lt;/div&gt;&lt;div style="font-family: arial, sans-serif; font-size: 13px; text-align: -webkit-auto;"&gt;We need a lot more failures, I think. Failures that don't kill us make us bolder, and teach us one more way that won't work, while opening the door to things that might.&lt;/div&gt;&lt;div style="font-family: arial, sans-serif; font-size: 13px; text-align: -webkit-auto;"&gt;School confuses us, so do bosses and families. Go ahead, fail. Try to avoid mistakes, though.&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7486773803503258327-9195123676413987477?l=manjotpahwa.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/22t67x1k5VcxRkEqp8bYc_cuhxo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/22t67x1k5VcxRkEqp8bYc_cuhxo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/22t67x1k5VcxRkEqp8bYc_cuhxo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/22t67x1k5VcxRkEqp8bYc_cuhxo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/KiwTH/~4/LXtTLT2ik5E" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manjotpahwa.blogspot.com/feeds/9195123676413987477/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7486773803503258327&amp;postID=9195123676413987477&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/9195123676413987477?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/9195123676413987477?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/KiwTH/~3/LXtTLT2ik5E/enlightening-thought.html" title="An Enlightening Thought" /><author><name>Manjot Pahwa</name><uri>http://www.blogger.com/profile/01321615468772658065</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/-yvlwnl1IC58/Tu3IyRTw0tI/AAAAAAAAB5Q/efTRLy7YTMg/s220/IMG_1804000.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://manjotpahwa.blogspot.com/2011/12/enlightening-thought.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0IMQnk5eip7ImA9WhRXEkw.&quot;"><id>tag:blogger.com,1999:blog-7486773803503258327.post-6685188762992049730</id><published>2011-12-18T05:39:00.000-08:00</published><updated>2011-12-18T05:39:43.722-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-18T05:39:43.722-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="conference" /><category scheme="http://www.blogger.com/atom/ns#" term="hopper" /><category scheme="http://www.blogger.com/atom/ns#" term="grace" /><title>Grace Hopper Conference India</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I recently attended the second Grace Hopper Conference India. Definitely an experience worth having for all women engineers, the whole event was well organized, extremely well thought out, had some of the best women engineers under one roof and was for me as well as for many present over there, I'm sure, quite a learning and inspiring experience.&lt;br /&gt;
The keynote speeches were one of the highlights. Specifically I would like to point out to the speech given by Dr. Sunita Maheshwari,&amp;nbsp;Senior Consultant Pediatric Cardiologist and Chief Dreamer, RXDX and Teleradiology Solutions. Her speech showed how people from a completely academic background can also become successful entrepreneurs. If you haven't seen it already, I highly recommend it. I will post the links once I get them.&lt;br /&gt;
The sessions were divided into tracks including Student track, New Career track, mid-level/Senior Management track, Program Management track, Strategy Management track, Academic Research track, Technical tracks. Each track had a Moderator and a panel. Interesting discussions some of them.&lt;br /&gt;
Another thing about which I'm very proud is that a girl from my class in my college, Vrinda Vasisth, won the technical student "Are the Queen of Geekdom" contest from among 35 students. Hearty Congratulations to you Vrinda, you did the college proud :)&lt;br /&gt;
Another highlight of the conference was the Women Entrepreneur Quest with finalists who had some brilliant ideas for startups. I will talk more about this Entrepreneur Quest in a later blog post. The winner was a woman who had developed a website for the overall management of apartment societies.&lt;br /&gt;
Further information can be found &lt;a href="http://gracehopper.org.in/2011/"&gt;here&lt;/a&gt;.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7486773803503258327-6685188762992049730?l=manjotpahwa.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/7W_gxFHOqyuZDoKRoyAy3QYban4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/7W_gxFHOqyuZDoKRoyAy3QYban4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/7W_gxFHOqyuZDoKRoyAy3QYban4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/7W_gxFHOqyuZDoKRoyAy3QYban4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/KiwTH/~4/IBzI2iyVY_M" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manjotpahwa.blogspot.com/feeds/6685188762992049730/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7486773803503258327&amp;postID=6685188762992049730&amp;isPopup=true" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/6685188762992049730?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/6685188762992049730?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/KiwTH/~3/IBzI2iyVY_M/grace-hopper-conference-india.html" title="Grace Hopper Conference India" /><author><name>Manjot Pahwa</name><uri>http://www.blogger.com/profile/01321615468772658065</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/-yvlwnl1IC58/Tu3IyRTw0tI/AAAAAAAAB5Q/efTRLy7YTMg/s220/IMG_1804000.jpg" /></author><thr:total>2</thr:total><feedburner:origLink>http://manjotpahwa.blogspot.com/2011/12/grace-hopper-conference-india.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0AHRnY4cSp7ImA9WhRQEEU.&quot;"><id>tag:blogger.com,1999:blog-7486773803503258327.post-750982109385725087</id><published>2011-12-04T10:57:00.000-08:00</published><updated>2011-12-05T02:42:17.839-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-05T02:42:17.839-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="question" /><category scheme="http://www.blogger.com/atom/ns#" term="interview" /><category scheme="http://www.blogger.com/atom/ns#" term="facebook" /><title>My Facebook Question</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;The Facebook question (which I could not solve then because I forgot to add one silly line in between despite having the same algorithm :( ) that I had for the written round is as follows:&lt;br /&gt;
Given a word list of n strings of the same length l and a large string str, which contains a permutation of all of those words in the wordlist in one continuous sequence without changing the words themselves, find the index of the starting position of that permutation.&lt;br /&gt;
e.g. n = 2;&lt;br /&gt;
s[][] = {"you", "mel"}&lt;br /&gt;
str = "sbakdabskdyoumeldbkasbdas"&lt;br /&gt;
Index = 10&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
The algorithm I followed was simple. Construct a hash table for all the words in teh word list. Then using the same hash function, calculate has value for the same length of string in str and see whether it is in the table. If it is, match the actual string. If it matches, that means matching has started and now we need to see if the rest of the words are also there. If you don't find the next word in a continuous manner, then that means matching has not begun. So we start again, searching in the string.&lt;br /&gt;
The time complexity of my solution woudl be as follows:&lt;br /&gt;
Assume length of str is 'm'. Assume length of each word in word list is 'l'. Then the time complexity is O(m*l + n*l).&lt;br /&gt;
Space would be required for the hash table. I have taken it to be a bit larger than the maximum number of words expected (to reduce the possibility of a hash collision).&lt;br /&gt;
I am posting teh code as well for this one. I just wish I could have solved this one at that time. But no excuses. We live to fight another day.&lt;br /&gt;
&lt;br /&gt;
If anyone of you has any better algorithm or can point out any bugs in the code, it would be welcome. :)&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;pre class="cpp" name="code"&gt;#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;stdlib.h&amp;gt;
#include&amp;lt;string.h&amp;gt;
#define FOR(i, a) for(i=0; i&amp;lt;a; i++)
#define MAXW 10
#define MAXH 1000

int table[MAXH] = {0};

void CalcHash(char s[][MAXW], int n, int l)
{
    int hash_key=0;
    int i, j;
    FOR(i, n){
        FOR(j, l){
            hash_key = (hash_key*10 + s[i][j]-'\0')%MAXH;
        }
        hash_key=hash_key%MAXH;
        table[hash_key] = i;
        hash_key=0;
    }
}

int CalcHashStr(char s[], int l)
{
    int i, hash_key;
    FOR(i, l){
        hash_key = (hash_key*10 + s[i]-'\0')%MAXH;
    }
    return (hash_key)%MAXH;
}

int CheckActualMatch(char *str, char *s, int l)
{
    int i=0;
    FOR(i, l){
        if(str[i]!=s[i])
            return 0;
    }
    return 1;
}

int CalcIdx(char s[][MAXW], char str[], int n, int l)
{
    int i, MatchStarted=0, Idx=-1, count=0, check_hash;
    CalcHash(s, n, l);

    i=0;
    while(i&amp;lt;strlen(str)){
        check_hash = CalcHashStr((str+i), l);

        if((table[check_hash]!=-1) &amp;&amp; (MatchStarted==0)){
//            printf("1\n");

            if(CheckActualMatch(str+i, s[table[check_hash]], l)){
//                printf("11\n");
                MatchStarted=1;
                Idx=i;
                i=i+l;
                count++;
                continue;
                }
                else{
//                    printf("12\n");
                    MatchStarted=0;
                    Idx=-1;
                    count=0;
                    i++;
                    continue;
                }
        }
        else if((table[check_hash]!=-1) &amp;&amp; (MatchStarted==1)){
  //          printf("2\n");
            if(CheckActualMatch(str+i, s[table[check_hash]], l)){
//                printf("21\n");
                i=i+l;
                count++;
                continue;
                }
            else{
//                printf("22\n");
                MatchStarted=0;
                Idx=-1;
                count=0;
                i++;
                continue;
                }
        }
        else if(count==n){
//            printf("3\n");
            return Idx;
        }
        else if(table[check_hash]==-1){
//            printf("4\n");
            MatchStarted=0;
            Idx=-1;
            count=0;
            i++;
            continue;
        }
    }
    return Idx;
}

int main()
{
    int i;
    char str[] = "acdsatcatratjahs";
    char s[3][10] = {
        "cat",
        "rat",
        "sat"
    };
    FOR(i, MAXH){
        table[i]=-1;
    }
    printf("%d\n", CalcIdx(s, str, 3, 3));
    return 0;
}


&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7486773803503258327-750982109385725087?l=manjotpahwa.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/oJEMdHy6pAywTMkxeha1x1Gsg3w/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/oJEMdHy6pAywTMkxeha1x1Gsg3w/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/oJEMdHy6pAywTMkxeha1x1Gsg3w/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/oJEMdHy6pAywTMkxeha1x1Gsg3w/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/KiwTH/~4/kkJOdJUtDzE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manjotpahwa.blogspot.com/feeds/750982109385725087/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7486773803503258327&amp;postID=750982109385725087&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/750982109385725087?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/750982109385725087?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/KiwTH/~3/kkJOdJUtDzE/my-facebook-question.html" title="My Facebook Question" /><author><name>Manjot Pahwa</name><uri>http://www.blogger.com/profile/01321615468772658065</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/-yvlwnl1IC58/Tu3IyRTw0tI/AAAAAAAAB5Q/efTRLy7YTMg/s220/IMG_1804000.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://manjotpahwa.blogspot.com/2011/12/my-facebook-question.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEYCQHk9fSp7ImA9WhRTGEg.&quot;"><id>tag:blogger.com,1999:blog-7486773803503258327.post-1924826893953548362</id><published>2011-11-09T08:29:00.000-08:00</published><updated>2011-11-09T08:29:21.765-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-09T08:29:21.765-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="interview" /><category scheme="http://www.blogger.com/atom/ns#" term="facebook" /><title>My Facebook Experience</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I recently gave an exam for Facebook. The process is as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;First there is an online test. Usually there is one programming question that is to be answered. The question concentrates on algorithms and datastructures. The time limit for it is about 60 minutes or 90 minutes depending on the question.&lt;br /&gt;
After you qualify the online test, you receive a call from Facebook and a phone interview is set up with one of their engineers. This interview again lasts for about an hour and you have to code online a solution to the question &amp;nbsp;asked by the engineer while talking to him. You will have to optimize your code and remove bugs, etc. And explain your whole approach well.&lt;br /&gt;
If you qualify this telephonic screening round, you are called to Palo Alto for an on-site interview.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7486773803503258327-1924826893953548362?l=manjotpahwa.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/oVtl_inngTXYW_jNtQcFQJVvNi8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/oVtl_inngTXYW_jNtQcFQJVvNi8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/oVtl_inngTXYW_jNtQcFQJVvNi8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/oVtl_inngTXYW_jNtQcFQJVvNi8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/KiwTH/~4/WQiGc6se93Q" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manjotpahwa.blogspot.com/feeds/1924826893953548362/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7486773803503258327&amp;postID=1924826893953548362&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/1924826893953548362?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/1924826893953548362?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/KiwTH/~3/WQiGc6se93Q/my-facebook-experience.html" title="My Facebook Experience" /><author><name>Manjot Pahwa</name><uri>http://www.blogger.com/profile/01321615468772658065</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/-yvlwnl1IC58/Tu3IyRTw0tI/AAAAAAAAB5Q/efTRLy7YTMg/s220/IMG_1804000.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://manjotpahwa.blogspot.com/2011/11/my-facebook-experience.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEQGSHo-eyp7ImA9WhdUFEg.&quot;"><id>tag:blogger.com,1999:blog-7486773803503258327.post-1730482119588459309</id><published>2011-10-01T01:05:00.000-07:00</published><updated>2011-10-01T01:05:29.453-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-01T01:05:29.453-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="algorithm" /><category scheme="http://www.blogger.com/atom/ns#" term="game" /><category scheme="http://www.blogger.com/atom/ns#" term="conway" /><category scheme="http://www.blogger.com/atom/ns#" term="of" /><category scheme="http://www.blogger.com/atom/ns#" term="llife" /><title>Conway's Game of Life</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;a href="http://en.wikipedia.org/wiki/Conway's_Game_of_Life"&gt;Conway's Game of Life&lt;/a&gt; is a very famous problem in cellular automata. It is a zero player game which means no input is required, just a few rules and then evolution is determined by the initial state and the rules that define the existence.&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;The usual rules are described as follows. At each step in time, the following transitions occur:&lt;br /&gt;
&lt;br /&gt;
&lt;ol style="text-align: left;"&gt;&lt;li&gt;Any live cell with fewer than two live neighbours dies, as if caused by under-population.&lt;/li&gt;
&lt;li&gt;Any live cell with two or three live neighbours lives on to the next generation.&lt;/li&gt;
&lt;li&gt;Any live cell with more than three live neighbours dies, as if by overcrowding.&lt;/li&gt;
&lt;li&gt;Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.&lt;/li&gt;
&lt;/ol&gt;&lt;div&gt;Initial pattern is known as the seed and at every step, the rules are applied again and again to see the evolution process.&lt;/div&gt;&lt;div&gt;Today I will be discussing the algorithmic implementation of this problem.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Input: A board describing the initial state of the system.&lt;/div&gt;&lt;div&gt;Output: It is continuously displayed showing the state of the system at every step. It can be in various ways, either an applet or an animation or just the static output of the system displaying the state of the system after a particular number of steps.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Datastructure to be Used: It can be a board of NxN (N specified by user) with each cell/node denoting whether the cell is alive, dead or empty. Call this Board[1...N][1...N]. Keep another such datastructure in hand known as NextState[1...N][1...N] and initially this structure has the same entries as Board[][].&lt;/div&gt;&lt;div&gt;Algorithm:&amp;nbsp;&lt;/div&gt;&lt;div&gt;1. Call a function which checks the state of the system for satisfaction of any of the rules above stated. If any rule is satisfied, then update the changes in the NextState[][] structure.&amp;nbsp;&lt;/div&gt;&lt;div&gt;2. After the changes have been made to the NextState[][] structure, call another fucntion FormNextGeneration() which updates Board[][] with values in NextState[][]. Board[][] now has the next state values in it.&lt;/div&gt;&lt;div&gt;3. To display these values or state of the system just call a function Display() which has the applet or simply sends the state to stdin.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Hence we have successfully implemented a simple version of Conway's Game of Life.&lt;/div&gt;&lt;div&gt;The complex version involves many other rules for reproduction, mutation, extinction et al.&amp;nbsp;&lt;/div&gt;&lt;div&gt;Hope this one helped! :)&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7486773803503258327-1730482119588459309?l=manjotpahwa.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/dwXzpTkd9FGXzbfNPUvOS9b6SMY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/dwXzpTkd9FGXzbfNPUvOS9b6SMY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/dwXzpTkd9FGXzbfNPUvOS9b6SMY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/dwXzpTkd9FGXzbfNPUvOS9b6SMY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/KiwTH/~4/7KNGkH4_B-4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manjotpahwa.blogspot.com/feeds/1730482119588459309/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7486773803503258327&amp;postID=1730482119588459309&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/1730482119588459309?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/1730482119588459309?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/KiwTH/~3/7KNGkH4_B-4/conways-game-of-life.html" title="Conway's Game of Life" /><author><name>Manjot Pahwa</name><uri>http://www.blogger.com/profile/01321615468772658065</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/-yvlwnl1IC58/Tu3IyRTw0tI/AAAAAAAAB5Q/efTRLy7YTMg/s220/IMG_1804000.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://manjotpahwa.blogspot.com/2011/10/conways-game-of-life.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkUEQnk5eSp7ImA9WhdUFE0.&quot;"><id>tag:blogger.com,1999:blog-7486773803503258327.post-6865417067924584733</id><published>2011-09-30T09:30:00.000-07:00</published><updated>2011-09-30T09:30:03.721-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-30T09:30:03.721-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="machine" /><category scheme="http://www.blogger.com/atom/ns#" term="norvig" /><category scheme="http://www.blogger.com/atom/ns#" term="stanford" /><category scheme="http://www.blogger.com/atom/ns#" term="online" /><category scheme="http://www.blogger.com/atom/ns#" term="andrew ng" /><category scheme="http://www.blogger.com/atom/ns#" term="classes" /><category scheme="http://www.blogger.com/atom/ns#" term="learning" /><category scheme="http://www.blogger.com/atom/ns#" term="thrun" /><category scheme="http://www.blogger.com/atom/ns#" term="intelligence" /><category scheme="http://www.blogger.com/atom/ns#" term="artificial" /><title>An Important Announcement!</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Hey, there is some good news I have to share. Stanford School of Engineering has made some of its classes available online.&lt;br /&gt;
You can register for them here: ml-class.org (for Machine Learning)&lt;br /&gt;
ai-class.com (for Artificial Intelligence)&lt;br /&gt;
&lt;br /&gt;
I would seriously advise you to register for at least the basic courses. They have some really good material explained extremely well by some of teh really good researchers at Stanford like Andrew Ng&amp;nbsp;(Professor at Stanford)&amp;nbsp;for Machine Learning and Sebastian Thrun (Professor at Stanford) &amp;amp; Peter Norvig (works at Google as Director of Research).&amp;nbsp;These people have done some commendable work in this field and I would definitely advise you to read some of their papers and/or their books in order to familiarize yourself with this field.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7486773803503258327-6865417067924584733?l=manjotpahwa.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/3J1ZrBMV2UcsRXSj_E8SoDJAl_c/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3J1ZrBMV2UcsRXSj_E8SoDJAl_c/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/3J1ZrBMV2UcsRXSj_E8SoDJAl_c/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3J1ZrBMV2UcsRXSj_E8SoDJAl_c/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/KiwTH/~4/lHsqwcO9mP4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manjotpahwa.blogspot.com/feeds/6865417067924584733/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7486773803503258327&amp;postID=6865417067924584733&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/6865417067924584733?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/6865417067924584733?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/KiwTH/~3/lHsqwcO9mP4/important-announcement.html" title="An Important Announcement!" /><author><name>Manjot Pahwa</name><uri>http://www.blogger.com/profile/01321615468772658065</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/-yvlwnl1IC58/Tu3IyRTw0tI/AAAAAAAAB5Q/efTRLy7YTMg/s220/IMG_1804000.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://manjotpahwa.blogspot.com/2011/09/important-announcement.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkUEQnc-cSp7ImA9WhdWEkw.&quot;"><id>tag:blogger.com,1999:blog-7486773803503258327.post-7273901861798014870</id><published>2011-09-04T21:25:00.000-07:00</published><updated>2011-09-05T02:16:43.959-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-05T02:16:43.959-07:00</app:edited><title>What Just Happened Back in There?</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Why O why?!&lt;br /&gt;
I did well, didn't I? Nothing went wrong. Well might not be enough.&lt;br /&gt;
Still, don't have any regrets or anger at myself at least.&lt;br /&gt;
Ah, maybe another day. We'll all float on alright.&lt;br /&gt;
(Sorry people this is pretty much random.)&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7486773803503258327-7273901861798014870?l=manjotpahwa.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/zQc8vBoJZhEWRw2Ja5DE4m1l_KM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zQc8vBoJZhEWRw2Ja5DE4m1l_KM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/zQc8vBoJZhEWRw2Ja5DE4m1l_KM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zQc8vBoJZhEWRw2Ja5DE4m1l_KM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/KiwTH/~4/1oaRvo_uZXI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manjotpahwa.blogspot.com/feeds/7273901861798014870/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7486773803503258327&amp;postID=7273901861798014870&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/7273901861798014870?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/7273901861798014870?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/KiwTH/~3/1oaRvo_uZXI/blog-post.html" title="What Just Happened Back in There?" /><author><name>Manjot Pahwa</name><uri>http://www.blogger.com/profile/01321615468772658065</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/-yvlwnl1IC58/Tu3IyRTw0tI/AAAAAAAAB5Q/efTRLy7YTMg/s220/IMG_1804000.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://manjotpahwa.blogspot.com/2011/09/blog-post.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0ENRX8zfCp7ImA9WhdWFUs.&quot;"><id>tag:blogger.com,1999:blog-7486773803503258327.post-2910744393995758105</id><published>2011-08-31T05:17:00.000-07:00</published><updated>2011-09-09T03:54:54.184-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-09T03:54:54.184-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="professional" /><category scheme="http://www.blogger.com/atom/ns#" term="code" /><category scheme="http://www.blogger.com/atom/ns#" term="writing" /><title>Importance of Writing Professional Code</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Sorry for not writing in a long time, recently gave my TOEFL exam but that wasn't the only reason for my absence. :)&lt;br /&gt;
So, coming back to the main topic, today I will talk about the importance of writing professional code and little little things that can help you how to walk that path.&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Many people would argue that this is a completely futile post as they may have the opinion, "I can code, how does it matter where I leave space or whether I indent it or not!". There is no argument with the fact that it is of utmost importance to know how to code. But it is also important that other people be able to easily understand and develop over your code because when you work for a company, you ill not be developing every single thing from scratch. Inevitably, you will be using code developed by others and you will develop code that will be used by others. Because of this simple reason, it is very important that your code be easy to understand and trace through.&lt;br /&gt;
Secondly, it will be easier for you as well to understand your own code after some time. Yes, this does happen, at least it happened with me! I couldn't understand my own code after some time.&lt;br /&gt;
So here are a few things to keep in mind:&lt;br /&gt;
1. DO NOT write the function which computes the result in main. This is one of the most common mistakes that beginners make, I used to do that as well. Main is there to call functions which compute your result and not to actually perform the grunt work.&lt;br /&gt;
2. Make your code as modular as possible. If you have an algorithm which computes the answer using different algorithms/steps, you can have separate functions. This even helps in reducing the amount of code you have to write. How? e.g. if I want to write code for finding out the height of a tree, I will first construct the tree and add a few nodes. I don't need to write that part of the code again if I have a function previously coded already, I can just copy and paste.&lt;br /&gt;
3. This is again one of the most ignored basic rules of writing good code, make your variable names, function names, etc. extremely descriptive of what they represent. Even if it makes the name longer. Having numNodes is much better than 'n'. Having IsBalancedBST() is much easier to understand than ibbst() or any other short uninformative name. This helps a lot in remembering what those variables and/or functions represent and you can understand what a function does by just looking at its name. Makes life easier, doesn't it?&lt;br /&gt;
&lt;br /&gt;
These are the only ones I could think of right now. If I come up with more, I will mention them later.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7486773803503258327-2910744393995758105?l=manjotpahwa.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/vRCA6SxnlJJPq7dNBIIowyjdOj4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vRCA6SxnlJJPq7dNBIIowyjdOj4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/vRCA6SxnlJJPq7dNBIIowyjdOj4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vRCA6SxnlJJPq7dNBIIowyjdOj4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/KiwTH/~4/_zoAKCqhRCw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manjotpahwa.blogspot.com/feeds/2910744393995758105/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7486773803503258327&amp;postID=2910744393995758105&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/2910744393995758105?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/2910744393995758105?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/KiwTH/~3/_zoAKCqhRCw/importance-of-writing-professional-code.html" title="Importance of Writing Professional Code" /><author><name>Manjot Pahwa</name><uri>http://www.blogger.com/profile/01321615468772658065</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/-yvlwnl1IC58/Tu3IyRTw0tI/AAAAAAAAB5Q/efTRLy7YTMg/s220/IMG_1804000.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://manjotpahwa.blogspot.com/2011/08/importance-of-writing-professional-code.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0AGSX4_eSp7ImA9WhdWFUs.&quot;"><id>tag:blogger.com,1999:blog-7486773803503258327.post-5741315531769953172</id><published>2011-08-14T00:11:00.000-07:00</published><updated>2011-09-09T03:55:28.041-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-09T03:55:28.041-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="data" /><category scheme="http://www.blogger.com/atom/ns#" term="structure" /><category scheme="http://www.blogger.com/atom/ns#" term="cormen" /><category scheme="http://www.blogger.com/atom/ns#" term="lcrs" /><category scheme="http://www.blogger.com/atom/ns#" term="books" /><category scheme="http://www.blogger.com/atom/ns#" term="algorithm" /><category scheme="http://www.blogger.com/atom/ns#" term="tanenbaum" /><title>The Tanenbaum V/S Cormen Debate</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Before I begin this post I would like to point out that the opinions expressed in this post are solely mine. This strategy worked for me doesn't mean it will work for everyone. Everyone be the better judge for himself.&lt;br /&gt;
So this question has come up several times in the mind of freshmen et al in the field of computer science whether to study from the book Data Structures by Tanenbaum or Introduction to Algorithms by&amp;nbsp;Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein.&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;People usually prefer the pure clear explanation given by Cormen rather than the lengthy discussion given by Tanenbaum. Tanenbaum treats the problem at every level and describes an indepth analysis of the solution presented (which comprises of complete code) and then discusses further modification which can improve the implementation even further. Cormen (LCRS) on the other hand describes the algorithm straight away and provides pseudocode. It does not delve into a deep discussion of the data structure or algorithm in question like Tanenbaum does. Even though I prefer reading the pseudocode to the actual code, I personally prefer the book Tanenbaum and studying from it has what made the difference for me (caveat: many people would differ from me saying that Tanenbaum is actually an extremely boring book which they don't feel like studying from so decide for yourself). Tanenbaum not only describes the data structure and its implementation, the operations that would be performed on it, etc but also discusses the data structure from an application point of view. This is where the difference comes in. By studying from Cormen you will easily be able to learn a data structure, algorithms associated with it but when it comes to a real life problem when you actually have to act as an engineer, you would need to think really hard in order to understand where all can this particular data structure be used and where all it should be used. Tanenbaum even discusses real life problem by providing an example of queues in a bank in the chapter on Linked Lists and then he discusses a scheduling problem and solves it with the help of graphs in the chapter Graphs. All of these topics most of the people don't even study but these examples help to develop a thinking with regard to its applications in a real world.&lt;br /&gt;
Of course, sometimes it is just too difficult to study from the verbose style that Tanenbaum has (Initially even I was stuck in several places). In that case, one can study the algorithm and data structure from Cormen first and then go over Tanenbaum.&lt;br /&gt;
Ultimately it depends on your learning style. Some people just can't study that much verbose text, they might want only clear cut pseudocode. I draw an analogy here by saying that I prefer reading classics while most people don't. So this really is a subjective thing.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7486773803503258327-5741315531769953172?l=manjotpahwa.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/NugQe7UC5smdSdNPy_88GqCH-_0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/NugQe7UC5smdSdNPy_88GqCH-_0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/NugQe7UC5smdSdNPy_88GqCH-_0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/NugQe7UC5smdSdNPy_88GqCH-_0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/KiwTH/~4/EhwxHViColk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manjotpahwa.blogspot.com/feeds/5741315531769953172/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7486773803503258327&amp;postID=5741315531769953172&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/5741315531769953172?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/5741315531769953172?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/KiwTH/~3/EhwxHViColk/tanenbaum-vs-cormen-debate.html" title="The Tanenbaum V/S Cormen Debate" /><author><name>Manjot Pahwa</name><uri>http://www.blogger.com/profile/01321615468772658065</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/-yvlwnl1IC58/Tu3IyRTw0tI/AAAAAAAAB5Q/efTRLy7YTMg/s220/IMG_1804000.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://manjotpahwa.blogspot.com/2011/08/tanenbaum-vs-cormen-debate.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0AASH04fSp7ImA9WhdWFUs.&quot;"><id>tag:blogger.com,1999:blog-7486773803503258327.post-5484918724089566453</id><published>2011-08-04T19:37:00.000-07:00</published><updated>2011-09-09T03:55:49.335-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-09T03:55:49.335-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="pahwa" /><category scheme="http://www.blogger.com/atom/ns#" term="nsit" /><category scheme="http://www.blogger.com/atom/ns#" term="manjot" /><title>Who Am I?</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I apologize friends, amidst all this coding I forgot to write an introductory paragraph about myself. Why should you even read my blog? And who am I to advise you?&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;I am a student of Netaji Subhas Institute of Technology, University of Delhi (this college ranks better than DCE if you are unaware of it) and currently in my senior year. I am a student of Computer Engineering. As ironical as it may sound, there are not many computer science courses in our syllabus for Computer Engineering so he students just have to learn and find out what to learn everything by themselves. So like the rest of the students in my college I started to research about different things in computer science from my second year onwards (my first year I spent watching movies and listening to bands if you really want to know :P). Computer science is such a vast field, SUCH a vast field that you have so many options whether you're into coding or just system analysis. Some of the different fields are&amp;nbsp;machine learning, data mining,&amp;nbsp;networking, if you're on the hardware side then architecture, or artificial intelligence if you are into the fun stuff (referred to as fun here because it's fun for me :) ), operating systems, database management systems, computer vision, natural language processing, computational neuroscience (another very interesting subject), and the list goes on.&lt;br /&gt;
I started to work in a startup in my second year and that is when I really got to know what's out there in the world, what all engineers are supposed to know, how much most of them actually know, how stuff works, et al.&lt;br /&gt;
I am really interested in machine learning and artificial intelligence. I have done projects in natural language processing and image processing. I am working currently on another project in the field of machine learning (more like thinking about the problem first). Details shall be posted once I'm ready with the implementation of the solution.&lt;br /&gt;
I have 2 publications as of now, one titled “A March Towards Constructivism based on Storytelling, Gaming and Collaboration”, Published at &lt;a href="http://linc.mit.edu/linc2010/proceedings.html"&gt;The Fifth International Conference of Learning International Networks Consortium&lt;/a&gt; (LINC), MIT &amp;nbsp;May 23rd – 26th 2010 and another one&amp;nbsp;titled "‘ShruthLaikh’: Employing Python to Develop Vocabulary Enhancing Application" describing the artificial intelligence techniques employed in the application at &lt;a href="http://ojs.pythonpapers.org/index.php/tppm/search/titles"&gt;Pycon Asia Pacific&lt;/a&gt;.&lt;br /&gt;
Furthermore I am recipient of &lt;a href="http://www.google.co.in/jobs/womeninengineering/index.html"&gt;Google Women in Engineering Award&lt;/a&gt;, 2011.&lt;br /&gt;
So despite the fact that I am not much of a coder, I believe I am a good solution developer and can develop systems components etc. well. I can think well from a higher view of the whole problem rather than the actual coding-level implementation. Which is why most of the time I work with MATLAB. C/C++ are the other two languages I work a lot with. We all have our strengths and weaknesses. I have mine too. And it's always good to know yours.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7486773803503258327-5484918724089566453?l=manjotpahwa.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/3xMp0m1KHIcr-FQi1cJRnYCkgSY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3xMp0m1KHIcr-FQi1cJRnYCkgSY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/3xMp0m1KHIcr-FQi1cJRnYCkgSY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3xMp0m1KHIcr-FQi1cJRnYCkgSY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/KiwTH/~4/WoSdTnshw_M" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manjotpahwa.blogspot.com/feeds/5484918724089566453/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7486773803503258327&amp;postID=5484918724089566453&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/5484918724089566453?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/5484918724089566453?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/KiwTH/~3/WoSdTnshw_M/who-am-i.html" title="Who Am I?" /><author><name>Manjot Pahwa</name><uri>http://www.blogger.com/profile/01321615468772658065</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/-yvlwnl1IC58/Tu3IyRTw0tI/AAAAAAAAB5Q/efTRLy7YTMg/s220/IMG_1804000.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://manjotpahwa.blogspot.com/2011/08/who-am-i.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0AMQnYyfyp7ImA9WhdWFUs.&quot;"><id>tag:blogger.com,1999:blog-7486773803503258327.post-3762532857575898275</id><published>2011-08-02T10:38:00.000-07:00</published><updated>2011-09-09T03:56:23.897-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-09T03:56:23.897-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="process" /><category scheme="http://www.blogger.com/atom/ns#" term="interview" /><category scheme="http://www.blogger.com/atom/ns#" term="algorithm" /><category scheme="http://www.blogger.com/atom/ns#" term="adobe" /><category scheme="http://www.blogger.com/atom/ns#" term="questions" /><title>How I Reached Adobe Final Round and Got Rejected :(</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;So basically there was a written round first in which there were 3 sections&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ol style="text-align: left;"&gt;&lt;li&gt;Quant &amp;amp;&amp;nbsp;Analytical (Puzzles) : Quant was pretty easy. Analytical took time but definitely not tough. Can be cracked. Just try to do some logical puzzles preferably from careercup&lt;/li&gt;
&lt;li&gt;C : This tested some basic knowledge of C. Do Test Your C Skills from Kanetkar and you'll do fine.&lt;/li&gt;
&lt;li&gt;Data Structures : This was the tricky part. No specified syllabus in this. Some questions were easy like reversing a linked list but some were difficult, algorithmic. Some required you to think a lot like the ones from Operating Systems. Do OS well, they ask from it a lot and that too all conceptual.&lt;/li&gt;
&lt;/ol&gt;&lt;div&gt;The written exam was given by around 140 people and 23 were selected for the interviews.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The interviews were basically 3 Technical and 1 HR although you can be eliminated before giving all 3 technical. My first round was pretty easy. I could solve most of the questions with time efficient solutions. 2nd round was more about resume and puzzles. And that too don't expect them to throw a puzzle at you right out of some book/website. They will ask for generalized solutions and you will have to think.&lt;/div&gt;&lt;div&gt;3rd round was the dip for me. Easy questions again but I didn't quite remember STL stuff of C otherwise there was not much to it.&lt;/div&gt;&lt;div&gt;After the 3rd round I wasn't called for the HR. End of story.&lt;/div&gt;&lt;div&gt;Anyway, may be some other day.&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7486773803503258327-3762532857575898275?l=manjotpahwa.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/0yFnoBGLkfEIp45WNz3gZ5w7Jb0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0yFnoBGLkfEIp45WNz3gZ5w7Jb0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/0yFnoBGLkfEIp45WNz3gZ5w7Jb0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0yFnoBGLkfEIp45WNz3gZ5w7Jb0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/KiwTH/~4/QP0Fb0n4z3A" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manjotpahwa.blogspot.com/feeds/3762532857575898275/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7486773803503258327&amp;postID=3762532857575898275&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/3762532857575898275?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/3762532857575898275?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/KiwTH/~3/QP0Fb0n4z3A/how-i-reached-adobe-final-round-and-got.html" title="How I Reached Adobe Final Round and Got Rejected :(" /><author><name>Manjot Pahwa</name><uri>http://www.blogger.com/profile/01321615468772658065</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/-yvlwnl1IC58/Tu3IyRTw0tI/AAAAAAAAB5Q/efTRLy7YTMg/s220/IMG_1804000.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://manjotpahwa.blogspot.com/2011/08/how-i-reached-adobe-final-round-and-got.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0EMRXo-fCp7ImA9WhdREEk.&quot;"><id>tag:blogger.com,1999:blog-7486773803503258327.post-3332277491521150884</id><published>2011-07-30T11:14:00.001-07:00</published><updated>2011-07-30T11:14:44.454-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-30T11:14:44.454-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="question" /><category scheme="http://www.blogger.com/atom/ns#" term="interview" /><category scheme="http://www.blogger.com/atom/ns#" term="algorithm" /><category scheme="http://www.blogger.com/atom/ns#" term="google" /><category scheme="http://www.blogger.com/atom/ns#" term="sort" /><category scheme="http://www.blogger.com/atom/ns#" term="microsoft" /><category scheme="http://www.blogger.com/atom/ns#" term="heap" /><title>Heap Sort</title><content type="html">This is another sorting algorithm working in O(nlogn) time. &lt;br /&gt;
&lt;br /&gt;
&lt;pre name="code" class="cpp"&gt;
//WORKING FINALLY! :)

#include&amp;lt;iostream&gt;
#include&amp;lt;stdlib.h&gt;
#include&amp;lt;stdio.h&gt;
#include&amp;lt;conio.h&gt;
#define MAXS 100
#define LEFT(i) (2*i+1)
#define RIGHT(i) (2*i+2)
#define PARENT(i) ((i-1)/2)
#define FOR(i, a) for(int i=0; i&amp;lt;a; i++)
using namespace std;

int HeapSize;

void SWAP(int *a, int *b)
{
     int tmp;
     tmp=(*a); (*a)=(*b); (*b)=tmp;
     }

void Heapify(int A[], int i)
{
     if(i&amp;lt;HeapSize){
         int l = LEFT(i);
         int r = RIGHT(i);
         int largest;
         if(l&amp;lt;HeapSize &amp;&amp; A[l]&gt;A[i])
                        largest = l;
         else largest = i;
         if(r&amp;lt;HeapSize &amp;&amp; A[r]&gt;A[largest])
                        largest = r;
         if(largest!=i){
                       SWAP(&amp;A[i], &amp;A[largest]);
                         Heapify(A, largest);
                       }
         }
         else return;
     }

void BuildHeap(int A[], int n)
{
     HeapSize = n;
     for(int i=(n-1)/2; i&gt;=0; i--){
            Heapify(A, i);
            }
     }

void HeapSort(int A[], int n)
{
     BuildHeap(A, n);
     for(int i=n-1; i&gt;=1; i--){
             SWAP(&amp;A[0], &amp;A[i]);
             HeapSize--;
             Heapify(A, 0);
             }
     FOR(i, n)
     cout&amp;lt;&amp;lt;A[i]&amp;lt;&amp;lt;endl;     
     }
int main()
{
    int A[] = {3, 61, 9, 2, 55, 100, 4};
    int n=7;
    HeapSort(A, 7);
    getch();
    }
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7486773803503258327-3332277491521150884?l=manjotpahwa.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Dv-GT8hYWl9BvzpVnE_Pm17yshg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Dv-GT8hYWl9BvzpVnE_Pm17yshg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Dv-GT8hYWl9BvzpVnE_Pm17yshg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Dv-GT8hYWl9BvzpVnE_Pm17yshg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/KiwTH/~4/vlN5nLQJ0U8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manjotpahwa.blogspot.com/feeds/3332277491521150884/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7486773803503258327&amp;postID=3332277491521150884&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/3332277491521150884?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/3332277491521150884?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/KiwTH/~3/vlN5nLQJ0U8/heap-sort.html" title="Heap Sort" /><author><name>Manjot Pahwa</name><uri>http://www.blogger.com/profile/01321615468772658065</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/-yvlwnl1IC58/Tu3IyRTw0tI/AAAAAAAAB5Q/efTRLy7YTMg/s220/IMG_1804000.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://manjotpahwa.blogspot.com/2011/07/heap-sort.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0QFRnk_eyp7ImA9WhdSGE4.&quot;"><id>tag:blogger.com,1999:blog-7486773803503258327.post-2991193877467920978</id><published>2011-07-20T05:50:00.000-07:00</published><updated>2011-07-28T00:48:37.743-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-28T00:48:37.743-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="young" /><category scheme="http://www.blogger.com/atom/ns#" term="algorithm" /><category scheme="http://www.blogger.com/atom/ns#" term="matrix" /><category scheme="http://www.blogger.com/atom/ns#" term="tableau" /><title>Young's Tableau (Matrix Sorted Row &amp; Column Wise)</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;br /&gt;
An m x n Young tableau is an m x n matrix such that the entries of each row are in sorted order&lt;br /&gt;
from left to right and the entries of each column are in sorted order from top to bottom. Some of the&lt;br /&gt;
entries of a Young tableau may be 1, which we treat as nonexistent elements. Thus a Young tableau&lt;br /&gt;
can be used to hold r &amp;lt;= mn numbers.&lt;br /&gt;
Given such a matrix, find an element in the best time.&lt;br /&gt;
&lt;br /&gt;
Searching for an element in Young's Tableau&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="cpp" name="code"&gt;//WORKING PERFECT!

#include&amp;lt;iostream&amp;gt;
#include&amp;lt;conio.h&amp;gt;
#include&amp;lt;cstring&amp;gt;
#include&amp;lt;cmath&amp;gt;
#define FOR(i, a) for(int i=0;i&amp;lt;a;i++)
#define MAXS 100
using namespace std;

bool SearchYoungTableau(int a[][MAXS], int *x, int *y, int ele, int m, int n)
{
*x = m-1;
*y = 0;
while((*x)&amp;lt;m &amp;amp;&amp;amp; (*y)&amp;lt;n){
if(a[*x][*y]==ele) {return true;}
if(a[*x][*y]&amp;gt;ele){ 
(*x)--; 
continue;
}
else if(a[*x][*y]&amp;lt;ele){
(*y)++;
continue;
}
}
return false;
}

int main()
{
int x, y;
int a[MAXS][MAXS];
a[0][0] = 1;
a[0][1] = 2;                    
a[1][0] = 3;
a[1][1] = 4;
cout&amp;lt;&amp;lt;SearchYoungTableau(a, &amp;amp;x, &amp;amp;y, 2, 2, 2)&amp;lt;&amp;lt;endl;
cout&amp;lt;&amp;lt;"x, y = "&amp;lt;&amp;lt;x&amp;lt;&amp;lt;", "&amp;lt;&amp;lt;y&amp;lt;&amp;lt;"\n";
getch();
return 0;
}

&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7486773803503258327-2991193877467920978?l=manjotpahwa.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/mfu_rhx47Z5USCdHN0SPKoHACwo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/mfu_rhx47Z5USCdHN0SPKoHACwo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/mfu_rhx47Z5USCdHN0SPKoHACwo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/mfu_rhx47Z5USCdHN0SPKoHACwo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/KiwTH/~4/A7-JgyHyESU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manjotpahwa.blogspot.com/feeds/2991193877467920978/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7486773803503258327&amp;postID=2991193877467920978&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/2991193877467920978?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/2991193877467920978?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/KiwTH/~3/A7-JgyHyESU/youngs-tableau.html" title="Young's Tableau (Matrix Sorted Row &amp; Column Wise)" /><author><name>Manjot Pahwa</name><uri>http://www.blogger.com/profile/01321615468772658065</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/-yvlwnl1IC58/Tu3IyRTw0tI/AAAAAAAAB5Q/efTRLy7YTMg/s220/IMG_1804000.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://manjotpahwa.blogspot.com/2011/07/youngs-tableau.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0MERn0-fip7ImA9WhdSGE4.&quot;"><id>tag:blogger.com,1999:blog-7486773803503258327.post-4909468793699190666</id><published>2011-07-20T05:44:00.000-07:00</published><updated>2011-07-28T00:50:07.356-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-28T00:50:07.356-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="binary" /><category scheme="http://www.blogger.com/atom/ns#" term="search" /><category scheme="http://www.blogger.com/atom/ns#" term="algorithm" /><category scheme="http://www.blogger.com/atom/ns#" term="tree" /><title>Sum of Nodes Which Have no Siblings Using Recursion</title><content type="html">Find the sum of all nodes in a BST which have no siblings.&lt;br /&gt;
&lt;br /&gt;
&lt;pre name="code" class="cpp"&gt;
//WORKING FNE

#include&amp;lt;iostream&gt;
#include&amp;lt;conio.h&gt;
#include&amp;lt;cstring&gt;
#include&amp;lt;cmath&gt;
#define FOR(i, a) for(int i=0;i&amp;lt;a;i++)
#define LEFT(i) (i*2+1)
#define RIGHT(i) (i*2+2)
#define MAXS 100
using namespace std;

struct node{  
int info;  
struct node *left, *right;  
};  
typedef struct node * N;  
N tree=NULL; 

N search(int x)  
{  
N p, q;  
p=tree;  
q=NULL;  
if(p==NULL) {cout&amp;lt;&amp;lt;"Not Found"; return NULL;}  
while(p!=NULL){  
q=p;  
if(p-&gt;info==x) {cout&amp;lt;&amp;lt;"Found\n"; return p;}  
p=(x&amp;lt;p-&gt;info)?(p-&gt;left):(p-&gt;right);  
}  
if(p==NULL &amp;&amp; q!=NULL) {cout&amp;lt;&amp;lt;"Not found\n"; return NULL;}  
}  

void insert(int x)  
{  
N p, q, tmp;  
p=tree;  
q=NULL;  
tmp = (N)malloc(sizeof(struct node));  
tmp-&gt;info=x;  
tmp-&gt;left=NULL;  
tmp-&gt;right=NULL;  
if(p==NULL) {tree=tmp; return;}  
while(p!=NULL){  
q=p;  
p=(x&amp;lt;p-&gt;info)?(p-&gt;left):(p-&gt;right);  
}  
if(x&amp;lt;=q-&gt;info) {q-&gt;left=tmp; return;}  
else { q-&gt;right = tmp; return; }  
} 

int sum;

void SiblingSum(N root)
{
if(root==NULL || (root-&gt;left==NULL &amp;&amp; root-&gt;right==NULL))
return;
if((root-&gt;left==NULL) &amp;&amp; root-&gt;right!=NULL){
sum+=root-&gt;right-&gt;info;
SiblingSum(root-&gt;right);
}
else if((root-&gt;right==NULL) &amp;&amp; root-&gt;left!=NULL){
sum+=root-&gt;left-&gt;info;
SiblingSum(root-&gt;left);
}     
else{
SiblingSum(root-&gt;left);          
SiblingSum(root-&gt;right);                    
}
}

int main()  
{  
int ans, x, h, index;  
char * s, *t;
s = (char*)malloc(sizeof(char)*20);
do{  
cout&amp;lt;&amp;lt;"Choose\n1.Insert\n2.Find\n3.SiblingSum\n4.Height\n5.Diameter\n6.Exit\n";  
cin&gt;&gt;ans;  
if(ans==1){  
cin&gt;&gt;x;  
insert(x);  
}  
else if(ans==2){  
cin&gt;&gt;x;  
search(x);  
}  
else if(ans==3){  
SiblingSum(tree);  
cout&amp;lt;&amp;lt;sum&amp;lt;&amp;lt;endl;
sum=0;
} 
}while(ans!=6);  
getch();  
return 0;  
}  

&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7486773803503258327-4909468793699190666?l=manjotpahwa.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/4JXHOJmgh6dk1sC14uSNeVcylt4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4JXHOJmgh6dk1sC14uSNeVcylt4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/4JXHOJmgh6dk1sC14uSNeVcylt4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4JXHOJmgh6dk1sC14uSNeVcylt4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/KiwTH/~4/PnHNVv4XI7c" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manjotpahwa.blogspot.com/feeds/4909468793699190666/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7486773803503258327&amp;postID=4909468793699190666&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/4909468793699190666?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/4909468793699190666?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/KiwTH/~3/PnHNVv4XI7c/sum-of-nodes-which-have-no-siblings.html" title="Sum of Nodes Which Have no Siblings Using Recursion" /><author><name>Manjot Pahwa</name><uri>http://www.blogger.com/profile/01321615468772658065</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/-yvlwnl1IC58/Tu3IyRTw0tI/AAAAAAAAB5Q/efTRLy7YTMg/s220/IMG_1804000.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://manjotpahwa.blogspot.com/2011/07/sum-of-nodes-which-have-no-siblings.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkYBQHgyfCp7ImA9WhdQE00.&quot;"><id>tag:blogger.com,1999:blog-7486773803503258327.post-943893762702550145</id><published>2011-07-20T05:42:00.000-07:00</published><updated>2011-08-13T23:42:31.694-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-13T23:42:31.694-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="breadth" /><category scheme="http://www.blogger.com/atom/ns#" term="first" /><category scheme="http://www.blogger.com/atom/ns#" term="traversal" /><category scheme="http://www.blogger.com/atom/ns#" term="algorithm" /><category scheme="http://www.blogger.com/atom/ns#" term="graph" /><title>Breadth First Search of a Graph Using Adjacency Matrix</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;pre class="cpp" name="code"&gt;//WORKING!

#include&amp;lt;iostream&amp;gt;
#include&amp;lt;conio.h&amp;gt;
#include&amp;lt;cstring&amp;gt;
#include&amp;lt;cmath&amp;gt;
#define FOR(i, a) for(int i=0;i&amp;lt;a;i++)
#define MAXS 100
using namespace std;

int gMat[MAXS][MAXS], data[MAXS], visited[MAXS];

struct Queue{
int front, back;
int item[MAXS];
};
struct Queue q;

void EnQ(int j)
{
q.back++;
q.item[q.back] = j;
if(q.front==-1)
q.front=q.back;
return;
}

void init()
{
q.front=q.back=-1;
}

bool isEmpty()
{
return q.front==q.back;
}

int DeQ()
{
int tmp = q.item[q.front];
q.front++;
return tmp;
}

void BFS(int n)
{
int i=0;
EnQ(i);
while(!isEmpty()){
i = DeQ();
if(!visited[i])
printf("%d\n", data[i]);
visited[i]=1;
for(int j=0; j&amp;lt;n; j++){
if(gMat[i][j]){
EnQ(j);
}
}

}//while ends
}

int main()
{
int n;
cin&amp;gt;&amp;gt;n;
FOR(i, n)
FOR(j, n)
cin&amp;gt;&amp;gt;gMat[i][j];
FOR(i, n) cin&amp;gt;&amp;gt;data[i];
BFS(n);
getch();
}

&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7486773803503258327-943893762702550145?l=manjotpahwa.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/tVtlJV-dQnnDvO5bn3j3gbkZa4Q/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/tVtlJV-dQnnDvO5bn3j3gbkZa4Q/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/tVtlJV-dQnnDvO5bn3j3gbkZa4Q/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/tVtlJV-dQnnDvO5bn3j3gbkZa4Q/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/KiwTH/~4/BjCFWTxJfTc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manjotpahwa.blogspot.com/feeds/943893762702550145/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7486773803503258327&amp;postID=943893762702550145&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/943893762702550145?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/943893762702550145?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/KiwTH/~3/BjCFWTxJfTc/breadth-first-search-of-graph-using.html" title="Breadth First Search of a Graph Using Adjacency Matrix" /><author><name>Manjot Pahwa</name><uri>http://www.blogger.com/profile/01321615468772658065</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/-yvlwnl1IC58/Tu3IyRTw0tI/AAAAAAAAB5Q/efTRLy7YTMg/s220/IMG_1804000.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://manjotpahwa.blogspot.com/2011/07/breadth-first-search-of-graph-using.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkUNQXkyfSp7ImA9WhdQE00.&quot;"><id>tag:blogger.com,1999:blog-7486773803503258327.post-1004563724583525115</id><published>2011-07-20T05:40:00.000-07:00</published><updated>2011-08-13T23:44:50.795-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-13T23:44:50.795-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="data" /><category scheme="http://www.blogger.com/atom/ns#" term="structure" /><category scheme="http://www.blogger.com/atom/ns#" term="trie" /><category scheme="http://www.blogger.com/atom/ns#" term="implementation" /><title>Implementation of Trie</title><content type="html">This is the implementation of a trie which is a data structure that can reduce the time complexity of searching for a word to O(L) where L is the length of that particular word. This means that even if we have a dictionary with 45,000 words, searching time would still remain O(L). Pretty cool, isn't it!&lt;br /&gt;
&lt;br /&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;pre class="cpp" name="code"&gt;//Woohoo, this is working!
#include&amp;lt;iostream&amp;gt;
#include&amp;lt;stdlib.h&amp;gt;
#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;conio.h&amp;gt;
#define FOR(i, a) for(int i=0; i&amp;lt;a; i++)
using namespace std;

struct Trie{
int next[26];
};
typedef struct Trie T;
T nodes[1000];
static int last;

void addNode(char s[], int m)
{
int current = 0;
FOR(i, m){
if(nodes[current].next[s[i]-'a']==-1){
nodes[current].next[s[i]-'a'] = (last+1);
last++;
FOR(j, 26) nodes[last].next[j]=-1;
current = last;
}
else{
current = nodes[current].next[s[i]-'a'];
}
}
}

bool exists(char s[], int m)
{
int current = 0;
FOR(i, m){
if(nodes[current].next[s[i]-'a']==-1) return false;
else{
current = nodes[current].next[s[i]-'a'];
}
}
return true;
}

int main()
{
char s[20];
int ans;
int m;
FOR(i, 26)
nodes[0].next[i] = -1;
cin&amp;gt;&amp;gt;s&amp;gt;&amp;gt;m;
addNode(s, m);
do{
printf("What do you want to do?\n1.Enter a word\n2.Exist\n3.Exit\n");
cin&amp;gt;&amp;gt;ans;
if(ans==1) { cin&amp;gt;&amp;gt;s&amp;gt;&amp;gt;m; addNode(s, m); }
else if(ans==2) {cin&amp;gt;&amp;gt;s&amp;gt;&amp;gt;m; printf("%d\n", exists(s, m));}
}while(ans!=3);
return 0;
}

&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7486773803503258327-1004563724583525115?l=manjotpahwa.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/41Gq4hgvUWdqNbMLg0TwRimLBPY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/41Gq4hgvUWdqNbMLg0TwRimLBPY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/41Gq4hgvUWdqNbMLg0TwRimLBPY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/41Gq4hgvUWdqNbMLg0TwRimLBPY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/KiwTH/~4/ZdWU_FlqPCI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manjotpahwa.blogspot.com/feeds/1004563724583525115/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7486773803503258327&amp;postID=1004563724583525115&amp;isPopup=true" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/1004563724583525115?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/1004563724583525115?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/KiwTH/~3/ZdWU_FlqPCI/implementation-of-trie.html" title="Implementation of Trie" /><author><name>Manjot Pahwa</name><uri>http://www.blogger.com/profile/01321615468772658065</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/-yvlwnl1IC58/Tu3IyRTw0tI/AAAAAAAAB5Q/efTRLy7YTMg/s220/IMG_1804000.jpg" /></author><thr:total>3</thr:total><feedburner:origLink>http://manjotpahwa.blogspot.com/2011/07/implementation-of-trie.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkQFQno7eSp7ImA9WhdQE00.&quot;"><id>tag:blogger.com,1999:blog-7486773803503258327.post-4290956240161632171</id><published>2011-07-19T06:41:00.000-07:00</published><updated>2011-08-13T23:45:13.401-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-13T23:45:13.401-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="array" /><category scheme="http://www.blogger.com/atom/ns#" term="rotated" /><category scheme="http://www.blogger.com/atom/ns#" term="algorithm" /><category scheme="http://www.blogger.com/atom/ns#" term="searching" /><title>Searching for an Element in a Rotated Array</title><content type="html">&lt;pre name="code" class="cpp"&gt;
//Rotated Array
#include&amp;lt;iostream&gt;
#include&amp;lt;conio.h&gt;
#include&amp;lt;cstring&gt;
#define FOR(i, a) for(int i=0;i&amp;lt;a;i++)
#define MAXS 100
using namespace std;

int FindSpike(int a[], int lo, int high, int n)
{
int mid = (lo+high)/2;
while(1){
mid = (lo+high)/2;
if(mid!=0 &amp;&amp; mid!=n-1){
if(a[mid]&amp;lt;a[mid-1] &amp;&amp; a[mid]&amp;lt;a[mid+1]) {return mid;}
else if(a[mid]&gt;a[mid-1] &amp;&amp; a[mid]&gt;a[mid+1]) {return mid;}
}
if(a[mid]&amp;lt;a[lo] &amp;&amp; a[mid]&amp;lt;a[high]) {high = mid; continue;}
else if(a[mid]&gt;a[high] &amp;&amp; a[mid]&gt;a[lo]) {lo = mid; continue;}
}
return mid;
}

bool BinSearch(int a[], int start, int end, int x)
{
int mid;
while(start&amp;lt;end){
mid = (start+end)/2;
if(a[mid]==x) return true;
else if(a[mid]&gt;x) {end = mid-1; continue;}
else {start=mid+1; continue;}
}
if(start==end &amp;&amp; a[start]==x) return true;
return false;
}

int FindEle(int a[], int n, int x)
{
int pt = FindSpike(a, 0, n-1, n);
if(x&amp;lt;=a[pt-1] &amp;&amp; x&gt;=a[0])  return BinSearch(a, 0, pt-1, x);
else return BinSearch(a, pt, n-1, x);
}

int main()
{
int a[] = {6, 7, 8, 1, 2, 3, 4, 5};
cout&amp;lt;&amp;lt;FindSpike(a, 0, 7, 7)&amp;lt;&amp;lt;endl;
int x=11;
cout&amp;lt;&amp;lt;FindEle(a, 8, x)&amp;lt;&amp;lt;endl;
getch();
return 0;
}

&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7486773803503258327-4290956240161632171?l=manjotpahwa.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/bGViLSXlFVKZ9_1wFMAeac1sGOA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/bGViLSXlFVKZ9_1wFMAeac1sGOA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/bGViLSXlFVKZ9_1wFMAeac1sGOA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/bGViLSXlFVKZ9_1wFMAeac1sGOA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/KiwTH/~4/mwjWeAjkHVc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manjotpahwa.blogspot.com/feeds/4290956240161632171/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7486773803503258327&amp;postID=4290956240161632171&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/4290956240161632171?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/4290956240161632171?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/KiwTH/~3/mwjWeAjkHVc/searching-for-element-in-rotated-array.html" title="Searching for an Element in a Rotated Array" /><author><name>Manjot Pahwa</name><uri>http://www.blogger.com/profile/01321615468772658065</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/-yvlwnl1IC58/Tu3IyRTw0tI/AAAAAAAAB5Q/efTRLy7YTMg/s220/IMG_1804000.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://manjotpahwa.blogspot.com/2011/07/searching-for-element-in-rotated-array.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkQHQngzfCp7ImA9WhdQE00.&quot;"><id>tag:blogger.com,1999:blog-7486773803503258327.post-6380596836047707277</id><published>2011-07-19T06:40:00.000-07:00</published><updated>2011-08-13T23:45:33.684-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-13T23:45:33.684-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="anagram" /><category scheme="http://www.blogger.com/atom/ns#" term="algorithm" /><category scheme="http://www.blogger.com/atom/ns#" term="string" /><title>Check Whether Two Strings are Anagrams</title><content type="html">&lt;pre name="code" class="cpp"&gt;
//WORKING!

//Check whether 2 strings are angrams of each other in O(n) time

#include&amp;lt;iostream&gt;  
#include&amp;lt;conio.h&gt;  
#include&amp;lt;cstring&gt;  
#include&amp;lt;algorithm&gt;  
#define FOR(i, a) for(int i=0; i&amp;lt;a; i++)  
#define MAXS 10  
#define INF 32000 
#define SIZE 256 
#define MIN(a, b, c) ((a&gt;b)?(b&amp;lt;c?b:c):(a&amp;lt;c?a:c))  
using namespace std;

int CharSet[SIZE];

bool CheckAnagrams(char A[], char B[])
{
if(strlen(A)!=strlen(B))
return false;
for(int i=0; i&amp;lt;strlen(A); i++){
CharSet[A[i]-'a']++;
CharSet[B[i]-'a']--;
}
FOR(j, SIZE){
if(CharSet[j]!=0)
return false;
}
return true;
}

int main()
{
char A[] = "abcd";
char B[] = "cbae";
cout&amp;lt;&amp;lt;CheckAnagrams(A, B);
getch();
}

&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7486773803503258327-6380596836047707277?l=manjotpahwa.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/CeVpiOv5cGgdhoXjUMklb2bdYSA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/CeVpiOv5cGgdhoXjUMklb2bdYSA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/CeVpiOv5cGgdhoXjUMklb2bdYSA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/CeVpiOv5cGgdhoXjUMklb2bdYSA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/KiwTH/~4/wrT1aLnwtYY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manjotpahwa.blogspot.com/feeds/6380596836047707277/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7486773803503258327&amp;postID=6380596836047707277&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/6380596836047707277?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/6380596836047707277?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/KiwTH/~3/wrT1aLnwtYY/check-whether-two-strings-are-anagrams.html" title="Check Whether Two Strings are Anagrams" /><author><name>Manjot Pahwa</name><uri>http://www.blogger.com/profile/01321615468772658065</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/-yvlwnl1IC58/Tu3IyRTw0tI/AAAAAAAAB5Q/efTRLy7YTMg/s220/IMG_1804000.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://manjotpahwa.blogspot.com/2011/07/check-whether-two-strings-are-anagrams.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkQCQXw_fSp7ImA9WhdQE00.&quot;"><id>tag:blogger.com,1999:blog-7486773803503258327.post-5947536942095944570</id><published>2011-07-19T06:39:00.001-07:00</published><updated>2011-08-13T23:46:00.245-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-13T23:46:00.245-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="array" /><category scheme="http://www.blogger.com/atom/ns#" term="merge" /><category scheme="http://www.blogger.com/atom/ns#" term="median" /><category scheme="http://www.blogger.com/atom/ns#" term="sorted" /><category scheme="http://www.blogger.com/atom/ns#" term="merging" /><title>Median of Two Sorted Arrays after Merging in log(N) Time</title><content type="html">&lt;pre name="code" class="cpp"&gt;//WORKING SWEET!
//Median of 2 Sorted Arrays in logn Time

#include&amp;lt;iostream&gt;  
#include&amp;lt;conio.h&gt;  
#include&amp;lt;cstring&gt;  
#include&amp;lt;algorithm&gt;  
#define FOR(i, a) for(int i=0; i&amp;lt;a; i++)  
#define MAXS 10  
#define INF 32000  
#define MIN(a, b, c) ((a&gt;b)?(b&amp;lt;c?b:c):(a&amp;lt;c?a:c))  
using namespace std; 

int MedianSortedArrays(int A[], int B[], int higha, int lowa, int highb, int lowb)
{
int mida = (higha+lowa)/2;
int midb = (highb+lowb)/2;    
if(mida==midb) return A[mida];
if(higha==lowa &amp;&amp; highb==lowb) return (A[higha]+B[highb])/2;
if(mida&gt;midb){
return MedianSortedArrays(A, B, mida-1, lowa, highb, midb+1);
}
if(mida&amp;lt;midb){
return MedianSortedArrays(A, B, higha, mida+1, midb-1, lowb);
}
}

int main()
{
int ar1[] = {1, 12, 15, 26, 38};   
int ar2[] = {2, 13, 17, 30, 45}; 
cout&amp;lt;&amp;lt;MedianSortedArrays(ar1, ar2, 4, 0, 4, 0);
getch();
}

&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7486773803503258327-5947536942095944570?l=manjotpahwa.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/PUfa4sBXN1LTGWSMaCNzgqKK5Qk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PUfa4sBXN1LTGWSMaCNzgqKK5Qk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/PUfa4sBXN1LTGWSMaCNzgqKK5Qk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PUfa4sBXN1LTGWSMaCNzgqKK5Qk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/KiwTH/~4/LUq7Rnrxj4g" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manjotpahwa.blogspot.com/feeds/5947536942095944570/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7486773803503258327&amp;postID=5947536942095944570&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/5947536942095944570?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/5947536942095944570?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/KiwTH/~3/LUq7Rnrxj4g/median-of-two-sorted-arrays-after.html" title="Median of Two Sorted Arrays after Merging in log(N) Time" /><author><name>Manjot Pahwa</name><uri>http://www.blogger.com/profile/01321615468772658065</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/-yvlwnl1IC58/Tu3IyRTw0tI/AAAAAAAAB5Q/efTRLy7YTMg/s220/IMG_1804000.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://manjotpahwa.blogspot.com/2011/07/median-of-two-sorted-arrays-after.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0MAQ3c7eCp7ImA9WhdSGE4.&quot;"><id>tag:blogger.com,1999:blog-7486773803503258327.post-312390787323263927</id><published>2011-07-19T06:37:00.000-07:00</published><updated>2011-07-28T00:50:42.900-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-28T00:50:42.900-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="preorder" /><category scheme="http://www.blogger.com/atom/ns#" term="traversal" /><category scheme="http://www.blogger.com/atom/ns#" term="inorder" /><category scheme="http://www.blogger.com/atom/ns#" term="binary" /><category scheme="http://www.blogger.com/atom/ns#" term="search" /><category scheme="http://www.blogger.com/atom/ns#" term="algorithm" /><category scheme="http://www.blogger.com/atom/ns#" term="tree" /><title>Construction Of BST Using Inorder and Preorder Traversal</title><content type="html">&lt;pre name="code" class="cpp"&gt;
//WORKING FINE!

//Construct a BST from inorder and preorder traversal

#include&amp;lt;iostream&gt;  
#include&amp;lt;conio.h&gt;  
#include&amp;lt;cstring&gt;  
#include&amp;lt;algorithm&gt;  
#define FOR(i, a) for(int i=0; i&amp;lt;a; i++)  
#define MAXS 10  
#define INF 32000 
#define SIZE 256 
#define MIN(a, b, c) ((a&gt;b)?(b&amp;lt;c?b:c):(a&amp;lt;c?a:c))  
using namespace std;

struct node{  
int info;  
struct node *left, *right;  
int maxSum;
};  
typedef struct node * N;  
N tree=NULL; 

N ConstructBSTInorderPreorder(int inOrder[], int preOrder[], int start, int end)
{
static int idx = 0;
int inIdx=0;
if(start&gt;end)     return NULL;
N tmp;
tmp = (N)malloc(sizeof(struct node));
tmp-&gt;info = preOrder[idx++];
tmp-&gt;left=NULL;
tmp-&gt;right=NULL;
if(start==end)
return tmp;
for(inIdx=start; inIdx&amp;lt;=end; inIdx++){
if(tmp-&gt;info==inOrder[inIdx])
break;
}
tmp-&gt;left = ConstructBSTInorderPreorder(inOrder, preOrder, start, inIdx-1);
tmp-&gt;right = ConstructBSTInorderPreorder(inOrder, preOrder, inIdx+1, end);
return tmp;
}

void inorder(N p)
{
if(p==NULL) return;
inorder(p-&gt;left);
printf("%d\n", p-&gt;info);
inorder(p-&gt;right);
}

void preorder(N p)
{
if(p==NULL) return;
printf("%d\n", p-&gt;info);
preorder(p-&gt;left);
preorder(p-&gt;right);
}

int main()
{
int in[] = {1, 2, 3, 4, 5, 6};
int pre[] = {4, 2, 1, 3, 5, 6};
int len;    
len = sizeof(in)/sizeof(int);
tree = ConstructBSTInorderPreorder(in, pre, 0, len-1);
inorder(tree);
cout&amp;lt;&amp;lt;"\n";
preorder(tree);
getch();
}

&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7486773803503258327-312390787323263927?l=manjotpahwa.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/fcjEVRQyWRw8pxUkmrlBFl2jqL8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/fcjEVRQyWRw8pxUkmrlBFl2jqL8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/fcjEVRQyWRw8pxUkmrlBFl2jqL8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/fcjEVRQyWRw8pxUkmrlBFl2jqL8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/KiwTH/~4/OyxV8CdgMJ4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manjotpahwa.blogspot.com/feeds/312390787323263927/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7486773803503258327&amp;postID=312390787323263927&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/312390787323263927?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/312390787323263927?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/KiwTH/~3/OyxV8CdgMJ4/construction-of-bst-using-inorder-and_19.html" title="Construction Of BST Using Inorder and Preorder Traversal" /><author><name>Manjot Pahwa</name><uri>http://www.blogger.com/profile/01321615468772658065</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/-yvlwnl1IC58/Tu3IyRTw0tI/AAAAAAAAB5Q/efTRLy7YTMg/s220/IMG_1804000.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://manjotpahwa.blogspot.com/2011/07/construction-of-bst-using-inorder-and_19.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0MCRHw4fSp7ImA9WhdSGE4.&quot;"><id>tag:blogger.com,1999:blog-7486773803503258327.post-4046307279380959255</id><published>2011-07-19T06:36:00.000-07:00</published><updated>2011-07-28T00:51:05.235-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-28T00:51:05.235-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="traversal" /><category scheme="http://www.blogger.com/atom/ns#" term="inorder" /><category scheme="http://www.blogger.com/atom/ns#" term="binary" /><category scheme="http://www.blogger.com/atom/ns#" term="search" /><category scheme="http://www.blogger.com/atom/ns#" term="algorithm" /><category scheme="http://www.blogger.com/atom/ns#" term="postorder" /><category scheme="http://www.blogger.com/atom/ns#" term="tree" /><title>Construction Of BST Using Inorder and Postorder Traversal</title><content type="html">&lt;pre name="code" class="cpp"&gt;
//WORKING FINE!

//Construct a BST from inorder and preorder traversal

#include&amp;lt;iostream&gt;  
#include&amp;lt;conio.h&gt;  
#include&amp;lt;cstring&gt;  
#include&amp;lt;algorithm&gt;  
#define FOR(i, a) for(int i=0; i&amp;lt;a; i++)  
#define MAXS 10  
#define INF 32000 
#define SIZE 256 
#define MIN(a, b, c) ((a&gt;b)?(b&amp;lt;c?b:c):(a&amp;lt;c?a:c))  
using namespace std;

struct node{  
int info;  
struct node *left, *right;  
int maxSum;
};  
typedef struct node * N;  
N tree=NULL; 

N ConstructBSTInorderPostorder(int inOrder[], int postOrder[], int start, int end, int idx)
{
int inIdx=0;
if(start&gt;end)     return NULL;
N tmp;
tmp = (N)malloc(sizeof(struct node));
tmp-&gt;info = postOrder[idx];
tmp-&gt;left=NULL;
tmp-&gt;right=NULL;
if(start==end)
return tmp;
for(inIdx=start; inIdx&amp;lt;=end; inIdx++){
if(tmp-&gt;info==inOrder[inIdx])
break;
}
tmp-&gt;right = ConstructBSTInorderPostorder(inOrder, postOrder, inIdx+1, end, idx-1);
tmp-&gt;left = ConstructBSTInorderPostorder(inOrder, postOrder, start, inIdx-1, idx-1-(end-inIdx));
return tmp;
}

void inorder(N p)
{
if(p==NULL) return;
inorder(p-&gt;left);
printf("%d\n", p-&gt;info);
inorder(p-&gt;right);
}

void preorder(N p)
{
if(p==NULL) return;
printf("%d\n", p-&gt;info);
preorder(p-&gt;left);
preorder(p-&gt;right);
}

int main()
{
int in[] = {1, 2, 3, 4, 5, 6};
int pre[] = {4, 2, 1, 3, 5, 6};
int post[] = {1, 3, 2, 6, 5, 4};
int len;    
len = sizeof(in)/sizeof(int);
tree = ConstructBSTInorderPostorder(in, post, 0, len-1, len-1);
inorder(tree);
cout&amp;lt;&amp;lt;"\n";
preorder(tree);
getch();
}

&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7486773803503258327-4046307279380959255?l=manjotpahwa.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/4Yx8qy1CzM2Pi9K9ydCONh8Nhk8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4Yx8qy1CzM2Pi9K9ydCONh8Nhk8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/4Yx8qy1CzM2Pi9K9ydCONh8Nhk8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4Yx8qy1CzM2Pi9K9ydCONh8Nhk8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/KiwTH/~4/uxkvzEewCKU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://manjotpahwa.blogspot.com/feeds/4046307279380959255/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=7486773803503258327&amp;postID=4046307279380959255&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/4046307279380959255?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7486773803503258327/posts/default/4046307279380959255?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/KiwTH/~3/uxkvzEewCKU/construction-of-bst-using-inorder-and.html" title="Construction Of BST Using Inorder and Postorder Traversal" /><author><name>Manjot Pahwa</name><uri>http://www.blogger.com/profile/01321615468772658065</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/-yvlwnl1IC58/Tu3IyRTw0tI/AAAAAAAAB5Q/efTRLy7YTMg/s220/IMG_1804000.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://manjotpahwa.blogspot.com/2011/07/construction-of-bst-using-inorder-and.html</feedburner:origLink></entry></feed>

