• Advanced
  • About 13 min
  • 5 practice questions

Rearrangement by position: smallest or largest to one end

Follow a machine that moves the smallest or largest number to one end in each step, and predict any step.

If something looks wrong, please tell us.

In an input-output question a machine rearranges a line of numbers or words step by step. You are asked for a given step, the number of steps, or the position of an item. The method is always the same: find the rule from the first step or two, then apply it carefully.

The rule used here

In each step, the smallest number not yet placed is moved to the left side, just after the numbers already placed, and the rest keep their order. The machine stops when the line is in ascending order.

Worked example 1

Input: 56 32 78 14 45 91. Step I brings the smallest, 14, to the front: 14 56 32 78 45 91. Step II brings the smallest of the rest, 32, next: 14 32 56 78 45 91. Step III brings the smallest of the rest, 45, next: 14 32 45 56 78 91. The line is now in order, so the machine stops. There are 3 steps.

Worked example 2

Rule: in each step the largest number not yet placed moves to the left end. Input: 8 21 5 14. Step I: 21 8 5 14. Step II: 21 14 8 5. The line is in descending order, so 2 steps.

Find the rule from the first step, test it on the second, then apply it step by step without skipping.

— Method to remember

Key takeaways: state the rule in words, apply it one step at a time, and stop when the line is fully ordered.

Check your understanding

  1. 1. Rule: In each step the smallest number not yet placed moves to the left, just after the numbers already placed, and the rest keep their order. Input: 47 12 89 33 60. What is Step II?

    1. 12 33 89 47 60
    2. 12 33 47 89 60
    3. 12 47 33 89 60
    4. 12 33 47 60 89
    Show answer

    Answer: B. Step I brings the smallest, 12, to the front: 12 47 89 33 60. Step II brings the smallest of the rest, 33, to the second place while 47 89 60 keep their order: 12 33 47 89 60.

  2. 2. Using the same rule on 47 12 89 33 60, how many steps does the machine take?

    1. 2
    2. 4
    3. 5
    4. 3
    Show answer

    Answer: D. Step I: 12 47 89 33 60. Step II: 12 33 47 89 60. Step III: 12 33 47 60 89, which is in ascending order, so the machine stops after 3 steps.

  3. 3. Rule: in each step the largest number not yet placed moves to the left, just after the numbers already placed. Input: 6 15 9 20 3. What is Step II?

    1. 20 15 6 9 3
    2. 20 15 9 6 3
    3. 15 20 6 9 3
    4. 20 6 15 9 3
    Show answer

    Answer: A. Step I brings the largest, 20, to the front: 20 6 15 9 3. Step II brings the largest of the rest, 15, to the second place, and 6 9 3 keep their order: 20 15 6 9 3.

  4. 4. Under the smallest-first rule, when does the machine stop?

    1. After as many steps as there are numbers
    2. When the largest number reaches the left end
    3. When the line is in ascending order
    4. After the first step
    Show answer

    Answer: C. The machine keeps placing the smallest remaining number until the whole line is in ascending order; then there is nothing left to move, so it stops.

  5. 5. Rule: In each step the smallest number not yet placed moves to the left, just after the numbers already placed, and the rest keep their order. Input: 30 12 25 6 18. Which number is third from the left in Step II?

    1. 25
    2. 18
    3. 30
    4. 12
    Show answer

    Answer: C. Step I: 6 30 12 25 18. Step II: 6 12 30 25 18. Counting from the left: 6, 12, 30 - so the third number is 30.

Sign in to keep track of the lessons you finish.

Next lesson → Adjacent-swap steps

Privacy · Terms · Refunds · Delivery