- Practice
- About 14 min
- 5 practice questions
Two-condition machines and exam practice
Solve a machine that moves odd numbers to the left in ascending order while even numbers keep their order, and work through exam-style practice.
If something looks wrong, please tell us.
Harder machines apply two conditions at once, for example one rule for odd numbers and another for even numbers. Handle one group at a time and note which group keeps its original order.
The machine
At each step the smallest odd number not yet placed goes to the next place from the left. The even numbers keep their original order after the odd ones.
Worked example 1
Input: 14 7 20 3 9 8. Step I: 3 14 7 20 9 8. Step II: 3 7 14 20 9 8. Step III: 3 7 9 14 20 8. The odd numbers 3, 7, 9 are now in ascending order at the left, and the even numbers 14, 20, 8 keep their original order. The machine stops after 3 steps.
Worked example 2
Input: 18 5 12 11 6 3. The odd numbers are 5, 11 and 3. Step I: 3 18 5 12 11 6. Step II: 3 5 18 12 11 6. Step III: 3 5 11 18 12 6.
Deal with each group separately; note which group keeps its order.
Key takeaways: treat each group separately, write each step, and stop when every condition is satisfied.
Check your understanding
-
1. Machine: at each step the smallest odd number not yet placed goes to the next place from the left; the even numbers keep their original order after the odd ones. Input: 12 9 6 5 10 3. What is Step II?
- 3 5 12 9 6 10
- 3 12 9 6 5 10
- 3 5 9 12 6 10
- 5 3 12 9 6 10
Show answer
Answer: A. The odd numbers in order are 3, 5, 9. Step I: 3 12 9 6 5 10. Step II: 5 goes to second place, giving 3 5 12 9 6 10.
-
2. Machine: at each step the smallest odd number not yet placed goes to the next place from the left; the even numbers keep their original order after the odd ones. Input: 12 9 6 5 10 3. What is the final arrangement?
- 3 5 9 6 10 12
- 3 5 9 12 6 10
- 12 6 10 3 5 9
- 3 5 9 10 12 6
Show answer
Answer: B. Step III places 9, giving 3 5 9 12 6 10. The odd numbers are in ascending order on the left, and the even numbers keep their original order 12, 6, 10.
-
3. Machine: at each step the smallest odd number not yet placed goes to the next place from the left; the even numbers keep their original order after the odd ones. Input: 2 8 6. What is the output?
- 8 6 2
- 2 6 8
- 2 8 6
- 6 8 2
Show answer
Answer: C. There are no odd numbers, so nothing moves and the output is the input, 2 8 6.
-
4. Machine: at each step the smallest odd number not yet placed goes to the next place from the left; the even numbers keep their original order after the odd ones. Input: 11 4 7 8 1. What is Step II?
- 1 11 4 7 8
- 1 7 4 11 8
- 11 7 1 4 8
- 1 7 11 4 8
Show answer
Answer: D. Odd numbers in order: 1, 7, 11. Step I: 1 11 4 7 8. Step II: 7 goes to second place, giving 1 7 11 4 8.
-
5. Machine: at each step the smallest odd number not yet placed goes to the next place from the left; the even numbers keep their original order after the odd ones. Input: 14 3 8 9 6 1. What is the final arrangement?
- 1 3 9 6 8 14
- 1 3 9 14 8 6
- 1 3 9 8 6 14
- 14 8 6 1 3 9
Show answer
Answer: B. Step I: 1 14 3 8 9 6. Step II: 1 3 14 8 9 6. Step III: 1 3 9 14 8 6. The even numbers keep their original order 14, 8, 6.
Sign in to keep track of the lessons you finish.