<?xml version="1.0" encoding="UTF-8" ?>
  <resource>
  <id>8192</id>
  <path>/www/nrich/html/content/id/8192/</path>
  <resourceTypeID>1</resourceTypeID>
  <last_published>0000-00-00T00:00:00</last_published>
  <indexXML>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;mdoxml version=&quot;1.0&quot;&gt;&lt;p&gt;Take some numbered cards; between ten and twenty should be enough (you could use a suit from a pack of playing cards).&lt;br&gt;&lt;/br&gt;
Shuffle the cards.&lt;br&gt;&lt;/br&gt;
Then organise your deck of cards into numerical order.&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
&lt;strong&gt;What method did you use to put them in numerical order?&lt;/strong&gt;&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
Can you think of any other ways you could have sorted them?&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
Here are some different sorting algorithms you could try. You may find it easiest to lay the cards out in a line to keep track of their order and see what&amp;#39;s happening at a glance.&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
&lt;strong&gt;Bubble Sort&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;toggle&quot;&gt;Compare the first two cards. If they are in the wrong order, swap them round. Then compare the second and third card. If they are in the wrong order, swap them round. Keep going through the pack. When you have finished, keep the cards in the new order and repeat the process from the beginning of the pack.&lt;br&gt;&lt;/br&gt;
Repeat until you get all the way through the pack without doing any swaps. The cards are now sorted.&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Shuttle Sort&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;toggle&quot;&gt;First pass: compare the first two cards. Swap them if necessary.&lt;br&gt;&lt;/br&gt;
Second pass: compare the second and third cards. Swap them if necessary, and then compare the first two cards again, and swap if necessary.&lt;br&gt;&lt;/br&gt;
Third pass: compare the third and fourth cards. Swap them if necessary, then compare second and third, swap if necessary, then compare first and second, then swap if necessary.&lt;br&gt;&lt;/br&gt;
Continue in the same way for the rest of the pack.&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Selection Sort&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;toggle&quot;&gt;Go through the pack until you find the Ace. Swap it with the first card. Then go through the pack until you find the Two. Swap it with the second card. Then go through the pack until you find the Three. Swap it with the third card. Repeat with the rest of the cards.&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Insertion Sort&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;toggle&quot;&gt;Put the first card down. Take the second card, and put it to the right or to the left of the first card, depending on whether it&amp;#39;s higher or lower. Then take the third card and place it correctly relative to the first two cards, making a space if necessary. Take the fourth card and place it correctly relative to the first three cards, making a space if necessary. Keep going
until all the cards are in order in the new pile.&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Quick Sort&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;toggle&quot;&gt;Take the first card of the pile. Sort the rest of the pack into numbers smaller than and numbers bigger than the number on the first card. Put the first card down between these two sub-packs. Then sort each sub-pack of cards by taking the top one and sorting the rest into two sub-packs in the same way. Keep going until there are no sub-packs with two or more cards.&lt;/div&gt;
&lt;p&gt;&lt;br&gt;&lt;/br&gt;
Try each algorithm a few times, and keep a record of how many &amp;#39;moves&amp;#39; or &amp;#39;swaps&amp;#39; you do. You could work with a friend and &amp;#39;race&amp;#39; against each other to see who sorts their pack the quickest.&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
If you are struggling to make sense of the written algorithms, &lt;a href=&quot;/8192/clue&quot;&gt;here&lt;/a&gt; are some videos showing each algorithm being performed.&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
&lt;strong&gt;Here are some questions to consider:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;On average, which algorithm did you find to be quickest?&lt;/li&gt;
&lt;li&gt;What is the &amp;#39;worst-case scenario&amp;#39; for each algorithm?&lt;/li&gt;
&lt;li&gt;How long would it take in the worst case?&lt;/li&gt;
&lt;li&gt;Which would you choose if you had to keep the cards in a pile rather than laying them out?&lt;/li&gt;
&lt;li&gt;Which would you choose if you only had a limited amount of desk space to arrange the cards on?&lt;/li&gt;
&lt;/ul&gt;
If you know a little about computer programming, think about how might you instruct a computer to perform these algorithms. Which ones would be quick to perform? Which ones would use a lot of space?&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
&lt;div class=&quot;framework&quot;&gt;&lt;strong&gt;Notes and Background&lt;/strong&gt;&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
One way to get a sense of how sorting algorithms work is to watch animations, such as the ones on &lt;a href=&quot;http://www.sorting-algorithms.com/&quot;&gt;this website&lt;/a&gt;.&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
Thanks to Margaret for testing this problem.&lt;/div&gt;&lt;/mdoxml&gt;</indexXML>
  <solutionXML/>
  <noteXML>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;mdoxml version=&quot;1.0&quot;&gt;&lt;h3&gt;Why do this problem?&lt;/h3&gt;
&lt;a href=&quot;/8192&quot;&gt;This problem&lt;/a&gt; introduces sorting algorithms by encouraging students to explore them using a pack of cards. By performing the algorithms for themselves, we hope students will gain a better understanding of the advantages and limitations of each method.&lt;br&gt;&lt;/br&gt;
&lt;h3&gt;Possible approach&lt;/h3&gt;
Each student will need one suit from a pack of cards.&lt;br&gt;&lt;/br&gt;
&quot;Shuffle your cards, and then put them in order from Ace to King. Watch how your partner puts their cards in order. Do you both do it the same way? How efficient is your method?&quot;&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
&lt;strong&gt;Either&lt;/strong&gt; show students each &lt;a href=&quot;/8192/clue&quot;&gt;video&lt;/a&gt; and invite them to make sense of the algorithm and have a go themselves,&lt;br&gt;&lt;/br&gt;
&lt;strong&gt;Or&lt;/strong&gt; hand out &lt;a class=&quot;pdflink&quot; href=&quot;/content/id/8192/Sorted.pdf&quot;&gt;this worksheet&lt;/a&gt; for them to make sense of the algorithms on paper.&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
&quot;For each of the algorithms, perform it a few times to get a feel for it. Then choose two algorithms and compare them. Which is the quickest? Why? Can you put your cards into a worst-case scenario for each of the algorithms, to make it take as long as possible?&quot;&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
Give students time to explore these, together with the questions from the problem which are on the worksheet:
&lt;ul&gt;
&lt;li&gt;On average, which algorithm did you find to be quickest?&lt;/li&gt;
&lt;li&gt;What is the &amp;#39;worst-case scenario&amp;#39; for each algorithm?&lt;/li&gt;
&lt;li&gt;How long would it take in the worst case?&lt;/li&gt;
&lt;li&gt;Which would you choose if you had to keep the cards in a pile rather than laying them out&lt;/li&gt;
&lt;li&gt;Which would you choose if you only had a limited amount of desk space to arrange the cards on?&lt;/li&gt;
&lt;/ul&gt;
Then bring the class together to discuss their findings.&lt;br&gt;&lt;/br&gt;
&lt;h3&gt;Possible extension&lt;/h3&gt;
Invite students to use &lt;a href=&quot;http://en.wikipedia.org/wiki/Pseudocode&quot;&gt;pseudocode&lt;/a&gt;, or a programming language if they know one, to express the algorithms.&lt;br&gt;&lt;/br&gt;
&lt;h3&gt;Possible support&lt;/h3&gt;
Introduce the algorithms one at a time, and then make pairwise comparisons between them.&lt;br&gt;&lt;/br&gt;&lt;/mdoxml&gt;</noteXML>
  <clueXML>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;mdoxml version=&quot;1.0&quot;&gt;Bubble Sort&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
&lt;video height=&quot;315&quot; id=&quot;Bubble%2520Sort.mp4&quot; src=&quot;Bubble%2520Sort.mp4&quot; tabindex=&quot;0&quot; type=&quot;video/mp4&quot; width=&quot;420&quot;&gt;&lt;/video&gt;
&lt;br&gt;&lt;/br&gt;
Shuttle Sort&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
&lt;video height=&quot;315&quot; id=&quot;Shuttle%2520Sort.mp4&quot; src=&quot;Shuttle%2520Sort.mp4&quot; tabindex=&quot;0&quot; type=&quot;video/mp4&quot; width=&quot;420&quot;&gt;&lt;/video&gt;
&lt;br&gt;&lt;/br&gt;
Selection Sort&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
&lt;video height=&quot;315&quot; id=&quot;Selection%2520Sort.mp4&quot; src=&quot;Selection%2520Sort.mp4&quot; tabindex=&quot;0&quot; type=&quot;video/mp4&quot; width=&quot;420&quot;&gt;&lt;/video&gt;
&lt;br&gt;&lt;/br&gt;
Insertion Sort&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
&lt;video height=&quot;315&quot; id=&quot;Insertion%2520Sort.mp4&quot; src=&quot;Insertion%2520Sort.mp4&quot; tabindex=&quot;0&quot; type=&quot;video/mp4&quot; width=&quot;420&quot;&gt;&lt;/video&gt;
&lt;br&gt;&lt;/br&gt;
Quick Sort&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
&lt;video height=&quot;315&quot; id=&quot;Quick%2520Sort.mp4&quot; src=&quot;Quick%2520Sort.mp4&quot; tabindex=&quot;0&quot; type=&quot;video/mp4&quot; width=&quot;420&quot;&gt;&lt;/video&gt;&lt;/mdoxml&gt;</clueXML>
  <canonXML/>
  <end_user_role>2</end_user_role>
  <difficulty>3</difficulty>
  <keystage1>0</keystage1>
  <keystage2>0</keystage2>
  <keystage3>0</keystage3>
  <keystage4>0</keystage4>
  <keystage4plus>1</keystage4plus>
  <title>Sorted</title>
  <description>decision maths sorting algorithms problem</description>
  <spec_group>Decision Mathematics and Combinatorics
    <specifier>Algorithms</specifier>
  </spec_group>
  <spec_group>Admin
    <specifier>Stage 5 Decision mapping</specifier>
  </spec_group>
  <spec_group>ajk44
    <specifier>Alison's problems under development</specifier>
  </spec_group>
</resource>