There are 6 students in a queue, arranged from tallest to shortest. They now want to sort themselves from shortest to tallest. They decide to use the following steps:
Step 1. The students in positions 3 and 5 each swap places with the student immediately in front of them if the one in front is taller.
Step 2. The students in positions 2, 4, and 6 each swap places with the student immediately in front of them if the one in front is taller.
Steps 1 and 2 repeat until everyone observes the student immediately in front of them is shorter than themselves.
Using this process, it takes 6 steps for the students to sort themselves, as shown in the animation below:
Now, if there are 10 students, how many rounds will it take?
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.
This is called odd-even transposition sort. It takes an order of n steps. Where n is the number of students. It is based on the Bubble Sort technique of comparing two numbers and switching them if the first is greater than the second, to achieve a left to right ascending ordering.