Chapter 21
Input-Output
Read the last step first, find what moves, and the machine has no secret left.
Input-Output questions look scary because the lines are long and the steps are many. But the machine inside is always a very simple worker. It follows one fixed instruction, applies it to a line, and shows you the new line. That is all.
Your job is to discover the instruction from the steps given, and then to apply or count it without a slip. This chapter first builds the language of the machine: input, step, final step, lane, auto-fill, shifting and swapping. Then it goes type by type, in the order of what the exam asks most:
- Type 1: Words and numbers together (alternating line and two lanes), the form the latest SSC papers print.
- Type 2: Numbers, lift-and-insert sorting: ascending, descending and alternating.
- Type 3: Words, letters and mixed kinds: dictionary order, vowel and consonant groups, kinds with a priority.
- Type 4: Swap machines and centre placement.
- Type 5: Arithmetic machines [New Pattern]: each number, adjacent pairs, letter-digit shifts.
- Type 6: Position patterns and matrix inputs [New Pattern].
- Type 7: Reverse questions, where you must find the Input.
These questions come only now and then in SSC, Railway and State exams, but they are free marks once you have the habit: read the last step, compare the first two steps, confirm, then apply. Every wrong answer in this chapter comes from skipping one of these four.
The Machine and Its Words
A machine in these questions is a simple instruction-follower. You give it a line of words, numbers or letters (the Input). It changes the line by one fixed instruction and shows the new line. That is one step. It repeats the same instruction again and again until one more application would change nothing. That last line is the final step.
The words you need are in this table.
| Term | Meaning |
|---|---|
| Input | The starting line. It is Step 0 and is never counted as a step |
| Step k | The line after k moves |
| Final step | The step after which nothing more changes |
| Anchor | The end from which the sorted part grows: left, right or centre |
| Lane | Words and numbers are two separate lists; a number never enters the word lane |
| Auto-fill | If the leftover items already sit in target order, no more moves are needed and no step is counted |
[[fig:0]]
In the picture the top line is the Input. In every next line the red tile is the item that was moved in that step, and green tiles are already fixed. The grey tiles at the end fell into place on their own. That is auto-fill, and it costs no step.
The Input is Step 0. Steps are counted only from the first real change.
Two Kinds of Change: Shifting and Swapping
Every machine moves items in one of two ways. Decide which one it is from Step 1.
Shifting (lift and insert). The chosen item is lifted out and placed at its target slot. The items in between slide one place to make room, and everyone else keeps the same relative order.
Swapping (exchange). The chosen item and the item that sits in the target slot simply trade places. Nobody else moves.
[[fig:0]]
Both pictures start from 5 9 2 7 4 and bring the smallest number, 2, to the front. In shifting, 5 and 9 slide right, so the line is 2 5 9 7 4. In swapping, 2 and 5 trade places, so the line is 2 9 5 7 4. The Step 1 lines are different, and so are all the lines after it.
How to decide quickly: look at the neighbours of the moved item in Step 1. If the items it jumped over are still in their old order, one after another, it is shifting. If the item that was in the target slot has landed exactly where the moved item came from, it is swapping.
Shifting moves a block. Swapping trades two items. Never mix the two.
How to Find the Instruction
Many questions do not tell you the instruction. They show an Input and two or three steps and ask you to work out the rest. Use the same four moves every time.
1. Read the last step first. It shows the target order. Is it ascending, descending, alphabetical, or something stranger?
2. Compare the Input with Step 1. What moved, and where did it go? Did the others slide (shifting) or did two items trade places (swapping)?
3. Confirm on Step 2 (and Step 3 if it is given). The instruction must explain every step shown, not just the first.
4. Only then apply it to the new input.
[[fig:0]]
Here the last line is ascending, so the target is smallest to largest. In Step 1 the number 17 jumped to the front and 34 slid right, so the machine shifts. In Step 2 the next smallest number, 26, jumped to the second slot. The instruction is confirmed: bring the smallest unplaced number to the next free slot from the left.
Never assume that the instruction in Step 1 continues unchanged. Check it on Step 2.
Some machines change their instruction from step to step, for example "Step I: add 3, Step II: square". Then the question always lists each step's instruction. Read them in order and do not carry the old one forward.
Counting Steps, Positions and Dictionary Order
Counting steps. In a left-anchored machine, one step places one item. An item that already sits in its target slot costs no step. The reliable method is to run the machine one step at a time and stop as soon as the leftover tail is already in target order. Do not use "n − 1 steps" blindly; it is true only in special cases.
For "how many more steps after Step s", the answer is the total T minus s, not T.
Positions. If a line has n items, the k-th item from the right is the (n + 1 − k)-th from the left. "Between X and Y" counts only the items strictly in between.
[[fig:0]]
In this line of 6 letters, C is 2nd from the left and 5th from the right. 2 + 5 = 6 + 1 = 7, always.
Dictionary order. Compare two words letter by letter from the left. The first different letter decides: "over" comes before "owl" because V comes before W. If one word is the beginning of the other, the shorter comes first: "pen" before "pencil".
Penultimate means the second last step. If the final step is Step 5, the penultimate step is Step 4.
k-th from right = (n + 1 − k)-th from left. A shorter word that is a prefix comes first.
Type 1
Words and Numbers Together: Alternating and Two-Lane
Here the line holds words and numbers together. The machine treats them as two separate lists: the words have their own order (A to Z) and the numbers have their own order (largest first or smallest first). A number never enters the word list and a word never enters the number list. Almost every question of this type is one of two forms, and the last step or the question's own sentence tells you which.
Form 1: the alternating line (the commonest). The final line runs number, word, number, word ... (or word, number, word, number ...). In each step one item is lifted to the next free slot from the left, in this pattern. All other items keep their old order.
[[fig:0]]
In the picture the target is built first: the largest number 62, the alphabetically first word elm, the next number 34, then oak, 17 and rat. Step 1 lifts 62 to the front, Step 2 lifts elm to the second slot, and so on. If one list is longer, its extra items stay together at the end in their order. When the target is complete the machine stops, and the next step shows the same line again.
Form 2: two lanes. Words are collected from the left end and numbers from the right end in the same step, and the two lanes grow towards each other.
[[fig:1]]
The final line is all the words in order, then all the numbers in order. Two items can move in one step, so never count steps as items ÷ 2. An item already in its slot is skipped, and the middle part falls into place by itself.
Method. (1) From the question or the last step, find which kind comes first and what order each kind follows. (2) Write the target line. (3) Place the target items one by one; an item already sitting in its slot costs no step.
Write the target first. Each step puts the next target item in its slot; the untouched items keep their old order.
- Input: cat 28 dog 43 bat 59 Step 1: 59 cat 28 dog 43 bat Step 2: 59 bat cat 28 dog 43 Step 3: 59 bat 43 cat 28 dog Step 4: 59 bat 43 dog…
- इनपुट: 93 box 27 pink 46 green 18 चरण 1: box 93 27 pink 46 green 18 चरण 2: box 93 green 27 pink 46 18 चरण 3: box 93 green 46 27 pink 18…
- A word-and-number arrangement machine rearranges the given input step, the smallest number is shifted to the leftmost side, and the…
- Input: 85 kite 23 lamp 62 brush. Step 1: brush 85 kite 23 lamp 62 Step 2: brush 85 kite 62 23 lamp Step 3: brush 85 kite 62 lamp 23 Which…
- A word-and-number arrangement machine rearranges a given input following a specific rule in each step. The rule involves moving the…
Type 2
Numbers: Lift-and-Insert Sorting (Ascending, Descending, Alternating)
This is the base machine of the whole chapter, so learn it well. In every step one number is lifted and put in its final slot. The numbers it jumps over slide one place; all others keep their old order. The exam prints two or three steps, or one line of rule, and asks for a later step, the number at some position, or the count of steps.
Form 1: smallest first, from the left. After Step k, the first k slots hold the k smallest numbers in ascending order. Input 48 15 62 30 21 becomes 15 48 62 30 21, then 15 21 48 62 30, then 15 21 30 48 62. That is three steps, not four, because 48 and 62 were already in order at the end.
[[fig:0]]
Form 2: other ends and orders. The same machine can take the largest first, or fill from the right.
| Lifted first | Placed at | Final line |
|---|---|---|
| Largest | Left end | Descending |
| Largest | Right end | Ascending |
| Smallest | Right end | Descending |
[[fig:1]]
A one-line version is also asked: "in the first step the largest number moves to the last place". Only that number moves. 2 5 1 becomes 2 1 5, not 1 2 5.
Form 3: alternating. Slot 1 takes the smallest, slot 2 the largest of the rest, slot 3 the next smallest, and so on.
[[fig:2]]
Why the other part looks untidy. Only one number moves in a step, so the numbers not yet touched keep the order they had in the Input. They are sorted only when their turn comes. This one idea gives every option-elimination trick of this type: an option whose untouched part is already sorted is wrong.
Step k = the first k numbers of the target, then the untouched numbers in their old order. A number already in its slot costs no step.
- A machine rearranges numbers by moving the largest number to the last place in the first step. Input: 2, 5, 1. What is the output after…
- A definite Input-Output process is given below. Study the arrangement rules carefully for the given input and follow them to answer the…
- In each step the largest of the numbers not yet fixed is lifted to the next free place on the left; the numbers it jumps over move one…
- In each step the largest of the numbers not yet fixed is lifted to the right-most free place; the numbers it jumps over move one place to…
- A machine rearranges numbers. In each step one number is lifted to the next free place from the left and the numbers it jumps over move…
Type 3
Words, Letters and Mixed Kinds [New Pattern for mixed kinds]
This is the same lift-and-insert machine as Type 2. Only the items change: they are words, letters, or a mixture of kinds. So the whole skill lies in writing the correct target line; after that you place its items one by one.
Words. Three targets are common: alphabetical (A to Z), reverse alphabetical (Z to A), and by length (fewer letters first; for equal length, alphabetical). Compare two words letter by letter from the left; the first different letter decides.
[[fig:0]]
'over' comes before 'owl' because V comes before W. 'pen' comes before 'pencil' because a word that ends first comes first. Never compare only the first letter: sun, sea, sky and star all begin with S.
Letters in two groups. The target has a vowel group and a consonant group, each with its own direction, for example vowels A to Z and then consonants Z to A. Split the Input, sort each group in its own direction, and join the groups in the stated order.
[[fig:1]]
Mixed kinds [New Pattern]. Numbers, words and symbols such as # @ & come together, and the question gives a priority among the kinds, for example 'symbols, then numbers, then words'. Write the target kind by kind. Symbols have no order of their own, so they keep the order in which they appear in the Input.
[[fig:2]]
For all three forms the step concept is the same: one item moves per step, the untouched items keep their old order, and an item already in its slot costs no step.
Target first: sort each kind or group by its own order, join them in the stated priority, then place one item per step.
Type 4
Swap Machines and Centre Placement
In a swap machine nothing slides. The chosen item and the item sitting in the target slot simply exchange places, and every other item stays exactly where it is. Compare with Type 2: take 5 9 2 7 4 and bring the smallest number 2 to the front. Lifting gives 2 5 9 7 4, because 5 and 9 slide. Swapping gives 2 9 5 7 4, because only 2 and 5 trade places.
[[fig:0]]
In the picture the red tile is the chosen number, and the blue tile is the item pushed out of its slot; it lands exactly where the red tile came from.
How to recognise a swap. Look at Step 1. If the displaced item has landed exactly where the chosen item came from and nobody else moved, it is a swap. If the items in between slid by one place, it is a lift. Some questions use the word 'swap' or 'exchange'; others show only the steps, so check.
A swap machine usually needs fewer steps than a lift machine on the same line, because a swap can fix one item and improve another. In the picture it finishes 2 3 5 6 8 9 in 3 steps, whereas lifting needs 4. A swap can also push out an item that was already in place, so rewrite the whole line after every swap.
Centre placement. Here the sorted part starts from the middle slot and grows outwards, for example for 7 slots the order of slots may be 4th, 5th, 3rd, 6th, 2nd, 7th, 1st. The statement gives the order of slots, and the result looks like a valley: small in the middle, large at the ends. Mostly it is a swap machine, so each chosen number trades places with whatever sits in its target slot.
[[fig:1]]
Read the slot order, the side that comes next (right or left), and 'smallest' or 'largest' from the question; they change from one question to the next.
Swapping trades two items; never slide the items in between. In centre placement, read the slot order from the question.
Type 5
Arithmetic Machines [New Pattern]: Each Number, Adjacent Pairs, Letter-Digit Shifts
In these machines the numbers do not move about; they are changed by arithmetic. The length of the new line tells you which machine it is.
| New line | Machine |
|---|---|
| Same length, every number changed | Each-number machine |
| Exactly one number shorter | Adjacent-pair machine |
| Letter-digit groups, letters move forward, digits change | Letter and digit machine |
Each-number machine. Every number gets the same operation in a step (add 4, multiply by 3, square, digit sum, product of digits). Each step may have its own operation. Each number makes its own journey: 58 gives digit sum 13, then square 169, then digit sum 16. Work digit by digit, and remember that 13 or 169 is a multi-digit number when the next step arrives.
[[fig:0]]
Sometimes the steps are shown for one Input and asked for another. Find the operation on the first number, test it on the second, and only then apply it to the new line.
Adjacent-pair machine. Each new number is built from two neighbours: their sum, positive difference, product, sum of squares or half of the sum. n numbers make n − 1 pairs, so the line is one shorter after every step.
[[fig:1]]
Letter and digit machine. In every step each letter moves forward by a fixed number of places and each digit changes by a fixed amount. After n steps they have moved n times as much, so you can jump straight to the step asked, provided no letter passes Z, no digit leaves 0 to 9, and the digit change does not depend on odd or even.
[[fig:2]]
Same length: each-number. One shorter: adjacent pairs. After n steps: n times the shift. Every step has its own operation.
Type 6
Position Patterns ('and so on') and Matrix Inputs [New Pattern]
Position-pattern machine. This machine does not look at what the items are. It follows one position map, the same in every step: 'the item in place 3 goes to place 1, the item in place 1 goes to place 2' and so on. So the same map works for any new Input. Step I is built by reading the old line in the order 3rd, 1st, 2nd, 5th, 4th.
[[fig:0]]
Because the same map repeats, the line must return to the Input after some steps. That number is the period. Three items in a cycle give ABC, BCA, CAB, ABC again: period 3.
[[fig:1]]
When several cycles run together, the period is the lcm of the cycle lengths: a 3-cycle with a 2-cycle gives lcm(3, 2) = 6. A far step is then easy. Divide the step number by the period and use only the remainder. With period 6, Step XIV is Step II, because 14 = 12 + 2. A remainder of 0 means the Input itself. Always confirm the map on Step II, and apply it to positions, not to the letters you saw in the example.
Matrix (box) input [New Pattern]. The Input is a grid. A step says 'the numbers in each column are arranged in ascending order from top to bottom', or the same for rows. Do it for every column (or row) and rewrite the whole grid; the next step works on the new grid, not on the original. Then read the asked cells: the main diagonal runs from top-left to bottom-right, the other diagonal from top-right to bottom-left, and the centre of a 3 × 3 grid is its middle cell.
[[fig:2]]
Position map, then cycles, then period (lcm), then remainder. For a grid: one pass per step, rewrite the grid, read the asked cells last.
Type 7
Reverse Questions: Find the Input
In a reverse question the machine is not run forwards. You are given a later step and asked for the Input (or for where an item came from). Before you start, ask one question: can the machine be undone exactly?
Invertible machines. If each step can be reversed exactly (add 5 can be undone by subtracting 5, double can be undone by halving, letters moved +2 can be moved −2), you simply undo the steps, last step first.
[[fig:0]]
In the picture, Step II is 17 29 9 41. Undo the last operation (subtract 5), then undo the first (halve), and the Input appears. Always check by running the machine forward once.
Non-invertible machines. A lift-and-insert machine cannot be undone by reading backwards. When the number 14 was lifted to the front, it could have come from the 2nd place, the 3rd place, or any other place, and the line after the step looks the same. So two different Inputs may produce one and the same step. In that case the correct answer is "cannot be determined".
How to handle such a question? Take each candidate input from the options and run it forward by the machine. If exactly one option gives the shown step, that is the answer. If two options give it, the answer is "cannot be determined". If the options contain no such choice, trust your forward runs.
[[fig:1]]
The picture shows two candidate Inputs that both lead to the same Step II. So the Input is not fixed.
Invertible: undo the last step first. Lift-and-insert: test every option forward; if two fit, the answer is "cannot be determined".