- Foundation
- About 13 min
- 5 practice questions
Sorting words by length and by last letter
Follow machines that arrange words by the number of letters or by their last letter, including what to do when two words tie.
If something looks wrong, please tell us.
Not every machine sorts words by the usual alphabetical order. Some arrange them by length, with the shortest first, and some by the last letter. The step-by-step method is the same as before: find what moves in Step I, state the rule in one sentence, and apply it one step at a time. The new skill is choosing the right key for each word.
Choosing the key
- By length: count the letters of each word. The shortest word has the smallest key.
- By last letter: look only at the final letter of each word and compare those letters alphabetically.
- Ties: if two words have the same key, the one that stood first in the line keeps its place ahead of the other, unless the question says otherwise.
In the machines of this lesson, each step moves one word, the next in order, to the next free place from the left. All the other words keep their order, as in the sorting machines you have already met. If a word is already in its correct place, no step is spent on it.
Worked examples
Example 1 (length). Input: elephant cat tiger ox lion. The lengths are 8, 3, 5, 2 and 4. The order from shortest is ox, cat, lion, tiger, elephant. Step I: ox elephant cat tiger lion. Step II: ox cat elephant tiger lion. Step III: ox cat lion elephant tiger. Step IV: ox cat lion tiger elephant. The machine stops after 4 steps.
Example 2 (last letter). Input: tap dog sun. The last letters are p, g and n. In alphabetical order the last letters are g, n, p, so the order is dog, sun, tap. Step I: dog tap sun. Step II: dog sun tap. The machine stops after 2 steps.
Example 3 (a tie). Input: table fig plum kiwi. The lengths are 5, 3, 4 and 4. Plum and kiwi tie, so plum goes first because it came first in the line. The order is fig, plum, kiwi, table. Step I: fig table plum kiwi. Step II: fig plum table kiwi. Step III: fig plum kiwi table. The final line has plum before kiwi.
Example 4 (a last-letter machine). Input: crow ant bee fox. The last letters are w, t, e and x, so the order is bee (e), ant (t), crow (w), fox (x). Step I: bee crow ant fox. Step II: bee ant crow fox. Fox is already in its place, so the machine finishes in 2 steps.
Example 5 (longest first). Rule: in each step the longest remaining word moves to the next place from the left. Input: cat elephant ox tiger. The lengths are 3, 8, 2 and 5, so the order is elephant, tiger, cat, ox. Step I: elephant cat ox tiger. Step II: elephant tiger cat ox. The line is now in order after 2 steps.
Common slips
- Using the first letter when the rule is about the last letter.
- Counting the letters wrongly in a long word; count each word twice.
- Moving two words in one step. Each step moves exactly one word.
- Putting the tied words in the wrong order.
Decide the key first (length or last letter), write the sorted order, and then move one word per step.
Key takeaways
- Count letters for a length rule; look at the final letter for a last-letter rule.
- Equal keys keep their original order.
- A word already in its place costs no step.
- Write the final order first, so you know where each word is heading.
Check your understanding
-
1. Rule: in each step the shortest remaining word moves to the next place from the left. Input: tiger ox lion cat. What is Step I?
- cat tiger ox lion
- ox cat tiger lion
- ox tiger lion cat
- tiger lion cat ox
Show answer
Answer: C. The lengths are 5, 2, 4 and 3, so ox is the shortest. Moving ox to the front gives ox tiger lion cat.
-
2. Using the same input and rule, how many steps are needed to complete the arrangement?
- 3
- 2
- 4
- 5
Show answer
Answer: A. Step I: ox tiger lion cat. Step II: ox cat tiger lion. Step III: ox cat lion tiger, which is in order. That is 3 steps.
-
3. Rule: the word whose last letter comes earliest in the alphabet moves to the next place from the left. Input: tap dog sun. What is Step II?
- dog tap sun
- sun dog tap
- tap dog sun
- dog sun tap
Show answer
Answer: D. The last letters are p, g and n, so the order is dog, sun, tap. Step I is dog tap sun and Step II is dog sun tap.
-
4. Rule: shortest word first, with equal lengths keeping their order. Input: table fig plum kiwi. Which word is second in the final line?
- kiwi
- plum
- table
- fig
Show answer
Answer: B. The final line is fig plum kiwi table. Plum and kiwi tie in length and plum came first.
-
5. Rule: sort by last letter, earliest in the alphabet first. Input: crow ant bee fox. What is the final line?
- ant bee crow fox
- bee crow ant fox
- bee ant crow fox
- fox crow ant bee
Show answer
Answer: C. The last letters are w, t, e and x, so the order is bee, ant, crow, fox.
Sign in to keep track of the lessons you finish.