<?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://geeksforgeeks.org/?feed=comments-rss2" rel="self" type="application/rss+xml" />
	<link>http://geeksforgeeks.org</link>
	<description>Add Interview/written questions to Interview Corner!!</description>
	<lastBuildDate>Wed, 08 Sep 2010 14:10:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>Comment on G-Fact 30 by Venki</title>
		<link>http://geeksforgeeks.org/?p=8539&#038;cpage=1#comment-2160</link>
		<dc:creator>Venki</dc:creator>
		<pubDate>Wed, 08 Sep 2010 14:10:32 +0000</pubDate>
		<guid isPermaLink="false">http://geeksforgeeks.org/?p=8539#comment-2160</guid>
		<description>Dear Geeks, the terminology is misleading. I think the intent of &quot;G-Fact 30&quot; is to explain about operator new and operator delete (operators). When you put new() and delete() it looks like operator new function and operator delete function respectively. These two are quite different in C++ terminology. The operator calls guarantee to invoke constructors and destructors, where as the new and delete functions can&#039;t.

Example,
[sourcecode language=&quot;c&quot;]
class Memory
{
public:
    Memory()
    {
        cout &lt;&lt; &quot;Constructor called&quot; &lt;&lt; endl;
    }

    ~Memory()
    {
        cout &lt;&lt; &quot;Destructor called&quot; &lt;&lt; endl;
    }
};

The call,

// Guarantee to call constructor
Memory *mem = new Memory();

is completely different from

// Note the paranthesis and size_t type argument, no constructor call
Memory *mem = operator new(sizeof (Memory));
[/sourcecode]
The second form is similar to malloc(). We *may* use free() on such allocation. Same holds for delete.

Please correct me if I am wrong.</description>
		<content:encoded><![CDATA[<p>Dear Geeks, the terminology is misleading. I think the intent of &#8220;G-Fact 30&#8243; is to explain about operator new and operator delete (operators). When you put new() and delete() it looks like operator new function and operator delete function respectively. These two are quite different in C++ terminology. The operator calls guarantee to invoke constructors and destructors, where as the new and delete functions can&#8217;t.</p>
<p>Example,</p>
<pre class="brush: cpp;">
class Memory
{
public:
    Memory()
    {
        cout &amp;lt;&amp;lt; &amp;quot;Constructor called&amp;quot; &amp;lt;&amp;lt; endl;
    }

    ~Memory()
    {
        cout &amp;lt;&amp;lt; &amp;quot;Destructor called&amp;quot; &amp;lt;&amp;lt; endl;
    }
};

The call,

// Guarantee to call constructor
Memory *mem = new Memory();

is completely different from

// Note the paranthesis and size_t type argument, no constructor call
Memory *mem = operator new(sizeof (Memory));
</pre>
<p>The second form is similar to malloc(). We *may* use free() on such allocation. Same holds for delete.</p>
<p>Please correct me if I am wrong.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Add 1 to a given number by Venki</title>
		<link>http://geeksforgeeks.org/?p=8198&#038;cpage=1#comment-2159</link>
		<dc:creator>Venki</dc:creator>
		<pubDate>Tue, 07 Sep 2010 17:55:41 +0000</pubDate>
		<guid isPermaLink="false">http://geeksforgeeks.org/?p=8198#comment-2159</guid>
		<description>@Karthik, it should work. I guess there is some typo.

We know that the negative number is represented in 2&#039;s complement form on most of the architectures. We have the following lemma hold for 2&#039;s complement representation of signed numbers.

Say, k is numerical value of a number, then

~k = -(k+1) [ ~ is for bitwise complement ]

(k + 1) is due to addition of 1 in 2&#039;s complement conversion

To get (k + 1) apply negation once again. So, the final expression becomes

[sourcecode language=&quot;c&quot;]

inline
int increment(int x)
{
    return (-(~x));
}

inline
int decrement(int x)
{
    return (~(-x));
}

[/sourcecode]

Example, assume the machine word length is one *nibble* for simplicity.
And k = 2 (0010),
~k = ~2 = 1101 (13 numerical)
-~k = -1101
Interpreting bits 1101 in 2&#039;s complement form yeilds numerical vlaue is -(2^4 - 13) = -3. Applying &#039;-&#039; on the result leaves 3.

Same analogy holds for decrement. These results hold only for 2&#039;s complement form.

What will be the output of functions at the extremes of bit pattern? For example x = 0x80000000.</description>
		<content:encoded><![CDATA[<p>@Karthik, it should work. I guess there is some typo.</p>
<p>We know that the negative number is represented in 2&#8217;s complement form on most of the architectures. We have the following lemma hold for 2&#8217;s complement representation of signed numbers.</p>
<p>Say, k is numerical value of a number, then</p>
<p>~k = -(k+1) [ ~ is for bitwise complement ]</p>
<p>(k + 1) is due to addition of 1 in 2&#8217;s complement conversion</p>
<p>To get (k + 1) apply negation once again. So, the final expression becomes</p>
<pre class="brush: cpp;">

inline
int increment(int x)
{
    return (-(~x));
}

inline
int decrement(int x)
{
    return (~(-x));
}
</pre>
<p>Example, assume the machine word length is one *nibble* for simplicity.<br />
And k = 2 (0010),<br />
~k = ~2 = 1101 (13 numerical)<br />
-~k = -1101<br />
Interpreting bits 1101 in 2&#8217;s complement form yeilds numerical vlaue is -(2^4 &#8211; 13) = -3. Applying &#8216;-&#8217; on the result leaves 3.</p>
<p>Same analogy holds for decrement. These results hold only for 2&#8217;s complement form.</p>
<p>What will be the output of functions at the extremes of bit pattern? For example x = 0&#215;80000000.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on G-Fact 30 by GeeksforGeeks</title>
		<link>http://geeksforgeeks.org/?p=8539&#038;cpage=1#comment-2158</link>
		<dc:creator>GeeksforGeeks</dc:creator>
		<pubDate>Tue, 07 Sep 2010 14:48:23 +0000</pubDate>
		<guid isPermaLink="false">http://geeksforgeeks.org/?p=8539#comment-2158</guid>
		<description>@Hello &amp; @nik, Please see Dheeraj&#039;s comment for explanation.

@Dheeraj: Thanks for inputs.  We have added the suggested point.</description>
		<content:encoded><![CDATA[<p>@Hello &#038; @nik, Please see Dheeraj&#8217;s comment for explanation.</p>
<p>@Dheeraj: Thanks for inputs.  We have added the suggested point.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on G-Fact 30 by Dheeraj</title>
		<link>http://geeksforgeeks.org/?p=8539&#038;cpage=1#comment-2157</link>
		<dc:creator>Dheeraj</dc:creator>
		<pubDate>Tue, 07 Sep 2010 13:25:52 +0000</pubDate>
		<guid isPermaLink="false">http://geeksforgeeks.org/?p=8539#comment-2157</guid>
		<description>For delete ptr2, see below lines from http://msdn.microsoft.com/en-us/library/h6227113%28VS.80%29.aspx.

&quot;Using delete on a pointer to an object not allocated with new gives unpredictable results. You can, however, use delete on a pointer with the value 0. This provision means that, when new returns 0 on failure, deleting the result of a failed new operation is harmless. See The new and delete Operators for more information&quot; Probably the 0 thing can be added to the fact.

For delete ptr2, delete is not made at all for the stack allocated data. The run time environment takes care of allocating and deallocating memory for stack frame data. So behavior is unpredictable for this also.</description>
		<content:encoded><![CDATA[<p>For delete ptr2, see below lines from <a href="http://msdn.microsoft.com/en-us/library/h6227113%28VS.80%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/h6227113%28VS.80%29.aspx</a>.</p>
<p>&#8220;Using delete on a pointer to an object not allocated with new gives unpredictable results. You can, however, use delete on a pointer with the value 0. This provision means that, when new returns 0 on failure, deleting the result of a failed new operation is harmless. See The new and delete Operators for more information&#8221; Probably the 0 thing can be added to the fact.</p>
<p>For delete ptr2, delete is not made at all for the stack allocated data. The run time environment takes care of allocating and deallocating memory for stack frame data. So behavior is unpredictable for this also.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on G-Fact 30 by nik</title>
		<link>http://geeksforgeeks.org/?p=8539&#038;cpage=1#comment-2156</link>
		<dc:creator>nik</dc:creator>
		<pubDate>Tue, 07 Sep 2010 13:02:29 +0000</pubDate>
		<guid isPermaLink="false">http://geeksforgeeks.org/?p=8539#comment-2156</guid>
		<description>wat&#039;s the reason??????</description>
		<content:encoded><![CDATA[<p>wat&#8217;s the reason??????</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Add 1 to a given number by kartik</title>
		<link>http://geeksforgeeks.org/?p=8198&#038;cpage=1#comment-2154</link>
		<dc:creator>kartik</dc:creator>
		<pubDate>Tue, 07 Sep 2010 09:15:07 +0000</pubDate>
		<guid isPermaLink="false">http://geeksforgeeks.org/?p=8198#comment-2154</guid>
		<description>It doesn&#039;t seem to be working.  See below program prints -10.

[sourcecode language=&quot;c&quot;]#include&lt;stdio.h&gt;
#include&lt;stdlib.h&gt;

int add1(int x)
{
   return -~-x;
}


int main()
{
  printf(&quot;%d&quot;, add1(11));
  getchar();
  return 0;
}
[/sourcecode]</description>
		<content:encoded><![CDATA[<p>It doesn&#8217;t seem to be working.  See below program prints -10.</p>
<pre class="brush: cpp;">#include&lt;stdio.h&gt;
#include&lt;stdlib.h&gt;

int add1(int x)
{
   return -~-x;
}

int main()
{
  printf(&quot;%d&quot;, add1(11));
  getchar();
  return 0;
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Maximum sum such that no two elements are adjacent by Jing</title>
		<link>http://geeksforgeeks.org/?p=3133&#038;cpage=1#comment-2153</link>
		<dc:creator>Jing</dc:creator>
		<pubDate>Tue, 07 Sep 2010 06:37:37 +0000</pubDate>
		<guid isPermaLink="false">http://geeksforgeeks.org/?p=3133#comment-2153</guid>
		<description>Dynamic programming.

So if there are negative numbers, is the only difference that 1) we can skip neg numbers because they only decrease the sum; 2) for the pos number after a neg number, use the incl &amp; excl of the last pos number, and incl of the current number can include the last pos number &#039;cause they are not adjacent.

This however, doesn&#039;t change time O(n).</description>
		<content:encoded><![CDATA[<p>Dynamic programming.</p>
<p>So if there are negative numbers, is the only difference that 1) we can skip neg numbers because they only decrease the sum; 2) for the pos number after a neg number, use the incl &amp; excl of the last pos number, and incl of the current number can include the last pos number &#8217;cause they are not adjacent.</p>
<p>This however, doesn&#8217;t change time O(n).</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on What is the purpose of a function prototype? by Shriram</title>
		<link>http://geeksforgeeks.org/?p=1061&#038;cpage=1#comment-2152</link>
		<dc:creator>Shriram</dc:creator>
		<pubDate>Tue, 07 Sep 2010 00:30:09 +0000</pubDate>
		<guid isPermaLink="false">http://geeksforgeeks.org/?p=1061#comment-2152</guid>
		<description>I feel that you can order the definition of your function any how if you declare the function prototype since the compiler knows before hand looking at the prototype that it is going to encounter the function at some point of time. For eg:
[sourcecode language=&quot;c&quot;]
#include&lt;stdio.h&gt;

void foo()
{
   printf(&quot;foo called&quot;);
}

int main()
{
   foo();
   getchar();
   return 0;
}
[/sourcecode]
would work fine since when foo() is called the compiler has already seen the foo() defined above.
However, the following will not work,
[sourcecode language=&quot;c&quot;]
#include&lt;stdio.h&gt;

int main()
{
   foo();
   getchar();
   return 0;
}
void foo() /*Not OK since we do not have a prototype defined */
{
   printf(&quot;foo called&quot;);
}
[/sourcecode]
In order for this to work, you insert a function prototype for foo() so that you can define it anywhere in the file and not necessarily before the point it is called. Hence, this would work fine:
[sourcecode language=&quot;c&quot;]
#include&lt;stdio.h&gt;

void foo(void); /* function prototype */
int main()
{
   foo();
   getchar();
   return 0;
}
void foo() /* function is defined after the point it is called. It is OK since we have a function prototype. */
{
   printf(&quot;foo called&quot;);
}
[/sourcecode]</description>
		<content:encoded><![CDATA[<p>I feel that you can order the definition of your function any how if you declare the function prototype since the compiler knows before hand looking at the prototype that it is going to encounter the function at some point of time. For eg:</p>
<pre class="brush: cpp;">
#include&lt;stdio.h&gt;

void foo()
{
   printf(&quot;foo called&quot;);
}

int main()
{
   foo();
   getchar();
   return 0;
}
</pre>
<p>would work fine since when foo() is called the compiler has already seen the foo() defined above.<br />
However, the following will not work,</p>
<pre class="brush: cpp;">
#include&lt;stdio.h&gt;

int main()
{
   foo();
   getchar();
   return 0;
}
void foo() /*Not OK since we do not have a prototype defined */
{
   printf(&quot;foo called&quot;);
}
</pre>
<p>In order for this to work, you insert a function prototype for foo() so that you can define it anywhere in the file and not necessarily before the point it is called. Hence, this would work fine:</p>
<pre class="brush: cpp;">
#include&lt;stdio.h&gt;

void foo(void); /* function prototype */
int main()
{
   foo();
   getchar();
   return 0;
}
void foo() /* function is defined after the point it is called. It is OK since we have a function prototype. */
{
   printf(&quot;foo called&quot;);
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Search an element in a sorted and pivoted array by bunty</title>
		<link>http://geeksforgeeks.org/?p=1068&#038;cpage=1#comment-2151</link>
		<dc:creator>bunty</dc:creator>
		<pubDate>Mon, 06 Sep 2010 19:04:38 +0000</pubDate>
		<guid isPermaLink="false">http://geeksforgeeks.org/?p=1068#comment-2151</guid>
		<description>Corrected the above code, as it missed few conditions:
[sourcecode language=&quot;C&quot;]
int PivotedBinarySearch(arr, lo, high, num)
{
 int mid = (lo+hi)/2;
 
 if (arr[mid]==num)
    return mid;
 
 if (num &lt; arr[mid])
 {
  /* Possible that elements on left may be normal  sorted or may be pivoted sorted. So num can be in any half */
  if (ar[lo] &lt; arr[mid])
   {
    /* Normal Sorted */
    if (a[lo] &lt; num)
     /* Num is in first half and is in between lo and 
     mid */
     return binarysearch(arr, lo, mid-1, num);
    else
      PivotedBinarySearch(arr, mid+1, hi, num);
   }
  else // Pivoted sorted
   {
    if (num &lt;a&gt; a[mid])
{
 /* Similar checks as of earlier conditions */
 if (a[mid] &lt; a[hi])
 { /* Normal sorted */
   if (num &lt; a[hi])
    return binarysearch(arr, mid+1, hi, num);
   else
    /* num is in second pivoted half */
    PivotedBinarySearch(arr, lo, mid-1, num);
 }
 else
 { /* Pivoted search */
  if (a[lo] &lt; num)
   return binarysearch(arr, lo, mid-1, num);
  else
   PivotedBinarySearch(arr, mid+1, hi, num);
 }
}
}
[/sourcecode]
Please ignore all other comment and code posted, by bunty, on 5th Sep. Those have missed few conditions.</description>
		<content:encoded><![CDATA[<p>Corrected the above code, as it missed few conditions:</p>
<pre class="brush: cpp;">
int PivotedBinarySearch(arr, lo, high, num)
{
 int mid = (lo+hi)/2;

 if (arr[mid]==num)
    return mid;

 if (num &lt; arr[mid])
 {
  /* Possible that elements on left may be normal  sorted or may be pivoted sorted. So num can be in any half */
  if (ar[lo] &lt; arr[mid])
   {
    /* Normal Sorted */
    if (a[lo] &lt; num)
     /* Num is in first half and is in between lo and
     mid */
     return binarysearch(arr, lo, mid-1, num);
    else
      PivotedBinarySearch(arr, mid+1, hi, num);
   }
  else // Pivoted sorted
   {
    if (num &lt;a&gt; a[mid])
{
 /* Similar checks as of earlier conditions */
 if (a[mid] &lt; a[hi])
 { /* Normal sorted */
   if (num &lt; a[hi])
    return binarysearch(arr, mid+1, hi, num);
   else
    /* num is in second pivoted half */
    PivotedBinarySearch(arr, lo, mid-1, num);
 }
 else
 { /* Pivoted search */
  if (a[lo] &lt; num)
   return binarysearch(arr, lo, mid-1, num);
  else
   PivotedBinarySearch(arr, mid+1, hi, num);
 }
}
}
</pre>
<p>Please ignore all other comment and code posted, by bunty, on 5th Sep. Those have missed few conditions.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Floor and Ceiling in a sorted array by nikhil</title>
		<link>http://geeksforgeeks.org/?p=7342&#038;cpage=1#comment-2150</link>
		<dc:creator>nikhil</dc:creator>
		<pubDate>Mon, 06 Sep 2010 17:05:48 +0000</pubDate>
		<guid isPermaLink="false">http://geeksforgeeks.org/?p=7342#comment-2150</guid>
		<description>wat abt d floor if x=0

:P</description>
		<content:encoded><![CDATA[<p>wat abt d floor if x=0<br />
 <img src='http://geeksforgeeks.org/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on How will you print numbers from 1 to 100 without using loop? by Venki</title>
		<link>http://geeksforgeeks.org/?p=36&#038;cpage=1#comment-2149</link>
		<dc:creator>Venki</dc:creator>
		<pubDate>Mon, 06 Sep 2010 07:26:09 +0000</pubDate>
		<guid isPermaLink="false">http://geeksforgeeks.org/?p=36#comment-2149</guid>
		<description>An indirect recursion technique can be seen in the following link

http://geeksforgeeks.org/forum/topic/please-explain-it</description>
		<content:encoded><![CDATA[<p>An indirect recursion technique can be seen in the following link</p>
<p><a href="http://geeksforgeeks.org/forum/topic/please-explain-it" rel="nofollow">http://geeksforgeeks.org/forum/topic/please-explain-it</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on How will you print numbers from 1 to 100 without using loop? by umesh</title>
		<link>http://geeksforgeeks.org/?p=36&#038;cpage=1#comment-2148</link>
		<dc:creator>umesh</dc:creator>
		<pubDate>Mon, 06 Sep 2010 04:16:57 +0000</pubDate>
		<guid isPermaLink="false">http://geeksforgeeks.org/?p=36#comment-2148</guid>
		<description>1st one also fine...
its also print 1......100...
if u c initially solution putting in call stack then printing...
so o/p will come 1 2.....100</description>
		<content:encoded><![CDATA[<p>1st one also fine&#8230;<br />
its also print 1&#8230;&#8230;100&#8230;<br />
if u c initially solution putting in call stack then printing&#8230;<br />
so o/p will come 1 2&#8230;..100</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Search an element in a sorted and pivoted array by bunty</title>
		<link>http://geeksforgeeks.org/?p=1068&#038;cpage=1#comment-2147</link>
		<dc:creator>bunty</dc:creator>
		<pubDate>Sun, 05 Sep 2010 17:43:20 +0000</pubDate>
		<guid isPermaLink="false">http://geeksforgeeks.org/?p=1068#comment-2147</guid>
		<description>[sourcecode language=&quot;C&quot;]
// missed &lt; in between a[lo] and num
//if (a[lo] &lt; num)

/* Possible that elements on left may be normal sorted or may
be pivoted sorted. So num can be in any half */
if (ar[lo] &lt; arr[mid])
{
/* Normal Sorted */
if (a[lo] &lt; num)
/* Num is in second half and is in between mid and hi */
return binarysearch(arr, mid+1, hi, num);
else
PivotedBinarySearch(arr, lo, mid-1, num);
}
}
[/sourcecode]</description>
		<content:encoded><![CDATA[<pre class="brush: cpp;">
// missed &lt; in between a[lo] and num
//if (a[lo] &lt; num)

/* Possible that elements on left may be normal sorted or may
be pivoted sorted. So num can be in any half */
if (ar[lo] &lt; arr[mid])
{
/* Normal Sorted */
if (a[lo] &lt; num)
/* Num is in second half and is in between mid and hi */
return binarysearch(arr, mid+1, hi, num);
else
PivotedBinarySearch(arr, lo, mid-1, num);
}
}
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>
