<?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: Sorting in Linear time</title>
	<atom:link href="http://elliottback.com/wp/sorting-in-linear-time/feed/" rel="self" type="application/rss+xml" />
	<link>http://elliottback.com/wp/sorting-in-linear-time/</link>
	<description>Internet &#38; Technology</description>
	<lastBuildDate>Wed, 08 Feb 2012 10:01:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: e2</title>
		<link>http://elliottback.com/wp/sorting-in-linear-time/#comment-2193700</link>
		<dc:creator>e2</dc:creator>
		<pubDate>Thu, 19 Aug 2010 04:35:25 +0000</pubDate>
		<guid isPermaLink="false">http://elliottback.com/wp/?p=1198#comment-2193700</guid>
		<description>Here is the Java Standard sort(). It does not seem to use any tricks like not bounds checking. It just improves upon quicksort a bit.(copied from java standard source)

// Insertion sort on smallest arrays
	if (len &lt; 7) {
	    for (int i=off; ioff &amp;&amp; x[j-1]&gt;x[j]; j--)
		    swap(x, j, j-1);
	    return;
	}

	// Choose a partition element, v
	int m = off + (len &gt;&gt; 1);       // Small arrays, middle element
	if (len &gt; 7) {
	    int l = off;
	    int n = off + len - 1;
	    if (len &gt; 40) {        // Big arrays, pseudomedian of 9
		int s = len/8;
		l = med3(x, l,     l+s, l+2*s);
		m = med3(x, m-s,   m,   m+s);
		n = med3(x, n-2*s, n-s, n);
	    }
	    m = med3(x, l, m, n); // Mid-size, med of 3
	}
	int v = x[m];

	// Establish Invariant: v* (v)* v*
	int a = off, b = a, c = off + len - 1, d = c;
	while(true) {
	    while (b &lt;= c &amp;&amp; x[b] = b &amp;&amp; x[c] &gt;= v) {
		if (x[c] == v)
		    swap(x, c, d--);
		c--;
	    }
	    if (b &gt; c)
		break;
	    swap(x, b++, c--);
	}

	// Swap partition elements back to middle
	int s, n = off + len;
	s = Math.min(a-off, b-a  );  vecswap(x, off, b-s, s);
	s = Math.min(d-c,   n-d-1);  vecswap(x, b,   n-s, s);

	// Recursively sort non-partition-elements
	if ((s = b-a) &gt; 1)
	    sort1(x, off, s);
	if ((s = d-c) &gt; 1)
	    sort1(x, n-s, s);
    }</description>
		<content:encoded><![CDATA[<p>Here is the Java Standard sort(). It does not seem to use any tricks like not bounds checking. It just improves upon quicksort a bit.(copied from java standard source)</p>
<p>// Insertion sort on smallest arrays<br />
	if (len &lt; 7) {<br />
	    for (int i=off; ioff &amp;&amp; x[j-1]&gt;x[j]; j&#8211;)<br />
		    swap(x, j, j-1);<br />
	    return;<br />
	}</p>
<p>	// Choose a partition element, v<br />
	int m = off + (len &gt;&gt; 1);       // Small arrays, middle element<br />
	if (len &gt; 7) {<br />
	    int l = off;<br />
	    int n = off + len &#8211; 1;<br />
	    if (len &gt; 40) {        // Big arrays, pseudomedian of 9<br />
		int s = len/8;<br />
		l = med3(x, l,     l+s, l+2*s);<br />
		m = med3(x, m-s,   m,   m+s);<br />
		n = med3(x, n-2*s, n-s, n);<br />
	    }<br />
	    m = med3(x, l, m, n); // Mid-size, med of 3<br />
	}<br />
	int v = x[m];</p>
<p>	// Establish Invariant: v* (v)* v*<br />
	int a = off, b = a, c = off + len &#8211; 1, d = c;<br />
	while(true) {<br />
	    while (b &lt;= c &amp;&amp; x[b] = b &amp;&amp; x[c] &gt;= v) {<br />
		if (x[c] == v)<br />
		    swap(x, c, d&#8211;);<br />
		c&#8211;;<br />
	    }<br />
	    if (b &gt; c)<br />
		break;<br />
	    swap(x, b++, c&#8211;);<br />
	}</p>
<p>	// Swap partition elements back to middle<br />
	int s, n = off + len;<br />
	s = Math.min(a-off, b-a  );  vecswap(x, off, b-s, s);<br />
	s = Math.min(d-c,   n-d-1);  vecswap(x, b,   n-s, s);</p>
<p>	// Recursively sort non-partition-elements<br />
	if ((s = b-a) &gt; 1)<br />
	    sort1(x, off, s);<br />
	if ((s = d-c) &gt; 1)<br />
	    sort1(x, n-s, s);<br />
    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert</title>
		<link>http://elliottback.com/wp/sorting-in-linear-time/#comment-2190073</link>
		<dc:creator>Robert</dc:creator>
		<pubDate>Thu, 03 Dec 2009 21:49:00 +0000</pubDate>
		<guid isPermaLink="false">http://elliottback.com/wp/?p=1198#comment-2190073</guid>
		<description>Here&#039;s a working example where Flashsort prevails.

Not in Java, but in Adobe Flash, ironically.

http://blog.inspirit.ru/?p=271</description>
		<content:encoded><![CDATA[<p>Here&#8217;s a working example where Flashsort prevails.</p>
<p>Not in Java, but in Adobe Flash, ironically.</p>
<p><a href="http://blog.inspirit.ru/?p=271" rel="nofollow">http://blog.inspirit.ru/?p=271</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elliott Back</title>
		<link>http://elliottback.com/wp/sorting-in-linear-time/#comment-2091620</link>
		<dc:creator>Elliott Back</dc:creator>
		<pubDate>Wed, 24 Sep 2008 23:04:25 +0000</pubDate>
		<guid isPermaLink="false">http://elliottback.com/wp/?p=1198#comment-2091620</guid>
		<description>I totally agree with you!</description>
		<content:encoded><![CDATA[<p>I totally agree with you!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrasek</title>
		<link>http://elliottback.com/wp/sorting-in-linear-time/#comment-2090927</link>
		<dc:creator>Andrasek</dc:creator>
		<pubDate>Wed, 24 Sep 2008 17:38:43 +0000</pubDate>
		<guid isPermaLink="false">http://elliottback.com/wp/?p=1198#comment-2090927</guid>
		<description>I feel like I should mention that you&#039;ll never be able to write an algorithm *in Java* that is faster than the in-built .sort() algorithm.  The reason for this is due to the overhead from using arrays in Java.

For example, it&#039;s not possible for an array to have a subscript that is beyond the bounds of the array.  For example, you can&#039;t have a 100 element array and then reference cell 105.  Java throws an error.  

This simple range checking functionality on every single instance of referencing an array causes a noticeable amount of overhead.  Imagine putting an &quot;if&quot; check before every array subscript usage.  I count 24 array subscripts in the PartialFlashSort algorithm alone.  That&#039;s 24 extra checks your code performs that the in-built .sort() routine can ignore.

Also, the inbuilt .sort() algorithm uses a &quot;tuned quicksort&quot; which performs significantly better than the standard quicksort on several troublesome data sets.  Trying to beat a quicksort is a challenge in itself.  If you add to that the additional overhead that the Java language adds, there&#039;s no chance that any Java-based sorting algorithm can compete with the internal Java .sort() routine.</description>
		<content:encoded><![CDATA[<p>I feel like I should mention that you&#8217;ll never be able to write an algorithm *in Java* that is faster than the in-built .sort() algorithm.  The reason for this is due to the overhead from using arrays in Java.</p>
<p>For example, it&#8217;s not possible for an array to have a subscript that is beyond the bounds of the array.  For example, you can&#8217;t have a 100 element array and then reference cell 105.  Java throws an error.  </p>
<p>This simple range checking functionality on every single instance of referencing an array causes a noticeable amount of overhead.  Imagine putting an &#8220;if&#8221; check before every array subscript usage.  I count 24 array subscripts in the PartialFlashSort algorithm alone.  That&#8217;s 24 extra checks your code performs that the in-built .sort() routine can ignore.</p>
<p>Also, the inbuilt .sort() algorithm uses a &#8220;tuned quicksort&#8221; which performs significantly better than the standard quicksort on several troublesome data sets.  Trying to beat a quicksort is a challenge in itself.  If you add to that the additional overhead that the Java language adds, there&#8217;s no chance that any Java-based sorting algorithm can compete with the internal Java .sort() routine.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic page generated in 0.203 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-02-10 01:20:59 -->

