Sort Wizard

Chris has a boring assignment, which is to sort the following numbers:

85 , 36 , 49 , 12 , 57 , 55 , 79 , 19 , 60 85, 36, 49, 12, 57, 55, 79, 19, 60

Agnishom went by and saw Chris is bored. A sorting wizard he is, he tells Chris that:

If you sort the first two third, then sort the last two third, and then sort the first two third again, the entire list of numbers will be sorted!

Curious, Chris tried it out

  • sort the first two third : 12 , 36 , 49 , 55 , 57 , 85 , 79 , 19 , 60 12, 36, 49, 55, 57, 85, 79, 19, 60
  • sort the last two third : 12 , 36 , 49 , 19 , 55 , 57 , 60 , 79 , 85 12, 36, 49, 19, 55, 57, 60, 79, 85
  • sort the first two third : 12 , 19 , 36 , 49 , 55 , 57 , 60 , 79 , 85 12, 19, 36, 49, 55, 57, 60, 79, 85

It really sorts the entire list! Does this work for any list of length divisible by 3? Or is this just a coincidence?

It works for any list of length divisible by 3 This is just a coincidence

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Christopher Boo
Sep 4, 2016

Evenly divide the array into section A , B , C A,B,C . Let's see what happens in each section after the sorting.

  1. Sort the first two third
    Section A , B A,B will be sorted. Numbers that are supposed to be in C C but initially lies in A A will now be sorted to B B . They cannot still be in A A as there are no more than a section of numbers larger than numbers supposed to be in C C .

  2. Sort the last two third
    Section B , C B,C will be sorted. Numbers that are supposed to be in C C was in either section B B or C C . Now that they are sorted, C C has the right numbers and order.

  3. Sort the first two third
    Section A , B A,B will be sorted again. Since C C has already sorted, then sort A , B A, B implies sorting the entire array!

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...