<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Just Another Programming Puzzle (Finding one non repeating element in list of pairs)</title>
	<atom:link href="http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/feed/" rel="self" type="application/rss+xml" />
	<link>http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/</link>
	<description>Why am I fighting to live, if I am living to die ?</description>
	<lastBuildDate>Fri, 19 Mar 2010 13:12:13 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Owen</title>
		<link>http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-26953</link>
		<dc:creator>Owen</dc:creator>
		<pubDate>Fri, 12 Sep 2008 01:13:33 +0000</pubDate>
		<guid isPermaLink="false">http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-26953</guid>
		<description>Actually,

My original algorithm will work and will be slightly faster than quick sort because you only recurse down a fraction of the tree.

But, it&#039;s still not linear time.</description>
		<content:encoded><![CDATA[<p>Actually,</p>
<p>My original algorithm will work and will be slightly faster than quick sort because you only recurse down a fraction of the tree.</p>
<p>But, it&#8217;s still not linear time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Owen</title>
		<link>http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-26952</link>
		<dc:creator>Owen</dc:creator>
		<pubDate>Fri, 12 Sep 2008 01:10:55 +0000</pubDate>
		<guid isPermaLink="false">http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-26952</guid>
		<description>Sorry

scratch that, I haven&#039;t had my morning coffee

Just sort O (n log n) then scan through (O (n))</description>
		<content:encoded><![CDATA[<p>Sorry</p>
<p>scratch that, I haven&#8217;t had my morning coffee</p>
<p>Just sort O (n log n) then scan through (O (n))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Owen</title>
		<link>http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-26951</link>
		<dc:creator>Owen</dc:creator>
		<pubDate>Fri, 12 Sep 2008 01:08:06 +0000</pubDate>
		<guid isPermaLink="false">http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-26951</guid>
		<description>The proposed algorithm clearly does not work.

if the list is [5, 4, 6, 4, 5]

then,

result = (((5 XOR 4) XOR 6) XOR 4) XOR 5
       = (( 0 XOR 6) XOR 4) XOR 5
       = (6 XOR 4) XOR 5
       = 0 XOR 5
       = 5

Perhaps I&#039;ve misunderstood ?

There&#039;s an intuitive solution to this problem, based on quick sort. It&#039;s O (n log n) though

Pick an element at random, the pivot, and then move the elements less than this number into one set and the elements greater into another set.

If your two sets are of equal size, then stop and return the pivot.

Repeat on the list that has an odd size.</description>
		<content:encoded><![CDATA[<p>The proposed algorithm clearly does not work.</p>
<p>if the list is [5, 4, 6, 4, 5]</p>
<p>then,</p>
<p>result = (((5 XOR 4) XOR 6) XOR 4) XOR 5<br />
       = (( 0 XOR 6) XOR 4) XOR 5<br />
       = (6 XOR 4) XOR 5<br />
       = 0 XOR 5<br />
       = 5</p>
<p>Perhaps I&#8217;ve misunderstood ?</p>
<p>There&#8217;s an intuitive solution to this problem, based on quick sort. It&#8217;s O (n log n) though</p>
<p>Pick an element at random, the pivot, and then move the elements less than this number into one set and the elements greater into another set.</p>
<p>If your two sets are of equal size, then stop and return the pivot.</p>
<p>Repeat on the list that has an odd size.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: yashez</title>
		<link>http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-26944</link>
		<dc:creator>yashez</dc:creator>
		<pubDate>Wed, 10 Sep 2008 02:04:54 +0000</pubDate>
		<guid isPermaLink="false">http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-26944</guid>
		<description>@Arthur Rodrigues:

(4 ^ 5) = 1, and it works</description>
		<content:encoded><![CDATA[<p>@Arthur Rodrigues:</p>
<p>(4 ^ 5) = 1, and it works</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arthur Rodrigues</title>
		<link>http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-26504</link>
		<dc:creator>Arthur Rodrigues</dc:creator>
		<pubDate>Sat, 02 Aug 2008 13:24:42 +0000</pubDate>
		<guid isPermaLink="false">http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-26504</guid>
		<description>By the way.. Let&#039;s manually run the proposed algorithm for the following list: ( 4,5,4,7,5 )


(4 ^ 5) ^ 4 ^ 7 ^ 5

( 0 ^ 4 ) ^ 7 ^ 5

(4 ^ 7 )  ^ 5

0 ^ 5 = 5 .. and 5 is not the non repeating element....</description>
		<content:encoded><![CDATA[<p>By the way.. Let&#8217;s manually run the proposed algorithm for the following list: ( 4,5,4,7,5 )</p>
<p>(4 ^ 5) ^ 4 ^ 7 ^ 5</p>
<p>( 0 ^ 4 ) ^ 7 ^ 5</p>
<p>(4 ^ 7 )  ^ 5</p>
<p>0 ^ 5 = 5 .. and 5 is not the non repeating element&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hisham abd El-Hafez</title>
		<link>http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-25863</link>
		<dc:creator>Hisham abd El-Hafez</dc:creator>
		<pubDate>Mon, 12 May 2008 13:30:11 +0000</pubDate>
		<guid isPermaLink="false">http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-25863</guid>
		<description>Vinayak, 
Yeah you are right, my solution will only work if the array is symmetric. 
my mistake :)</description>
		<content:encoded><![CDATA[<p>Vinayak,<br />
Yeah you are right, my solution will only work if the array is symmetric.<br />
my mistake <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vinayak</title>
		<link>http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-25808</link>
		<dc:creator>Vinayak</dc:creator>
		<pubDate>Wed, 30 Apr 2008 13:21:21 +0000</pubDate>
		<guid isPermaLink="false">http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-25808</guid>
		<description>@ Hisham abd El-Hafez:

Actually your solution works only if the pairs are quasi symmetrically placed and if your pairless number is not the center number then you end up performing the same operation on both the numbers of atlease 1 pair;
eg: 4 4 5 7 5 
according to your solution we actuallly have 

4 + 4 + 5 - 7 - 5 = 1</description>
		<content:encoded><![CDATA[<p>@ Hisham abd El-Hafez:</p>
<p>Actually your solution works only if the pairs are quasi symmetrically placed and if your pairless number is not the center number then you end up performing the same operation on both the numbers of atlease 1 pair;<br />
eg: 4 4 5 7 5<br />
according to your solution we actuallly have </p>
<p>4 + 4 + 5 &#8211; 7 &#8211; 5 = 1</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hisham abd El-Hafez</title>
		<link>http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-25652</link>
		<dc:creator>Hisham abd El-Hafez</dc:creator>
		<pubDate>Sun, 06 Apr 2008 07:43:03 +0000</pubDate>
		<guid isPermaLink="false">http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-25652</guid>
		<description>san, the problem definition states that you should solve it in O(1) extra space, using your map, the extra space complexity will be O(n-1)</description>
		<content:encoded><![CDATA[<p>san, the problem definition states that you should solve it in O(1) extra space, using your map, the extra space complexity will be O(n-1)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: san</title>
		<link>http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-25643</link>
		<dc:creator>san</dc:creator>
		<pubDate>Sat, 05 Apr 2008 05:57:43 +0000</pubDate>
		<guid isPermaLink="false">http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-25643</guid>
		<description>Create Map

Loop thru your array and check

if elememt in aaray exist in map , if not then add

if exists then remove

Finally only one element will left will be your non repeated elemet.</description>
		<content:encoded><![CDATA[<p>Create Map</p>
<p>Loop thru your array and check</p>
<p>if elememt in aaray exist in map , if not then add</p>
<p>if exists then remove</p>
<p>Finally only one element will left will be your non repeated elemet.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hisham abd El-Hafez</title>
		<link>http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-25618</link>
		<dc:creator>Hisham abd El-Hafez</dc:creator>
		<pubDate>Wed, 02 Apr 2008 16:31:10 +0000</pubDate>
		<guid isPermaLink="false">http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-25618</guid>
		<description>ok, I have another solution 

Fact: all of list elements has another element equivalent except for one element, which means that list length is an odd number 
 
if you start from the beginning the list and add the numbers to each other, until you reach the middle number, then you start subtracting numbers from the total until you are done, then the final count will be the number with no corresponding peer


int Foo(int[] arr)
{
  int count = arr[0];
  for(int i = 0; i &lt; arr.Length; i++)
  {
	if( i &lt;= (size - 1) / 2) 
	   count += arr[i];
        else
	   count -= arr[i];
  }
  return count;
}</description>
		<content:encoded><![CDATA[<p>ok, I have another solution </p>
<p>Fact: all of list elements has another element equivalent except for one element, which means that list length is an odd number </p>
<p>if you start from the beginning the list and add the numbers to each other, until you reach the middle number, then you start subtracting numbers from the total until you are done, then the final count will be the number with no corresponding peer</p>
<p>int Foo(int[] arr)<br />
{<br />
  int count = arr[0];<br />
  for(int i = 0; i &lt; arr.Length; i++)<br />
  {<br />
	if( i &lt;= (size &#8211; 1) / 2)<br />
	   count += arr[i];<br />
        else<br />
	   count -= arr[i];<br />
  }<br />
  return count;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Haroon Saeed</title>
		<link>http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-25439</link>
		<dc:creator>Haroon Saeed</dc:creator>
		<pubDate>Wed, 12 Mar 2008 19:51:56 +0000</pubDate>
		<guid isPermaLink="false">http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-25439</guid>
		<description>Ohh well Qasim Pasta!! there was a typo, ammended it.. :), well I dont think capturing the first element and running the loop n - 1 times will make any difference, though your comment and intention noted :)...

Thx for poiting out the typo..</description>
		<content:encoded><![CDATA[<p>Ohh well Qasim Pasta!! there was a typo, ammended it.. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> , well I dont think capturing the first element and running the loop n &#8211; 1 times will make any difference, though your comment and intention noted <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> &#8230;</p>
<p>Thx for poiting out the typo..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Muhammad Qasim Pasta</title>
		<link>http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-25438</link>
		<dc:creator>Muhammad Qasim Pasta</dc:creator>
		<pubDate>Wed, 12 Mar 2008 19:16:02 +0000</pubDate>
		<guid isPermaLink="false">http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-25438</guid>
		<description>and what about make it little bit more efficient ...

int Foo(int [] nList)
{
int result = nList[0]; // we know the first element
for (int i = 1; i &lt; nList.Length; i++) // running one less than total numbers
result ^= nList[i];

return result;
}</description>
		<content:encoded><![CDATA[<p>and what about make it little bit more efficient &#8230;</p>
<p>int Foo(int [] nList)<br />
{<br />
int result = nList[0]; // we know the first element<br />
for (int i = 1; i &lt; nList.Length; i++) // running one less than total numbers<br />
result ^= nList[i];</p>
<p>return result;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Muhammad Qasim Pasta</title>
		<link>http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-25437</link>
		<dc:creator>Muhammad Qasim Pasta</dc:creator>
		<pubDate>Wed, 12 Mar 2008 19:13:28 +0000</pubDate>
		<guid isPermaLink="false">http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-25437</guid>
		<description>I think a little bit modification require ... 

result ^= nList[i]</description>
		<content:encoded><![CDATA[<p>I think a little bit modification require &#8230; </p>
<p>result ^= nList[i]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Haroon Saeed</title>
		<link>http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-25431</link>
		<dc:creator>Haroon Saeed</dc:creator>
		<pubDate>Wed, 12 Mar 2008 07:44:39 +0000</pubDate>
		<guid isPermaLink="false">http://haroonsaeed.wordpress.com/2008/03/12/just-another-programming-puzzle-finding-one-non-repeating-element-in-list-of-pairs/#comment-25431</guid>
		<description>The solution is as follows remember the list is not sorted,

FACT 1: XORing a number with 0 will return the number itself.

FACT 2: XORing a number with itself will return 0.

So when we XOR all the elements with each other in a list of number in which each number is repeated once except one number we will get the non repeated number. For example if List is {5,4,6,4,5} we will get 6 if we execute this: 5 XOR 4 XOR 6 XOR 4 XOR 5.

Here is the C Sharp Source to do the same.

int Foo(int [] nList)
{
    int result = 0;
    for (int i = 0; i &lt; nList.Length; i++)
         result ^= nList[i];
    return result;
}

In C Sharp &#039;^&#039; is the operator for XOR, This piece of code takes O(n) time and O(1) extra space.</description>
		<content:encoded><![CDATA[<p>The solution is as follows remember the list is not sorted,</p>
<p>FACT 1: XORing a number with 0 will return the number itself.</p>
<p>FACT 2: XORing a number with itself will return 0.</p>
<p>So when we XOR all the elements with each other in a list of number in which each number is repeated once except one number we will get the non repeated number. For example if List is {5,4,6,4,5} we will get 6 if we execute this: 5 XOR 4 XOR 6 XOR 4 XOR 5.</p>
<p>Here is the C Sharp Source to do the same.</p>
<p>int Foo(int [] nList)<br />
{<br />
    int result = 0;<br />
    for (int i = 0; i &lt; nList.Length; i++)<br />
         result ^= nList[i];<br />
    return result;<br />
}</p>
<p>In C Sharp &#8216;^&#8217; is the operator for XOR, This piece of code takes O(n) time and O(1) extra space.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
