<?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 on: Little LINQ puzzle</title>
	<atom:link href="http://igoro.com/archive/little-linq-puzzle/feed/" rel="self" type="application/rss+xml" />
	<link>http://igoro.com/archive/little-linq-puzzle/</link>
	<description>On programming, technology, and random things of interest</description>
	<lastBuildDate>Thu, 02 Feb 2012 01:36:06 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
	<item>
		<title>By: One LINQ operator to rule them all &#124; Igor Ostrovsky Blogging</title>
		<link>http://igoro.com/archive/little-linq-puzzle/comment-page-1/#comment-561</link>
		<dc:creator>One LINQ operator to rule them all &#124; Igor Ostrovsky Blogging</dc:creator>
		<pubDate>Wed, 09 Sep 2009 07:12:06 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/little-linq-puzzle/#comment-561</guid>
		<description>[...] you enjoyed this article, check out these LINQ puzzles. Also, read my article on the 7 tricks to simplify your programs with [...]</description>
		<content:encoded><![CDATA[<p>[...] you enjoyed this article, check out these LINQ puzzles. Also, read my article on the 7 tricks to simplify your programs with [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Igor Ostrovsky</title>
		<link>http://igoro.com/archive/little-linq-puzzle/comment-page-1/#comment-363</link>
		<dc:creator>Igor Ostrovsky</dc:creator>
		<pubDate>Tue, 16 Sep 2008 21:39:44 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/little-linq-puzzle/#comment-363</guid>
		<description>Those are some good answers. Joe, yours is particularly accurate.

Now, what about the other puzzle? Still no answer there. ;-)</description>
		<content:encoded><![CDATA[<p>Those are some good answers. Joe, yours is particularly accurate.</p>
<p>Now, what about the other puzzle? Still no answer there. <img src='http://igoro.com/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe White</title>
		<link>http://igoro.com/archive/little-linq-puzzle/comment-page-1/#comment-360</link>
		<dc:creator>Joe White</dc:creator>
		<pubDate>Mon, 15 Sep 2008 12:51:26 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/little-linq-puzzle/#comment-360</guid>
		<description>It doesn&#039;t hang; it just takes an unreasonably long time.

You end up with a &quot;tree&quot; with only 41 distinct node objects (the original empty Enumerable, plus 40 Concat decorators), which is why there&#039;s no risk of an OutOfMemoryException. But the second node down serves double duty -- it&#039;s both the left and the right child of the top node. The third node down serves quadruple duty, the fourth 8x, the fifth 16x, etc.

ToArray() has to traverse the entire tree, and it&#039;s not visiting 40 objects -- it&#039;s visiting all 2,199,023,255,551 nodes in the tree (2^41 - 1). Even a &quot;for&quot; loop with that many iterations will take longer than most of us are willing to wait.

It&#039;s not the 40 layers of decorators that kill you, it&#039;s the fact that every single layer (except the first) is visited more than once, which takes you into exponential time.</description>
		<content:encoded><![CDATA[<p>It doesn&#8217;t hang; it just takes an unreasonably long time.</p>
<p>You end up with a &#8220;tree&#8221; with only 41 distinct node objects (the original empty Enumerable, plus 40 Concat decorators), which is why there&#8217;s no risk of an OutOfMemoryException. But the second node down serves double duty &#8212; it&#8217;s both the left and the right child of the top node. The third node down serves quadruple duty, the fourth 8x, the fifth 16x, etc.</p>
<p>ToArray() has to traverse the entire tree, and it&#8217;s not visiting 40 objects &#8212; it&#8217;s visiting all 2,199,023,255,551 nodes in the tree (2^41 &#8211; 1). Even a &#8220;for&#8221; loop with that many iterations will take longer than most of us are willing to wait.</p>
<p>It&#8217;s not the 40 layers of decorators that kill you, it&#8217;s the fact that every single layer (except the first) is visited more than once, which takes you into exponential time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pete</title>
		<link>http://igoro.com/archive/little-linq-puzzle/comment-page-1/#comment-357</link>
		<dc:creator>Pete</dc:creator>
		<pubDate>Fri, 12 Sep 2008 14:37:41 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/little-linq-puzzle/#comment-357</guid>
		<description>Got it; I think...

Enumerable.Concat has a parameter (first) which is the first sequence to concatinate which is itself.  Because of this you get massive recursion that&#039;s why it appears to hang.  Am I correct ?</description>
		<content:encoded><![CDATA[<p>Got it; I think&#8230;</p>
<p>Enumerable.Concat has a parameter (first) which is the first sequence to concatinate which is itself.  Because of this you get massive recursion that&#8217;s why it appears to hang.  Am I correct ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pete</title>
		<link>http://igoro.com/archive/little-linq-puzzle/comment-page-1/#comment-356</link>
		<dc:creator>Pete</dc:creator>
		<pubDate>Fri, 12 Sep 2008 14:27:02 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/little-linq-puzzle/#comment-356</guid>
		<description>Instead of

empty = empty.Concat(empty)

just have 

empty.Concat(empty)

it will run fine.  Still trying to figure out why...</description>
		<content:encoded><![CDATA[<p>Instead of</p>
<p>empty = empty.Concat(empty)</p>
<p>just have </p>
<p>empty.Concat(empty)</p>
<p>it will run fine.  Still trying to figure out why&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pete</title>
		<link>http://igoro.com/archive/little-linq-puzzle/comment-page-1/#comment-355</link>
		<dc:creator>Pete</dc:creator>
		<pubDate>Fri, 12 Sep 2008 14:24:23 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/little-linq-puzzle/#comment-355</guid>
		<description>Actually it doesn&#039;t hang on the last line.  The problem is with the Concat operation.  If you decrease the for-loop iteration to something smaller (like 10) the code snippet will execute and emptyArray will be the equivalent to Enumerable.Empty or {int[0]}.  The Concat operations slows things down exponentially and in the end you&#039;ll end up with an OutOfMemoryException.  Why ?  I don&#039;t have a clue...yet :)</description>
		<content:encoded><![CDATA[<p>Actually it doesn&#8217;t hang on the last line.  The problem is with the Concat operation.  If you decrease the for-loop iteration to something smaller (like 10) the code snippet will execute and emptyArray will be the equivalent to Enumerable.Empty or {int[0]}.  The Concat operations slows things down exponentially and in the end you&#8217;ll end up with an OutOfMemoryException.  Why ?  I don&#8217;t have a clue&#8230;yet <img src='http://igoro.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: beefarino</title>
		<link>http://igoro.com/archive/little-linq-puzzle/comment-page-1/#comment-354</link>
		<dc:creator>beefarino</dc:creator>
		<pubDate>Fri, 12 Sep 2008 12:49:49 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/little-linq-puzzle/#comment-354</guid>
		<description>Hi Igor!

Concat() execution is deferred, so each call to Concat() returns a decorated IEnumerable instance; by Concat()ing the collection to itself 40 times, you end up with a tree of (I believe) 40! unique collection instances that must be traversed during the call to ToArray().

jimbo</description>
		<content:encoded><![CDATA[<p>Hi Igor!</p>
<p>Concat() execution is deferred, so each call to Concat() returns a decorated IEnumerable instance; by Concat()ing the collection to itself 40 times, you end up with a tree of (I believe) 40! unique collection instances that must be traversed during the call to ToArray().</p>
<p>jimbo</p>
]]></content:encoded>
	</item>
</channel>
</rss>

