<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>algorithms. unplugged on C'est la Z</title><link>https://cestlaz.github.io/cestlaz-old-hugo.github.io/tags/algorithms.-unplugged/</link><description>C'est la Z (algorithms. unplugged)</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Tue, 21 Nov 2017 00:00:00 +0000</lastBuildDate><atom:link href="https://cestlaz.github.io/cestlaz-old-hugo.github.io/tags/algorithms.-unplugged/rss.xml" rel="self" type="application/rss"/><item><title>Motivating and understanding quicksort</title><link>https://cestlaz.github.io/cestlaz-old-hugo.github.io/posts/quick-sort-starting/</link><pubDate>Tue, 21 Nov 2017 00:00:00 +0000</pubDate><guid>https://cestlaz.github.io/cestlaz-old-hugo.github.io/posts/quick-sort-starting/</guid><description>&lt;p>
Thks question was posed the other day - how can one get students to
truly understand the quicksort algorithm?&lt;/p>
&lt;p>
I&amp;#39;ve written a few posts about quicksort. The last time I did a &lt;a href="https://cestlaz.github.io/posts/2014-03-12-select-to-sort.html/">lesson
writeup&lt;/a> on the subject I wrote about first looking and quickselect and
then moving to the quicksort. The class was first faced with the
problem of writing a routine to find the Kth smallest item in an
unsorted data set. The first solution was n^2 and then refined to a
quickselect. This led directly to the quicksort.&lt;/p>
&lt;p>
I liked the lesson and I think it worked well when I taught it but
that was partly due to the overall tenor of that particular group of
students.&lt;/p>
&lt;p>
A similar approach develops the quicksort in a similar way but is
both more direct and accessible.&lt;/p>
&lt;p>
The motivating problem is to put one item in a data set in its proper
place. You could select one person in class and arrange the class so
that the selected student is in their proper size place, that is
everyone shorter on one side, taller on the other. You could also do
this for age. A similar exercise could be done with any number of
manipulatives.&lt;/p>
&lt;p>
This operation of arranging the rest of the set around one selected
item or person is very easy and in fact it&amp;#39;s trivial to show that this
can be done in linear time.&lt;/p>
&lt;p>
Once we&amp;#39;ve done this arrangement, we can discuss what we can infer
from this new arrangement. We can now tell that:&lt;/p>
&lt;ul>
&lt;li>everyone to the left of the &amp;#34;pivot&amp;#34; is less than the pivot&lt;/li>
&lt;li>everyone to the right is greater&lt;/li>
&lt;li>The pivot element is at its true location if the list were&lt;/li>
&lt;/ul>
&lt;p>sorted. That is, if we started arranging around item k, then we&amp;#39;ve
moved item k to the kth location in the dataset.&lt;/p>
&lt;p>
From here it&amp;#39;s a small jump to the quicksort algorithm, just repeat
the process on the left and right data sets.&lt;/p>
&lt;p>
This approach not only makes the algorithm and its development clear
and simple but it also can be used to illustrate the worst case n^2
behavior.&lt;/p>
&lt;p>
The whole thing, minus the coding, can also be done as an unplugged activity.&lt;/p>
&lt;p>
In case anyone&amp;#39;s interested, I also wrote a post on subtle
implementation errors when writing the quicksort (&lt;a href="https://cestlaz.github.io/posts/2014-03-17-subtle-errors-sorting.html">here&lt;/a>) and also
looking at the qucksort from the point of view of different
programming paradigms (&lt;a href="https://cestlaz.github.io/posts/2010-03-14-sorting-from-top-and-from-bottom.html">here&lt;/a>).&lt;/p>
&lt;p>
Enjoy.&lt;/p></description></item></channel></rss>