Odd Even Transposition Sort - Random Instance

6 students with different heights are standing in a row, 1 1 being the shortest and 6 6 the tallest: 1 3 4 5 2 6. 1 \quad 3 \quad 4 \quad 5 \quad 2 \quad 6. They want to rearrange themselves by height, with the tallest on the far right: 123456.

The teacher proposes the following algorithm:

  • In phase 1, every student in odd positions swaps places with the student on their right if the one on the right is taller.
  • In phase 2, every student in even positions swaps places with the student on their right if the one on the right is taller.
  • Both phases are repeated alternately until everybody observes that the student in front of them is shorter than themselves.

Counting each phase as one round, how many rounds does it take to sort the given row of students?


For example, if they were initially arranged in reverse order (654321), it would take 6 rounds of these swaps for the students to sort themselves, as shown below:


The answer is 4.

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

Jonathan Quarrie
Jul 30, 2017

R e d \color{#D61F06}Red numbers have swapped positions in the current phase.

  • 1 3 4 5 2 6 \: 1 \:\:\: 3 \:\:\: 4 \:\:\: 5 \:\:\: 2 \:\:\: 6
  1. 1 3 \boxed{1 \:\:\: 3} 4 5 \boxed{4 \:\:\: 5} 2 6 \boxed{2 \:\:\: 6} (Odd)
  2. 1 \: 1 \: 3 4 \boxed{3 \:\:\: 4} 2 5 \boxed{\color{#D61F06}2 \:\:\: 5} 6 \: 6 (Even)
  3. 1 3 \boxed{1 \:\:\: 3} 2 4 \boxed{\color{#D61F06}2 \:\:\: 4} 5 6 \boxed{5 \:\:\: 6} (Odd)
  4. 1 \: 1 \: 2 3 \boxed{\color{#D61F06}2 \:\:\: 3} 4 5 \boxed{4 \:\:\: 5} 6 \: 6 (Even)
  • 1 2 3 4 5 6 \: 1 \:\:\: 2 \:\:\: 3 \:\:\: 4 \:\:\: 5 \:\:\: 6

4 \large\boxed{4} rounds = 1 2 3 4 5 6 = \: 1 \:\:\: 2 \:\:\: 3 \:\:\: 4 \:\:\: 5 \:\:\: 6

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...