- Foundation
- About 13 min
- 5 practice questions
Arranging words alphabetically and numbers in order
Solve machines that sort words alphabetically or numbers in ascending or descending order, one element per step.
If something looks wrong, please tell us.
The most common rule sorts the line. Words are sorted by alphabet (A comes first), and numbers by size. Each step places one element, usually starting from the left or the right. You must always apply the rule exactly as seen, and not sort the whole line at once.
Alphabetical order
Compare words by their first letter. If two words start with the same letter, compare the second letter, and so on. For example, bag comes before ball, which comes before bat.
Worked examples
Example 1. Input: pen cat dog bag. Rule: one word per step, in alphabetical order, moving to the left end positions. The alphabetical order is bag, cat, dog, pen. Step I: bag pen cat dog (bag moves to the front). Step II: bag cat pen dog (cat moves to second place). Step III: bag cat dog pen (dog moves to third place). The line is sorted after 3 steps.
One word per step
- Input: pen cat dog bag
- Step I: bag pen cat dog bag moves to the front.
- Step II: bag cat pen dog cat moves to second place.
- Step III: bag cat dog pen dog moves to third place; the line is sorted.
Example 2. Input: 14 9 22 5. Rule: each step the largest remaining number moves to the right end (to the next place from the right). Step I: 14 9 5 22 (22 goes to the end). Step II: 9 5 14 22 (14 goes to the second last place). Step III: 5 9 14 22 (9 goes to the third last place, and the line is sorted). It takes 3 steps.
Example 3. Input: 72 15 48 90 33. Rule: the smallest remaining number moves to the left each step. Step I: 15 72 48 90 33. Step II: 15 33 72 48 90. Step III: 15 33 48 72 90. The line is sorted at Step III.
To check Example 3: Step I moves 15 to the front. Step II moves the next smallest, 33, to second place, giving 15 33 72 48 90. Step III moves 48 to third place, giving 15 33 48 72 90, which is ascending.
Do exactly one move per step. The final step is the first one where the line is fully in order.
Key takeaways
- Apply one move per step.
- Sort words by first letter, then second letter, and so on.
- The rest of the line keeps its order.
Check your understanding
-
1. Which word comes first in alphabetical order?
- bat
- ball
- bag
- band
Show answer
Answer: C. All start with 'ba', so compare the third letter: g (bag) comes before l (ball), n (band) and t (bat).
-
2. Rule: one word per step moves to the next place from the left in alphabetical order. Input: lamp desk bed fan. What is Step II?
- bed desk lamp fan
- bed lamp desk fan
- bed desk fan lamp
- desk bed lamp fan
Show answer
Answer: A. Alphabetical order is bed, desk, fan, lamp. Step I: bed lamp desk fan. Step II: desk moves to second place, giving bed desk lamp fan.
-
3. Rule: at each step the largest remaining number moves to the next place from the right. Input: 25 42 8 16. What is Step II?
- 25 8 16 42
- 42 25 8 16
- 8 16 25 42
- 16 8 25 42
Show answer
Answer: C. Step I: 42 goes to the right end, giving 25 8 16 42. Step II: the next largest, 25, goes to the second last place, giving 8 16 25 42.
-
4. Rule: at each step the smallest remaining number moves to the next place from the left, and the others keep their order. Input: 50 27 64 35 19. What is Step II?
- 19 50 27 64 35
- 19 27 35 50 64
- 27 19 50 64 35
- 19 27 50 64 35
Show answer
Answer: D. Step I: 19 moves to the front, giving 19 50 27 64 35. Step II: 27 moves to second place, giving 19 27 50 64 35.
-
5. Why should you not sort the whole line at once when writing Step I?
- Because numbers must be added first
- Because the machine makes exactly one move per step
- Because words always go to the right
- Because the first step is never counted
Show answer
Answer: B. The machine places one element per step, and the rest of the line keeps its order, so Step I shows only one move.
Sign in to keep track of the lessons you finish.