<?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: A simple shuffle that proved not so simple after all</title>
	<atom:link href="http://szeryf.wordpress.com/2007/06/19/a-simple-shuffle-that-proved-not-so-simple-after-all/feed/" rel="self" type="application/rss+xml" />
	<link>http://szeryf.wordpress.com/2007/06/19/a-simple-shuffle-that-proved-not-so-simple-after-all/</link>
	<description>The blog with the bug.</description>
	<lastBuildDate>Thu, 23 May 2013 14:32:44 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Student</title>
		<link>http://szeryf.wordpress.com/2007/06/19/a-simple-shuffle-that-proved-not-so-simple-after-all/#comment-941</link>
		<dc:creator><![CDATA[Student]]></dc:creator>
		<pubDate>Thu, 15 Jan 2009 04:04:08 +0000</pubDate>
		<guid isPermaLink="false">http://szeryf.wordpress.com/2007/06/19/a-simple-shuffle-that-proved-not-so-simple-after-all/#comment-941</guid>
		<description><![CDATA[Style cop!

&lt;code&gt;class Array
&#160;&#160;def shuffle!
&#160;&#160;&#160;&#160;(1...size).each do &#124;j&#124;
&#160;&#160;&#160;&#160;&#160;&#160;r = rand(j+1)
&#160;&#160;&#160;&#160;&#160;&#160;self[r], self[j] = at(j), at(r)
&#160;&#160;&#160;&#160;end
&#160;&#160;&#160;&#160;self
&#160;&#160;end
&#160;&#160;def shuffle
&#160;&#160;&#160;&#160;dup.shuffle!
&#160;&#160;end
end
&lt;/code&gt;
&lt;code&gt;at&lt;/code&gt; is supposed to be a bit faster than &lt;code&gt;[]&lt;/code&gt;, but it is rhs only.
minimize the arithmetic inside the loop.
minimize the arithmetic outside the loop.
allow the user to decide if he wants to pay for the &lt;code&gt;dup&lt;/code&gt; or not.]]></description>
		<content:encoded><![CDATA[<p>Style cop!</p>
<p><code>class Array<br />
&nbsp;&nbsp;def shuffle!<br />
&nbsp;&nbsp;&nbsp;&nbsp;(1...size).each do |j|<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r = rand(j+1)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self[r], self[j] = at(j), at(r)<br />
&nbsp;&nbsp;&nbsp;&nbsp;end<br />
&nbsp;&nbsp;&nbsp;&nbsp;self<br />
&nbsp;&nbsp;end<br />
&nbsp;&nbsp;def shuffle<br />
&nbsp;&nbsp;&nbsp;&nbsp;dup.shuffle!<br />
&nbsp;&nbsp;end<br />
end<br />
</code><br />
<code>at</code> is supposed to be a bit faster than <code>[]</code>, but it is rhs only.<br />
minimize the arithmetic inside the loop.<br />
minimize the arithmetic outside the loop.<br />
allow the user to decide if he wants to pay for the <code>dup</code> or not.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: not-just-yeti</title>
		<link>http://szeryf.wordpress.com/2007/06/19/a-simple-shuffle-that-proved-not-so-simple-after-all/#comment-484</link>
		<dc:creator><![CDATA[not-just-yeti]]></dc:creator>
		<pubDate>Sat, 22 Mar 2008 11:46:40 +0000</pubDate>
		<guid isPermaLink="false">http://szeryf.wordpress.com/2007/06/19/a-simple-shuffle-that-proved-not-so-simple-after-all/#comment-484</guid>
		<description><![CDATA[Ah, thanks.

After a bunch of thinking, it can be proved that *no* sort algorithm will make shuffle_sort work (meaning that this isn&#039;t just the details of quicksort that muck things up; it won&#039;t work for mergesort or anything else):
  If the sort algorithm makes k comparisons (i.e. k calls to rand), then there are 2^k possible executions, which can&#039;t be *uniformly* mapped onto the n! possible shuffled outputs.

(As I write that, I realize it&#039;s the same idea made about a non-sorting algorithm, on the post you linked to.)]]></description>
		<content:encoded><![CDATA[<p>Ah, thanks.</p>
<p>After a bunch of thinking, it can be proved that *no* sort algorithm will make shuffle_sort work (meaning that this isn&#8217;t just the details of quicksort that muck things up; it won&#8217;t work for mergesort or anything else):<br />
  If the sort algorithm makes k comparisons (i.e. k calls to rand), then there are 2^k possible executions, which can&#8217;t be *uniformly* mapped onto the n! possible shuffled outputs.</p>
<p>(As I write that, I realize it&#8217;s the same idea made about a non-sorting algorithm, on the post you linked to.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: szeryf</title>
		<link>http://szeryf.wordpress.com/2007/06/19/a-simple-shuffle-that-proved-not-so-simple-after-all/#comment-482</link>
		<dc:creator><![CDATA[szeryf]]></dc:creator>
		<pubDate>Fri, 21 Mar 2008 21:25:36 +0000</pubDate>
		<guid isPermaLink="false">http://szeryf.wordpress.com/2007/06/19/a-simple-shuffle-that-proved-not-so-simple-after-all/#comment-482</guid>
		<description><![CDATA[not-just-yeti: it doesn&#039;t. If you read the last part of this article (under &quot;just one more thing&quot;) you&#039;ll see that I show that the results are not uniform.

Also see http://www.codinghorror.com/blog/archives/001015.html if you want more proof.]]></description>
		<content:encoded><![CDATA[<p>not-just-yeti: it doesn&#8217;t. If you read the last part of this article (under &#8220;just one more thing&#8221;) you&#8217;ll see that I show that the results are not uniform.</p>
<p>Also see <a href="http://www.codinghorror.com/blog/archives/001015.html" rel="nofollow">http://www.codinghorror.com/blog/archives/001015.html</a> if you want more proof.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: not-just-yeti</title>
		<link>http://szeryf.wordpress.com/2007/06/19/a-simple-shuffle-that-proved-not-so-simple-after-all/#comment-481</link>
		<dc:creator><![CDATA[not-just-yeti]]></dc:creator>
		<pubDate>Fri, 21 Mar 2008 21:18:09 +0000</pubDate>
		<guid isPermaLink="false">http://szeryf.wordpress.com/2007/06/19/a-simple-shuffle-that-proved-not-so-simple-after-all/#comment-481</guid>
		<description><![CDATA[Maybe I&#039;m an idiot, but is it obvious that
   arr.sort{rand(3)-1}
really gives a uniform distribution?  It seems to depend on the details of the sort.

(For example, if we were to use bubblesort, the probability that the first element ends up last is only 1/2^n, instead of 1/n.  So for quicksort, I need some convincing that the results really are uniform.)

(Also, at the very least, that cute-but-inefficient version would want to use 
   arr.sort{ 2*rand(2)-1 }
)]]></description>
		<content:encoded><![CDATA[<p>Maybe I&#8217;m an idiot, but is it obvious that<br />
   arr.sort{rand(3)-1}<br />
really gives a uniform distribution?  It seems to depend on the details of the sort.</p>
<p>(For example, if we were to use bubblesort, the probability that the first element ends up last is only 1/2^n, instead of 1/n.  So for quicksort, I need some convincing that the results really are uniform.)</p>
<p>(Also, at the very least, that cute-but-inefficient version would want to use<br />
   arr.sort{ 2*rand(2)-1 }<br />
)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: [Be el o ge] &#187; Blog Archive &#187; Shuffle Algorithm</title>
		<link>http://szeryf.wordpress.com/2007/06/19/a-simple-shuffle-that-proved-not-so-simple-after-all/#comment-480</link>
		<dc:creator><![CDATA[[Be el o ge] &#187; Blog Archive &#187; Shuffle Algorithm]]></dc:creator>
		<pubDate>Fri, 21 Mar 2008 10:18:03 +0000</pubDate>
		<guid isPermaLink="false">http://szeryf.wordpress.com/2007/06/19/a-simple-shuffle-that-proved-not-so-simple-after-all/#comment-480</guid>
		<description><![CDATA[[...] Update and this is too! [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Update and this is too! [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Bernier</title>
		<link>http://szeryf.wordpress.com/2007/06/19/a-simple-shuffle-that-proved-not-so-simple-after-all/#comment-422</link>
		<dc:creator><![CDATA[Daniel Bernier]]></dc:creator>
		<pubDate>Thu, 10 Jan 2008 18:30:00 +0000</pubDate>
		<guid isPermaLink="false">http://szeryf.wordpress.com/2007/06/19/a-simple-shuffle-that-proved-not-so-simple-after-all/#comment-422</guid>
		<description><![CDATA[Very nice explanation &amp; illustration of Big O notation...those benchmark numbers lay it out pretty clearly.

delicious&#039;ed.]]></description>
		<content:encoded><![CDATA[<p>Very nice explanation &amp; illustration of Big O notation&#8230;those benchmark numbers lay it out pretty clearly.</p>
<p>delicious&#8217;ed.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: szeryf</title>
		<link>http://szeryf.wordpress.com/2007/06/19/a-simple-shuffle-that-proved-not-so-simple-after-all/#comment-405</link>
		<dc:creator><![CDATA[szeryf]]></dc:creator>
		<pubDate>Sat, 05 Jan 2008 10:21:20 +0000</pubDate>
		<guid isPermaLink="false">http://szeryf.wordpress.com/2007/06/19/a-simple-shuffle-that-proved-not-so-simple-after-all/#comment-405</guid>
		<description><![CDATA[Tarun: I&#039;m sorry but you must have got that entirely backwards. The hidden constant is hidden because it doesn&#039;t matter when you compare two algorithms. You don&#039;t have to know how big it is. 

Consider two functions: F(n) = A * n and G(n) = B * n * n, where A and B could be arbitrarily large, but constant numbers. Do you need to know A and B values to tell that given n big enough, G(n) &gt; F(n)? 

Or, more formally, we can easily prove that there is some N that for every n &gt; N, G(n) &gt; F(n) holds. Which means that it holds for &lt;a href=&quot;http://en.wikipedia.org/wiki/Almost_all&quot; rel=&quot;nofollow&quot;&gt;&quot;almost all&quot;&lt;/a&gt; numbers. And this is enough for algorithmic theory to say &quot;G is slower(bigger) than F&quot; because the theory compares their asymptotic complexities, that is where n increases to infinity.]]></description>
		<content:encoded><![CDATA[<p>Tarun: I&#8217;m sorry but you must have got that entirely backwards. The hidden constant is hidden because it doesn&#8217;t matter when you compare two algorithms. You don&#8217;t have to know how big it is. </p>
<p>Consider two functions: F(n) = A * n and G(n) = B * n * n, where A and B could be arbitrarily large, but constant numbers. Do you need to know A and B values to tell that given n big enough, G(n) &gt; F(n)? </p>
<p>Or, more formally, we can easily prove that there is some N that for every n &gt; N, G(n) &gt; F(n) holds. Which means that it holds for <a href="http://en.wikipedia.org/wiki/Almost_all" rel="nofollow">&#8220;almost all&#8221;</a> numbers. And this is enough for algorithmic theory to say &#8220;G is slower(bigger) than F&#8221; because the theory compares their asymptotic complexities, that is where n increases to infinity.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tarun</title>
		<link>http://szeryf.wordpress.com/2007/06/19/a-simple-shuffle-that-proved-not-so-simple-after-all/#comment-402</link>
		<dc:creator><![CDATA[Tarun]]></dc:creator>
		<pubDate>Sat, 05 Jan 2008 01:32:39 +0000</pubDate>
		<guid isPermaLink="false">http://szeryf.wordpress.com/2007/06/19/a-simple-shuffle-that-proved-not-so-simple-after-all/#comment-402</guid>
		<description><![CDATA[Sir, Please tell me how do we prove that one algorithm is faster than the other by finding out the hidden constants]]></description>
		<content:encoded><![CDATA[<p>Sir, Please tell me how do we prove that one algorithm is faster than the other by finding out the hidden constants</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kilkoi</title>
		<link>http://szeryf.wordpress.com/2007/06/19/a-simple-shuffle-that-proved-not-so-simple-after-all/#comment-372</link>
		<dc:creator><![CDATA[Kilkoi]]></dc:creator>
		<pubDate>Sun, 23 Dec 2007 19:02:46 +0000</pubDate>
		<guid isPermaLink="false">http://szeryf.wordpress.com/2007/06/19/a-simple-shuffle-that-proved-not-so-simple-after-all/#comment-372</guid>
		<description><![CDATA[Cool topic! ;)]]></description>
		<content:encoded><![CDATA[<p>Cool topic! ;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jetru</title>
		<link>http://szeryf.wordpress.com/2007/06/19/a-simple-shuffle-that-proved-not-so-simple-after-all/#comment-367</link>
		<dc:creator><![CDATA[Jetru]]></dc:creator>
		<pubDate>Thu, 20 Dec 2007 20:01:17 +0000</pubDate>
		<guid isPermaLink="false">http://szeryf.wordpress.com/2007/06/19/a-simple-shuffle-that-proved-not-so-simple-after-all/#comment-367</guid>
		<description><![CDATA[Superb! One of the better blogs i&#039;ve come across! I&#039;m a regular! :) And awesome site design :D]]></description>
		<content:encoded><![CDATA[<p>Superb! One of the better blogs i&#8217;ve come across! I&#8217;m a regular! :) And awesome site design :D</p>
]]></content:encoded>
	</item>
</channel>
</rss>
