<?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) embedded systems</title>
	<atom:link href="http://embeddedgurus.com/stack-overflow/2009/03/sorting-in-embedded-systems/feed/" rel="self" type="application/rss+xml" />
	<link>http://embeddedgurus.com/stack-overflow/2009/03/sorting-in-embedded-systems/</link>
	<description>Thoughts on embedded systems by Nigel Jones</description>
	<lastBuildDate>Mon, 06 Sep 2010 14:57:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Nigel Jones</title>
		<link>http://embeddedgurus.com/stack-overflow/2009/03/sorting-in-embedded-systems/comment-page-1/#comment-165</link>
		<dc:creator>Nigel Jones</dc:creator>
		<pubDate>Tue, 16 Jun 2009 01:08:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/03/15/sorting-in-embedded-systems/#comment-165</guid>
		<description>Looking over some of the comments it&#039;s interesting to see how many people claim to know what the best algorithm is - with a strong emphasis on bubble sorting. I went ahead and added the bubble and cocktail sorts - and as expected they had nothing to commend them. Gregory&#039;s additional comment that a radix sort can be performed in linear time prompted me to take a look at it. Maybe it&#039;s just the Wikipedia implementation but it appears to require dynamic memory allocation, random number generation and integer divide by 10 and integer modulo 10 arithmetic. In short it looks like a complete non starter on an embedded system.</description>
		<content:encoded><![CDATA[<p>Looking over some of the comments it&#39;s interesting to see how many people claim to know what the best algorithm is &#8211; with a strong emphasis on bubble sorting. I went ahead and added the bubble and cocktail sorts &#8211; and as expected they had nothing to commend them. Gregory&#39;s additional comment that a radix sort can be performed in linear time prompted me to take a look at it. Maybe it&#39;s just the Wikipedia implementation but it appears to require dynamic memory allocation, random number generation and integer divide by 10 and integer modulo 10 arithmetic. In short it looks like a complete non starter on an embedded system.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gregory</title>
		<link>http://embeddedgurus.com/stack-overflow/2009/03/sorting-in-embedded-systems/comment-page-1/#comment-164</link>
		<dc:creator>Gregory</dc:creator>
		<pubDate>Mon, 15 Jun 2009 19:55:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/03/15/sorting-in-embedded-systems/#comment-164</guid>
		<description>First off, any recursive algorithm can be made iterative by keeping an explicit state stack instead of relying on the call stack to preserve state (and if you know the stack size at compile time, as you often do, you can allocate that data structure on the stack; at worst, there&#039;s calloc).Second, I would have liked to see bubblesort/cocktail sort in your analysis. They perform very well for small n.Third, integers of a known width (e.g. 32-bit) can be sorted in linear time. See &lt;a href=&quot;http://en.wikipedia.org/wiki/Radix_sort&quot; rel=&quot;nofollow&quot;&gt;radix sort&lt;/a&gt;.</description>
		<content:encoded><![CDATA[<p>First off, any recursive algorithm can be made iterative by keeping an explicit state stack instead of relying on the call stack to preserve state (and if you know the stack size at compile time, as you often do, you can allocate that data structure on the stack; at worst, there&#39;s calloc).Second, I would have liked to see bubblesort/cocktail sort in your analysis. They perform very well for small n.Third, integers of a known width (e.g. 32-bit) can be sorted in linear time. See <a href="http://en.wikipedia.org/wiki/Radix_sort" rel="nofollow">radix sort</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://embeddedgurus.com/stack-overflow/2009/03/sorting-in-embedded-systems/comment-page-1/#comment-163</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Sat, 11 Apr 2009 07:12:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/03/15/sorting-in-embedded-systems/#comment-163</guid>
		<description>void shellsort(long *a, long n){        /* Sedgewick-Incerpi sequence */        long step[16] = {1, 3, 7, 21, 48, 112, 336, 861, 1968, 4592, 13776, 33936, 86961, 198768, 463792, 1391376};        long i, j, k, s, t;        k = (n &lt; 256) ? 6 : 15;        do {                for (s=step[k], i=s-1; i &lt; n; i++) {                        t = a[i];                        for (j=i; j &gt;= s &amp;&amp; t &gt; a[j-s]; a[j] = a[j-s], j -= s);                        a[j] = t;                }        } while (k--);}</description>
		<content:encoded><![CDATA[<p>void shellsort(long *a, long n){        /* Sedgewick-Incerpi sequence */        long step[16] = {1, 3, 7, 21, 48, 112, 336, 861, 1968, 4592, 13776, 33936, 86961, 198768, 463792, 1391376};        long i, j, k, s, t;        k = (n &lt; 256) ? 6 : 15;        do {                for (s=step[k], i=s-1; i &lt; n; i++) {                        t = a[i];                        for (j=i; j &gt;= s &amp;&amp; t &gt; a[j-s]; a[j] = a[j-s], j -= s);                        a[j] = t;                }        } while (k&#8211;);}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dyork</title>
		<link>http://embeddedgurus.com/stack-overflow/2009/03/sorting-in-embedded-systems/comment-page-1/#comment-162</link>
		<dc:creator>dyork</dc:creator>
		<pubDate>Fri, 10 Apr 2009 00:43:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/03/15/sorting-in-embedded-systems/#comment-162</guid>
		<description>Bubble sort was the right answer 30 years ago, with insertion sort a close second. It&#039;s still the right answer. Glad you saw the light. :)</description>
		<content:encoded><![CDATA[<p>Bubble sort was the right answer 30 years ago, with insertion sort a close second. It&#8217;s still the right answer. Glad you saw the light. <img src='http://embeddedgurus.com/stack-overflow/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://embeddedgurus.com/stack-overflow/2009/03/sorting-in-embedded-systems/comment-page-1/#comment-161</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Fri, 10 Apr 2009 00:30:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/03/15/sorting-in-embedded-systems/#comment-161</guid>
		<description>shell sort has long been my &quot;favorite&quot;, since it&#039;s easy enough to mostly remember (it&#039;s just a modified bubble sort) and is very predictable. Michael Langford: yes, brute force bubble sort works well for a VERY small number of items, but.. shell only has maybe 10-20% more code, and it works well for a MUCH larger range of items.We had a project where someone had coded a bubble sort for a small number of items, because it was quick. Then, we ended up putting in a few hundred or thousand items later. And it took MINUTES to run on a fast machine. Moral of the story is: don&#039;t use an algorithm which degrades horribly unless you have no choice..</description>
		<content:encoded><![CDATA[<p>shell sort has long been my &#8220;favorite&#8221;, since it&#8217;s easy enough to mostly remember (it&#8217;s just a modified bubble sort) and is very predictable. Michael Langford: yes, brute force bubble sort works well for a VERY small number of items, but.. shell only has maybe 10-20% more code, and it works well for a MUCH larger range of items.We had a project where someone had coded a bubble sort for a small number of items, because it was quick. Then, we ended up putting in a few hundred or thousand items later. And it took MINUTES to run on a fast machine. Moral of the story is: don&#8217;t use an algorithm which degrades horribly unless you have no choice..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harold Fowler</title>
		<link>http://embeddedgurus.com/stack-overflow/2009/03/sorting-in-embedded-systems/comment-page-1/#comment-160</link>
		<dc:creator>Harold Fowler</dc:creator>
		<pubDate>Thu, 09 Apr 2009 21:42:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/03/15/sorting-in-embedded-systems/#comment-160</guid>
		<description>Very fascinating!RTwww.anon-tools.cz.tc</description>
		<content:encoded><![CDATA[<p>Very fascinating!RTwww.anon-tools.cz.tc</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://embeddedgurus.com/stack-overflow/2009/03/sorting-in-embedded-systems/comment-page-1/#comment-159</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Thu, 09 Apr 2009 20:42:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/03/15/sorting-in-embedded-systems/#comment-159</guid>
		<description>&quot;I&#039;m not sure how a highly optimized qsort leads to lots of code overhead&quot;I think he is talking about the qsort implementing special cases. Robust implementations of algorithms can have a lot more code than a basic implementation.</description>
		<content:encoded><![CDATA[<p>&#8220;I&#8217;m not sure how a highly optimized qsort leads to lots of code overhead&#8221;I think he is talking about the qsort implementing special cases. Robust implementations of algorithms can have a lot more code than a basic implementation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nigel Jones</title>
		<link>http://embeddedgurus.com/stack-overflow/2009/03/sorting-in-embedded-systems/comment-page-1/#comment-158</link>
		<dc:creator>Nigel Jones</dc:creator>
		<pubDate>Thu, 09 Apr 2009 19:09:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/03/15/sorting-in-embedded-systems/#comment-158</guid>
		<description>What you suggest would of course work admirably for a specific case. However I&#039;m trying to generalize the solution for embedded systems, since different things come in to play when compared to sorting data in your typical database application. In many cases, the code footprint is important (as it was when I found that qsort was very large compared to my available memory). In other cases the running time is the most important. Depending upon the application, it could be the worst case running time or it might be the variability between best and worst case that is of interest. Finally the issues of dynamic memory allocation and recursion that I mentioned are also important in many (most?) embedded systems.</description>
		<content:encoded><![CDATA[<p>What you suggest would of course work admirably for a specific case. However I&#8217;m trying to generalize the solution for embedded systems, since different things come in to play when compared to sorting data in your typical database application. In many cases, the code footprint is important (as it was when I found that qsort was very large compared to my available memory). In other cases the running time is the most important. Depending upon the application, it could be the worst case running time or it might be the variability between best and worst case that is of interest. Finally the issues of dynamic memory allocation and recursion that I mentioned are also important in many (most?) embedded systems.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Langford</title>
		<link>http://embeddedgurus.com/stack-overflow/2009/03/sorting-in-embedded-systems/comment-page-1/#comment-157</link>
		<dc:creator>Michael Langford</dc:creator>
		<pubDate>Thu, 09 Apr 2009 18:33:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/03/15/sorting-in-embedded-systems/#comment-157</guid>
		<description>Perhaps I misunderstand.Aren&#039;t you doing a array of known length, where you&#039;re having greater issues with code size then runtime?Just use the sort that has the smallest footprint, then calculate what array data would be the worst case runtime, and run it a thousand times on that data while measuring your timing.If that&#039;s satisfactory, problem solved.</description>
		<content:encoded><![CDATA[<p>Perhaps I misunderstand.Aren&#8217;t you doing a array of known length, where you&#8217;re having greater issues with code size then runtime?Just use the sort that has the smallest footprint, then calculate what array data would be the worst case runtime, and run it a thousand times on that data while measuring your timing.If that&#8217;s satisfactory, problem solved.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://embeddedgurus.com/stack-overflow/2009/03/sorting-in-embedded-systems/comment-page-1/#comment-156</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Thu, 09 Apr 2009 18:29:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/03/15/sorting-in-embedded-systems/#comment-156</guid>
		<description>&gt;its running time should increase linearly ...good luck with that. O(NlogN) is about the best you can do, unless you can constrain the input so that pigeonhole sort will work.http://en.wikipedia.org/wiki/Sorting_algorithm</description>
		<content:encoded><![CDATA[<p>&gt;its running time should increase linearly &#8230;good luck with that. O(NlogN) is about the best you can do, unless you can constrain the input so that pigeonhole sort will work.http://en.wikipedia.org/wiki/Sorting_algorithm</p>
]]></content:encoded>
	</item>
</channel>
</rss>
