<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments for GeeksforGeeks</title>
	<atom:link href="http://www.geeksforgeeks.org/comments/feed" rel="self" type="application/rss+xml" />
	<link>http://www.geeksforgeeks.org</link>
	<description>A computer science portal for geeks</description>
	<lastBuildDate>Wed, 22 Feb 2012 04:59:34 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>Comment on Maximum Length Bitonic Subarray by vijay_kansal</title>
		<link>http://www.geeksforgeeks.org/archives/12292/comment-page-1#comment-7635</link>
		<dc:creator>vijay_kansal</dc:creator>
		<pubDate>Wed, 22 Feb 2012 04:59:34 +0000</pubDate>
		<guid isPermaLink="false">http://geeksforgeeks.org/?p=12292#comment-7635</guid>
		<description>I think the given simple solution of O(n) time and O(1) space must work.
Please indicate errors in the code, if any...


[sourcecode language=&quot;C&quot;]
int longest_bitonic(int *a,int n)
{
 if(n&lt;=0)
  return 0;
 int i,max,lastdistincti=0,starti;
 i=0;
 while(i&lt;n)
 {
  starti=lastdistincti;

  for(;i&lt;n&amp;&amp;a[i]&gt;=a[i-1];i++)
   ;

  for(;i&lt;n&amp;&amp;a[i]&lt;=a[i-1];i++)
   if(a[i]&lt;a[i-1])
    lastdistincti=i;
  
  if(i-starti&gt;max)
   max=i-starti;
 }
 return max;
}
[/sourcecode]</description>
		<content:encoded><![CDATA[<p>I think the given simple solution of O(n) time and O(1) space must work.<br />
Please indicate errors in the code, if any...</p>
<pre class="brush: cpp; title: ; notranslate">
int longest_bitonic(int *a,int n)
{
 if(n&lt;=0)
  return 0;
 int i,max,lastdistincti=0,starti;
 i=0;
 while(i&lt;n)
 {
  starti=lastdistincti;

  for(;i&lt;n&amp;&amp;a[i]&gt;=a[i-1];i++)
   ;

  for(;i&lt;n&amp;&amp;a[i]&lt;=a[i-1];i++)
   if(a[i]&lt;a[i-1])
    lastdistincti=i;

  if(i-starti&gt;max)
   max=i-starti;
 }
 return max;
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Trie &#124; (Insert and Search) by Tarun</title>
		<link>http://www.geeksforgeeks.org/archives/13067/comment-page-1#comment-7634</link>
		<dc:creator>Tarun</dc:creator>
		<pubDate>Tue, 21 Feb 2012 23:10:13 +0000</pubDate>
		<guid isPermaLink="false">http://geeksforgeeks.org/?p=13067#comment-7634</guid>
		<description>[sourcecode language=&quot;C&quot;]
/* Paste your code here (You may delete these lines if not writing code) */

///===========================node.h==========================================
#ifndef __NODE__H
#define __NODE__H

//node.h
#include &lt;string&gt;
#include &lt;ostream&gt;

#define ARRAY_SIZE(a) sizeof(a)/sizeof(a[0])
#define ALPHABET_SIZE 26
#define index(c) ((int)c - (int)&#039;a&#039;)




class Node
{
private:
    int m_count;
    std::string m_data;
    Node* child[ALPHABET_SIZE];
public:
    Node();
    friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; _out, const Node&amp; _node);
    friend class Tries;
};
#endif //node.h
///===========================end of node.h==========================================
///===========================node.cpp==========================================
#include &quot;node.h&quot;



Node::Node()
{
    for(int i = 0; i &lt; ALPHABET_SIZE; ++i)
    {
        child[i] = 0;
    }
}


std::ostream&amp; operator&lt;&lt;(std::ostream&amp; _out, const Node&amp; _node)
{
    if(!_node.m_data.empty())
    {
        _out&lt;&lt;_node.m_data&lt;&lt;&quot;,&quot;;
    }
    for(int i = 0; i &lt; ALPHABET_SIZE; i++)
    {
        if(_node.child[i] == NULL)
        {
            continue;
        }
        _out&lt;&lt;*(_node.child[i]);
    }
    _out&lt;&lt;std::endl;
}
////===========================end of node.cpp==========================================

///===========================tries.h==========================================
#ifndef __TRIES__H
#define __TRIES__H


class Node;

class Tries
{
public:
    Tries();
    void insert(char _key[]);
    void search(char _key[]);
private:
    void init();
    Node* m_head;
};
#endif //tries.h
///===========================end of tries.h==========================================

///===========================tries.cpp==========================================
#include &lt;iostream&gt;
#include &quot;node.h&quot;
#include &quot;tries.h&quot;

void Tries::init()
{
    if(NULL == m_head)
    {
        m_head = new Node();
    }
    m_head-&gt;m_count = 0;
}

Tries::Tries()
{
    init();
}

void Tries::insert(char _key[])
{
    if (NULL == _key)
    {
        return;
    }
    Node* temp = m_head;
    int len = strlen(_key);

    for(int i = 0; i &lt; len; ++i)
    {
        int indx = index(_key[i]);
        if(NULL == temp-&gt;child[indx])
        {
            temp-&gt;child[indx] = new Node();
            temp = temp-&gt;child[indx];
        }
        else
        {
            temp = temp-&gt;child[indx];
        }
        temp-&gt;m_count++;
    }
    temp-&gt;m_data = _key;
}

void Tries::search(char _key[])
{
    if(NULL == m_head)
    {
        return;
    }

    int len = strlen(_key);
    int i = 0;
    Node* temp = m_head;

    for(i = 0; i &lt; len-1; i++)

    for(i = 0; i &lt; len-1; i++)
    {
        temp = temp-&gt;child[index(_key[i])];
        if(NULL == temp)
        {
            return;
        }
        if(!temp-&gt;m_data.empty())
        {
            std::cout&lt;&lt;&quot;data: &lt;&quot;&lt;&lt;temp-&gt;m_data&lt;&lt;&quot;&gt;&quot;&lt;&lt;std::endl;
        }
    }
    temp = temp-&gt;child[index(_key[i])];
    if(temp)
    {
        std::cout&lt;&lt;*temp;
    }
}
///===========================end of tries.cpp==========================================

/*
 * =====================================================================================
 *
 *       Filename:  tries_test.cpp
 *
 *    Description:  main calls for testing of tries
 *
 *        Version:  1.0
 *        Created:  Tue Feb 21 2012 05:52:50
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Tarun Kumar (1.1), tarun_kumar1@symantec.com
 *        Company:  Symantec, Chennai
 *
 * =====================================================================================
 */

#include &quot;tries.h&quot;

int main()
{
    char value[][8] = {&quot;she&quot;, &quot;sells&quot;, &quot;sea&quot;, &quot;shore&quot;, &quot;the&quot;, &quot;by&quot;, &quot;sheer&quot;};

    Tries Tree;

    for(int i = 0; i &lt; 7; ++i)
    {
        Tree.insert(value[i]);
    }

    Tree.search(&quot;s&quot;);

    return 0;
}

///===========================Makefile==========================================
##Makefile

GCC = g++ -g

all: tries.exe

OBJ =   node.o \
        tries.o \
        tries_test.o \


tries.exe: $(OBJ)
    $(GCC) $(OBJ) -o tries.exe
    rm -f $(OBJ)

tries.o: tries.cpp tries.h node.h node.cpp
    $(GCC) -c tries.cpp

node.o: node.cpp node.h
    $(GCC) -c node.cpp

tries_test.o: tries.o
    $(GCC) -c tries_test.cpp


# -- remove binary and executable

clean:
    rm -f $(OBJ) tries.exe
///===========================end of Makefile==========================================
[/sourcecode]</description>
		<content:encoded><![CDATA[<pre class="brush: cpp; title: ; notranslate">
/* Paste your code here (You may delete these lines if not writing code) */

///===========================node.h==========================================
#ifndef __NODE__H
#define __NODE__H

//node.h
#include &lt;string&gt;
#include &lt;ostream&gt;

#define ARRAY_SIZE(a) sizeof(a)/sizeof(a[0])
#define ALPHABET_SIZE 26
#define index(c) ((int)c - (int)'a')

class Node
{
private:
    int m_count;
    std::string m_data;
    Node* child[ALPHABET_SIZE];
public:
    Node();
    friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; _out, const Node&amp; _node);
    friend class Tries;
};
#endif //node.h
///===========================end of node.h==========================================
///===========================node.cpp==========================================
#include &quot;node.h&quot;

Node::Node()
{
    for(int i = 0; i &lt; ALPHABET_SIZE; ++i)
    {
        child[i] = 0;
    }
}

std::ostream&amp; operator&lt;&lt;(std::ostream&amp; _out, const Node&amp; _node)
{
    if(!_node.m_data.empty())
    {
        _out&lt;&lt;_node.m_data&lt;&lt;&quot;,&quot;;
    }
    for(int i = 0; i &lt; ALPHABET_SIZE; i++)
    {
        if(_node.child[i] == NULL)
        {
            continue;
        }
        _out&lt;&lt;*(_node.child[i]);
    }
    _out&lt;&lt;std::endl;
}
////===========================end of node.cpp==========================================

///===========================tries.h==========================================
#ifndef __TRIES__H
#define __TRIES__H

class Node;

class Tries
{
public:
    Tries();
    void insert(char _key[]);
    void search(char _key[]);
private:
    void init();
    Node* m_head;
};
#endif //tries.h
///===========================end of tries.h==========================================

///===========================tries.cpp==========================================
#include &lt;iostream&gt;
#include &quot;node.h&quot;
#include &quot;tries.h&quot;

void Tries::init()
{
    if(NULL == m_head)
    {
        m_head = new Node();
    }
    m_head-&gt;m_count = 0;
}

Tries::Tries()
{
    init();
}

void Tries::insert(char _key[])
{
    if (NULL == _key)
    {
        return;
    }
    Node* temp = m_head;
    int len = strlen(_key);

    for(int i = 0; i &lt; len; ++i)
    {
        int indx = index(_key[i]);
        if(NULL == temp-&gt;child[indx])
        {
            temp-&gt;child[indx] = new Node();
            temp = temp-&gt;child[indx];
        }
        else
        {
            temp = temp-&gt;child[indx];
        }
        temp-&gt;m_count++;
    }
    temp-&gt;m_data = _key;
}

void Tries::search(char _key[])
{
    if(NULL == m_head)
    {
        return;
    }

    int len = strlen(_key);
    int i = 0;
    Node* temp = m_head;

    for(i = 0; i &lt; len-1; i++)

    for(i = 0; i &lt; len-1; i++)
    {
        temp = temp-&gt;child[index(_key[i])];
        if(NULL == temp)
        {
            return;
        }
        if(!temp-&gt;m_data.empty())
        {
            std::cout&lt;&lt;&quot;data: &lt;&quot;&lt;&lt;temp-&gt;m_data&lt;&lt;&quot;&gt;&quot;&lt;&lt;std::endl;
        }
    }
    temp = temp-&gt;child[index(_key[i])];
    if(temp)
    {
        std::cout&lt;&lt;*temp;
    }
}
///===========================end of tries.cpp==========================================

/*
 * =====================================================================================
 *
 *       Filename:  tries_test.cpp
 *
 *    Description:  main calls for testing of tries
 *
 *        Version:  1.0
 *        Created:  Tue Feb 21 2012 05:52:50
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Tarun Kumar (1.1), tarun_kumar1@symantec.com
 *        Company:  Symantec, Chennai
 *
 * =====================================================================================
 */

#include &quot;tries.h&quot;

int main()
{
    char value[][8] = {&quot;she&quot;, &quot;sells&quot;, &quot;sea&quot;, &quot;shore&quot;, &quot;the&quot;, &quot;by&quot;, &quot;sheer&quot;};

    Tries Tree;

    for(int i = 0; i &lt; 7; ++i)
    {
        Tree.insert(value[i]);
    }

    Tree.search(&quot;s&quot;);

    return 0;
}

///===========================Makefile==========================================
##Makefile

GCC = g++ -g

all: tries.exe

OBJ =   node.o \
        tries.o \
        tries_test.o \

tries.exe: $(OBJ)
    $(GCC) $(OBJ) -o tries.exe
    rm -f $(OBJ)

tries.o: tries.cpp tries.h node.h node.cpp
    $(GCC) -c tries.cpp

node.o: node.cpp node.h
    $(GCC) -c node.cpp

tries_test.o: tries.o
    $(GCC) -c tries_test.cpp

# -- remove binary and executable

clean:
    rm -f $(OBJ) tries.exe
///===========================end of Makefile==========================================
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Find the largest BST subtree in a given Binary Tree by Neeraj</title>
		<link>http://www.geeksforgeeks.org/archives/7291/comment-page-1#comment-7633</link>
		<dc:creator>Neeraj</dc:creator>
		<pubDate>Tue, 21 Feb 2012 19:38:39 +0000</pubDate>
		<guid isPermaLink="false">http://geeksforgeeks.org/?p=7291#comment-7633</guid>
		<description>Need new glasses ;)

[sourcecode language=&quot;C&quot;]
/* Paste your code here (You may delete these lines if not writing code) */
[/sourcecode]</description>
		<content:encoded><![CDATA[<p>Need new glasses <img src='http://www.geeksforgeeks.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<pre class="brush: cpp; title: ; notranslate">
/* Paste your code here (You may delete these lines if not writing code) */
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Average of a stream of numbers by Progod</title>
		<link>http://www.geeksforgeeks.org/archives/15658/comment-page-1#comment-7632</link>
		<dc:creator>Progod</dc:creator>
		<pubDate>Tue, 21 Feb 2012 17:47:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.geeksforgeeks.org/?p=15658#comment-7632</guid>
		<description>Yes it should be float balance = x - oldAvg; That was a typo


[sourcecode language=&quot;C&quot;]
/* Paste your code here (You may delete these lines if not writing code) */
[/sourcecode]</description>
		<content:encoded><![CDATA[<p>Yes it should be float balance = x - oldAvg; That was a typo</p>
<pre class="brush: cpp; title: ; notranslate">
/* Paste your code here (You may delete these lines if not writing code) */
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Average of a stream of numbers by Progod</title>
		<link>http://www.geeksforgeeks.org/archives/15658/comment-page-1#comment-7631</link>
		<dc:creator>Progod</dc:creator>
		<pubDate>Tue, 21 Feb 2012 17:36:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.geeksforgeeks.org/?p=15658#comment-7631</guid>
		<description>Sorry for typo It should be float balance = x - oldAvg;


[sourcecode language=&quot;C&quot;]
/* Paste your code here (You may delete these lines if not writing code) */
[/sourcecode]</description>
		<content:encoded><![CDATA[<p>Sorry for typo It should be float balance = x - oldAvg;</p>
<pre class="brush: cpp; title: ; notranslate">
/* Paste your code here (You may delete these lines if not writing code) */
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Average of a stream of numbers by Progod</title>
		<link>http://www.geeksforgeeks.org/archives/15658/comment-page-1#comment-7630</link>
		<dc:creator>Progod</dc:creator>
		<pubDate>Tue, 21 Feb 2012 17:22:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.geeksforgeeks.org/?p=15658#comment-7630</guid>
		<description>Sorry for the typo. 


[sourcecode language=&quot;C&quot;]
float getAvg (int x)
{
static int sum, n;

sum += x;
return (((float)sum)/++n);
}
here sum can give you overflow problem.
to solve this problem you can use following approach.

float getAvg (int x)
{
    static float oldAvg, n;
 
    fload balance = x - oldAvg;
    oldAvg += (balance/++n);
 
    return oldAvg;
}

[/sourcecode]</description>
		<content:encoded><![CDATA[<p>Sorry for the typo. </p>
<pre class="brush: cpp; title: ; notranslate">
float getAvg (int x)
{
static int sum, n;

sum += x;
return (((float)sum)/++n);
}
here sum can give you overflow problem.
to solve this problem you can use following approach.

float getAvg (int x)
{
    static float oldAvg, n;

    fload balance = x - oldAvg;
    oldAvg += (balance/++n);

    return oldAvg;
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Given an array arr[], find the maximum j &#8211; i such that arr[j] &gt; arr[i] by kartikaditya</title>
		<link>http://www.geeksforgeeks.org/archives/12450/comment-page-1#comment-7628</link>
		<dc:creator>kartikaditya</dc:creator>
		<pubDate>Tue, 21 Feb 2012 16:27:25 +0000</pubDate>
		<guid isPermaLink="false">http://geeksforgeeks.org/?p=12450#comment-7628</guid>
		<description>Time - O(N)
Space - O(1)

[sourcecode language=&quot;C&quot;]
#include &lt;iostream&gt;
#include &lt;stdio.h&gt;

using namespace std;

int findMaxJMinusI(int a[], int n) {
    int start = 0, end = n - 1;
    while (start &lt; end) {
        if (a[start] &lt; a[end]) {
            return end - start;
        } else if (a[start] &lt; a[end - 1] &#124;&#124; a[start + 1] &lt; end) {
            return end - 1 - start;
        }
        ++start;
        --end;
    }
    return -1;
}

int main() {
    int a1[] = {34, 8, 10, 3, 2, 80, 30, 33, 1};
    cout &lt;&lt; findMaxJMinusI(a1, 9) &lt;&lt; endl;
    int a2[] = {9, 2, 3, 4, 5, 6, 7, 8, 18, 0};
    cout &lt;&lt; findMaxJMinusI(a2, 10) &lt;&lt; endl;
    int a3[] = {1, 2, 3, 4, 5, 6};
    cout &lt;&lt; findMaxJMinusI(a3, 6) &lt;&lt; endl;
    int a4[] = {6, 5, 4, 3, 2, 1};
    cout &lt;&lt; findMaxJMinusI(a4, 6) &lt;&lt; endl;
    int a5[] = {4, 8, 1, 5};
    cout &lt;&lt; findMaxJMinusI(a5, 4) &lt;&lt; endl;
    return 0;
}
[/sourcecode]</description>
		<content:encoded><![CDATA[<p>Time - O(N)<br />
Space - O(1)</p>
<pre class="brush: cpp; title: ; notranslate">
#include &lt;iostream&gt;
#include &lt;stdio.h&gt;

using namespace std;

int findMaxJMinusI(int a[], int n) {
    int start = 0, end = n - 1;
    while (start &lt; end) {
        if (a[start] &lt; a[end]) {
            return end - start;
        } else if (a[start] &lt; a[end - 1] || a[start + 1] &lt; end) {
            return end - 1 - start;
        }
        ++start;
        --end;
    }
    return -1;
}

int main() {
    int a1[] = {34, 8, 10, 3, 2, 80, 30, 33, 1};
    cout &lt;&lt; findMaxJMinusI(a1, 9) &lt;&lt; endl;
    int a2[] = {9, 2, 3, 4, 5, 6, 7, 8, 18, 0};
    cout &lt;&lt; findMaxJMinusI(a2, 10) &lt;&lt; endl;
    int a3[] = {1, 2, 3, 4, 5, 6};
    cout &lt;&lt; findMaxJMinusI(a3, 6) &lt;&lt; endl;
    int a4[] = {6, 5, 4, 3, 2, 1};
    cout &lt;&lt; findMaxJMinusI(a4, 6) &lt;&lt; endl;
    int a5[] = {4, 8, 1, 5};
    cout &lt;&lt; findMaxJMinusI(a5, 4) &lt;&lt; endl;
    return 0;
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Given an array arr[], find the maximum j &#8211; i such that arr[j] &gt; arr[i] by kartikaditya</title>
		<link>http://www.geeksforgeeks.org/archives/12450/comment-page-1#comment-7627</link>
		<dc:creator>kartikaditya</dc:creator>
		<pubDate>Tue, 21 Feb 2012 16:17:33 +0000</pubDate>
		<guid isPermaLink="false">http://geeksforgeeks.org/?p=12450#comment-7627</guid>
		<description>Time - O(N)
Space - O(1)

[sourcecode language=&quot;C++&quot;]
#include &lt;iostream&gt;
#include &lt;stdio.h&gt;

using namespace std;

int findMaxJMinusI(int a[], int n) {
    int start = 0, end = n - 1;
    while (start &lt; end) {
        if (a[start] &lt; a[end]) {
            return end - start;
        } else if (a[start] &lt; a[end - 1] &#124;&#124; a[start + 1] &lt; end) {
            return end - 1 - start;
        }
        ++start;
        --end;
    }
    return -1;
}

int main() {
    int a1[] = {34, 8, 10, 3, 2, 80, 30, 33, 1};
    cout &lt;&lt; findMaxJMinusI(a1, 9) &lt;&lt; endl;
    int a2[] = {9, 2, 3, 4, 5, 6, 7, 8, 18, 0};
    cout &lt;&lt; findMaxJMinusI(a2, 10) &lt;&lt; endl;
    int a3[] = {1, 2, 3, 4, 5, 6};
    cout &lt;&lt; findMaxJMinusI(a3, 6) &lt;&lt; endl;
    int a4[] = {6, 5, 4, 3, 2, 1};
    cout &lt;&lt; findMaxJMinusI(a4, 6) &lt;&lt; endl;
    int a5[] = {4, 8, 1, 5};
    cout &lt;&lt; findMaxJMinusI(a5, 4) &lt;&lt; endl;
    return 0;
}
[/sourcecode]</description>
		<content:encoded><![CDATA[<p>Time - O(N)<br />
Space - O(1)</p>
<p>#include &lt;iostream&gt;<br />
#include &lt;stdio.h&gt;</p>
<p>using namespace std;</p>
<p>int findMaxJMinusI(int a[], int n) {<br />
    int start = 0, end = n - 1;<br />
    while (start &lt; end) {<br />
        if (a[start] &lt; a[end]) {<br />
            return end - start;<br />
        } else if (a[start] &lt; a[end - 1] || a[start + 1] &lt; end) {<br />
            return end - 1 - start;<br />
        }<br />
        ++start;<br />
        --end;<br />
    }<br />
    return -1;<br />
}</p>
<p>int main() {<br />
    int a1[] = {34, 8, 10, 3, 2, 80, 30, 33, 1};<br />
    cout &lt;&lt; findMaxJMinusI(a1, 9) &lt;&lt; endl;<br />
    int a2[] = {9, 2, 3, 4, 5, 6, 7, 8, 18, 0};<br />
    cout &lt;&lt; findMaxJMinusI(a2, 10) &lt;&lt; endl;<br />
    int a3[] = {1, 2, 3, 4, 5, 6};<br />
    cout &lt;&lt; findMaxJMinusI(a3, 6) &lt;&lt; endl;<br />
    int a4[] = {6, 5, 4, 3, 2, 1};<br />
    cout &lt;&lt; findMaxJMinusI(a4, 6) &lt;&lt; endl;<br />
    int a5[] = {4, 8, 1, 5};<br />
    cout &lt;&lt; findMaxJMinusI(a5, 4) &lt;&lt; endl;<br />
    return 0;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Dynamic Programming &#124; Set 3 (Longest Increasing Subsequence) by kartikaditya</title>
		<link>http://www.geeksforgeeks.org/archives/12832/comment-page-1#comment-7626</link>
		<dc:creator>kartikaditya</dc:creator>
		<pubDate>Tue, 21 Feb 2012 15:21:46 +0000</pubDate>
		<guid isPermaLink="false">http://geeksforgeeks.org/?p=12832#comment-7626</guid>
		<description>[sourcecode language=&quot;JAVA&quot;]
public class LongestIncreasingSubsequence {
    private static int binarySearch(int a[], int x, int start, int end) {
        int limit = end;
        int mid = 0;
        while (start &lt; end) {
            mid = (start + end) &gt;&gt; 1;
            if (a[mid] &lt;= x) {
                start = mid + 1;
            } else {
                end = mid - 1;
            }
        }
        if (a[start] &lt;= x) {
            return start;
        }
        return start - 1;
    }

    public static void getLongestIncreasingSubsequence(int a[]) {
        int dp[] = new int[a.length + 1];
        int memo[] = new int[a.length + 1];

        dp[0] = 1;
        memo[1] = a[0];
        int maxSize = 1;
        for (int i = 1; i &lt; a.length; ++i) {
            if (a[i] &lt; memo[1]) {
                memo[1] = a[i];
                dp[i] = 1;
            } else if (a[i] &gt;= memo[maxSize]) {
                ++maxSize;
                memo[maxSize] = a[i];
                dp[i] = maxSize;
            } else {
                int k = binarySearch(memo, a[i], 1, maxSize);
                memo[k + 1] = a[i];
                dp[i] = k + 1;
            }
        }
        System.out.print(maxSize + &quot; :: &quot;);
        for (int i = 1; i &lt;= maxSize; ++i) {
            System.out.print(memo[i] + &quot; &quot;);
        }
        System.out.println();
    }

    public static void main(String args[]) {
        getLongestIncreasingSubsequence(new int[]{10, 22, 9, 33, 21, 50, 41, 60});
        getLongestIncreasingSubsequence(new int[]{10, 22, 9, 33, 21, 50, 41, 60, 80});
        getLongestIncreasingSubsequence(new int[]{1, 1, 1, 1, 0, 0, 0, 0, 0});
        getLongestIncreasingSubsequence(new int[]{0, 0, 0, 0, 0, 1, 1, 1, 1});
    }
}
[/sourcecode]</description>
		<content:encoded><![CDATA[<pre class="brush: java; title: ; notranslate">
public class LongestIncreasingSubsequence {
    private static int binarySearch(int a[], int x, int start, int end) {
        int limit = end;
        int mid = 0;
        while (start &lt; end) {
            mid = (start + end) &gt;&gt; 1;
            if (a[mid] &lt;= x) {
                start = mid + 1;
            } else {
                end = mid - 1;
            }
        }
        if (a[start] &lt;= x) {
            return start;
        }
        return start - 1;
    }

    public static void getLongestIncreasingSubsequence(int a[]) {
        int dp[] = new int[a.length + 1];
        int memo[] = new int[a.length + 1];

        dp[0] = 1;
        memo[1] = a[0];
        int maxSize = 1;
        for (int i = 1; i &lt; a.length; ++i) {
            if (a[i] &lt; memo[1]) {
                memo[1] = a[i];
                dp[i] = 1;
            } else if (a[i] &gt;= memo[maxSize]) {
                ++maxSize;
                memo[maxSize] = a[i];
                dp[i] = maxSize;
            } else {
                int k = binarySearch(memo, a[i], 1, maxSize);
                memo[k + 1] = a[i];
                dp[i] = k + 1;
            }
        }
        System.out.print(maxSize + &quot; :: &quot;);
        for (int i = 1; i &lt;= maxSize; ++i) {
            System.out.print(memo[i] + &quot; &quot;);
        }
        System.out.println();
    }

    public static void main(String args[]) {
        getLongestIncreasingSubsequence(new int[]{10, 22, 9, 33, 21, 50, 41, 60});
        getLongestIncreasingSubsequence(new int[]{10, 22, 9, 33, 21, 50, 41, 60, 80});
        getLongestIncreasingSubsequence(new int[]{1, 1, 1, 1, 0, 0, 0, 0, 0});
        getLongestIncreasingSubsequence(new int[]{0, 0, 0, 0, 0, 1, 1, 1, 1});
    }
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Find the largest BST subtree in a given Binary Tree by kartikaditya</title>
		<link>http://www.geeksforgeeks.org/archives/7291/comment-page-1#comment-7625</link>
		<dc:creator>kartikaditya</dc:creator>
		<pubDate>Tue, 21 Feb 2012 15:12:01 +0000</pubDate>
		<guid isPermaLink="false">http://geeksforgeeks.org/?p=7291#comment-7625</guid>
		<description>Dude 45 is to the left of 40</description>
		<content:encoded><![CDATA[<p>Dude 45 is to the left of 40</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Find the largest BST subtree in a given Binary Tree by Neeraj</title>
		<link>http://www.geeksforgeeks.org/archives/7291/comment-page-1#comment-7624</link>
		<dc:creator>Neeraj</dc:creator>
		<pubDate>Tue, 21 Feb 2012 14:56:52 +0000</pubDate>
		<guid isPermaLink="false">http://geeksforgeeks.org/?p=7291#comment-7624</guid>
		<description>I don&#039;t follow. Why is the largest BST of size 3? The entire tree seems like a BST to me?


[sourcecode language=&quot;C&quot;]
/* Paste your code here (You may delete these lines if not writing code) */
[/sourcecode]</description>
		<content:encoded><![CDATA[<p>I don't follow. Why is the largest BST of size 3? The entire tree seems like a BST to me?</p>
<pre class="brush: cpp; title: ; notranslate">
/* Paste your code here (You may delete these lines if not writing code) */
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Lucky Numbers by aravind</title>
		<link>http://www.geeksforgeeks.org/archives/542/comment-page-1#comment-7622</link>
		<dc:creator>aravind</dc:creator>
		<pubDate>Tue, 21 Feb 2012 05:59:52 +0000</pubDate>
		<guid isPermaLink="false">http://geeksforgeeks.org/?p=542#comment-7622</guid>
		<description>Thanks a lot for good code...</description>
		<content:encoded><![CDATA[<p>Thanks a lot for good code...</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Dynamic Programming &#124; Set 4 (Longest Common Subsequence) by kartikaditya</title>
		<link>http://www.geeksforgeeks.org/archives/12998/comment-page-1#comment-7621</link>
		<dc:creator>kartikaditya</dc:creator>
		<pubDate>Tue, 21 Feb 2012 05:17:02 +0000</pubDate>
		<guid isPermaLink="false">http://geeksforgeeks.org/?p=12998#comment-7621</guid>
		<description>[sourcecode language=&quot;JAVA&quot;]
public class LongestCommonSubsequence {
    public static String getLongestCommonSubsequence(String s1, String s2) {
		int dp[][] = new int[s1.length()][s2.length()];
		dp[0][0] = (s1.charAt(0) == s2.charAt(0)) ? 1 : 0;
		for (int i = 1; i &lt; s1.length(); ++i) {
			if (s1.charAt(i) == s2.charAt(0)) {
				dp[i][0] = 1;
			} else {
				dp[i][0] = dp[i - 1][0];
			}
		}
		for (int i = 1; i &lt; s2.length(); ++i) {
			if (s1.charAt(0) == s2.charAt(i)) {
				dp[0][i] = 1;
			} else {
				dp[0][i] = dp[0][i - 1];
			}
		}
		for (int i = 1; i &lt; s1.length(); ++i) {
			for (int j = 1; j &lt; s2.length(); ++j) {
				if (s1.charAt(i) == s2.charAt(j)) {
					dp[i][j] = 1 + dp[i - 1][j - 1];
				} else {
					dp[i][j] = Math.max(dp[i][j - 1], dp[i - 1][j]);
				}
			}
		}
		StringBuffer sb = new StringBuffer();
		int x = s1.length() - 1, y = s2.length() - 1;
		while (x &gt;= 0 &amp;&amp; y &gt;= 0) {
			if (s1.charAt(x) == s2.charAt(y)) {
				sb.append(s1.charAt(x));
				--x;
				--y;
			} else {
				if (x &gt; 0 &amp;&amp; dp[x - 1][y] == dp[x][y]) {
					--x;
				} else {
					--y;
				}
			}
		}
		return sb.reverse().toString();
	}

	public static void main(String[] args) {
		System.out.println(getLongestCommonSubsequence(&quot;ABCDGH&quot;, &quot;AEDFHR&quot;));
		System.out.println(getLongestCommonSubsequence(&quot;AGGTAB&quot;, &quot;GXTXAYB&quot;));
	}
}
[/sourcecode]</description>
		<content:encoded><![CDATA[<pre class="brush: java; title: ; notranslate">
public class LongestCommonSubsequence {
    public static String getLongestCommonSubsequence(String s1, String s2) {
		int dp[][] = new int[s1.length()][s2.length()];
		dp[0][0] = (s1.charAt(0) == s2.charAt(0)) ? 1 : 0;
		for (int i = 1; i &lt; s1.length(); ++i) {
			if (s1.charAt(i) == s2.charAt(0)) {
				dp[i][0] = 1;
			} else {
				dp[i][0] = dp[i - 1][0];
			}
		}
		for (int i = 1; i &lt; s2.length(); ++i) {
			if (s1.charAt(0) == s2.charAt(i)) {
				dp[0][i] = 1;
			} else {
				dp[0][i] = dp[0][i - 1];
			}
		}
		for (int i = 1; i &lt; s1.length(); ++i) {
			for (int j = 1; j &lt; s2.length(); ++j) {
				if (s1.charAt(i) == s2.charAt(j)) {
					dp[i][j] = 1 + dp[i - 1][j - 1];
				} else {
					dp[i][j] = Math.max(dp[i][j - 1], dp[i - 1][j]);
				}
			}
		}
		StringBuffer sb = new StringBuffer();
		int x = s1.length() - 1, y = s2.length() - 1;
		while (x &gt;= 0 &amp;&amp; y &gt;= 0) {
			if (s1.charAt(x) == s2.charAt(y)) {
				sb.append(s1.charAt(x));
				--x;
				--y;
			} else {
				if (x &gt; 0 &amp;&amp; dp[x - 1][y] == dp[x][y]) {
					--x;
				} else {
					--y;
				}
			}
		}
		return sb.reverse().toString();
	}

	public static void main(String[] args) {
		System.out.println(getLongestCommonSubsequence(&quot;ABCDGH&quot;, &quot;AEDFHR&quot;));
		System.out.println(getLongestCommonSubsequence(&quot;AGGTAB&quot;, &quot;GXTXAYB&quot;));
	}
}
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic page generated in 1.498 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-02-22 21:59:50 -->

