State inputs and outputs
Leans on
Quick review (2 minutes)
A friend slides a row of number cards across the table and asks for the largest number.
A problem statement names the input, says which inputs are allowed and names the output each allowed input needs. An algorithm solves the problem when it ends with the correct output for every allowed input.
Write the word Input and say what the algorithm is given. For the card problem, that is a row of cards.
Add the limits on the input: how many items, and of what kind. Here the limits are one or more cards, each showing an integer.
Write the word Output and say what must be handed back. Here it is the largest number in the row.
Choose three or four allowed inputs. Include the smallest allowed input. For the card problem, add a row with a repeated number as well.
Work out the correct output for each chosen input by hand and write it beside the input. Keep the table for testing.
The common slip is writing steps before the limits are settled. A statement that says a row of cards and stops there leaves the empty row open. One reader decides the output is 0, and another decides there is none. Decide which inputs are allowed and write the decision into the statement. In this unit the empty row is not allowed.
A second slip is naming the wrong output. The largest number in 5 5 3 is 5. The position of the largest card is a different output, and for this row two positions hold it.
1 In plain words
A friend slides a row of number cards across the table and asks for the largest number. Before you plan a single step, settle two things: what you are given, and what you must hand back.
An algorithm is a finite set of instructions that carries out a specific task. The Computer Science Field Guide adds that an algorithm gives the correct result every time.
A program's input is data sent to it for processing, and its output is data it sends out. For an algorithm on paper, the input is what you are given at the start, and the output is what you hand back at the end. A problem statement names both and says which inputs are allowed.
The main problem of this unit is invented for these lessons. The input is a row of one or more cards, each showing an integer. In this unit an integer means a number with no fraction part, and it may be negative, zero or positive. The output is the largest number in the row. For the row 4 9 2 the output is 9. Working out the largest of several numbers is a task with well-known algorithms.
Remember one sentence: say what goes in and what comes out before you say how. That advice is this lesson's own. For the definition of an algorithm, find essential knowledge AAP-2.A.1 in the AP Computer Science Principles Course and Exam Description.
2 Picture it
A table of four input rows and their outputs. The row 4 9 2 needs the output 9. The row 7 needs 7. The row 5 5 3 needs 5. The row -3 -8 needs -3. The one-card row and the row of negative numbers are marked.
3 Why
Stating the output first gives you something to check a procedure against. For the row 4 9 2, a correct procedure must hand back 9, whatever its steps are. Testing compares what a procedure produces with outputs worked out beforehand.
The statement has to cover every allowed input. A row with one card is allowed, so the output for the row 7 is 7. A number may repeat, so the output for 5 5 3 is 5. Negative integers are allowed too. Of two negative numbers, the one closer to zero is the larger, so the output for -3 -8 is -3. A procedure that is right for some allowed rows and wrong for others does not solve the problem, because an algorithm gives the correct result every time.
4 The rule
A problem statement names the input, says which inputs are allowed and names the output each allowed input needs.
An algorithm solves the problem when it ends with the correct output for every allowed input.
5 How
- Write the word Input and say what the algorithm is given. For the card problem, that is a row of cards.
- Add the limits on the input: how many items, and of what kind. Here the limits are one or more cards, each showing an integer.
- Write the word Output and say what must be handed back. Here it is the largest number in the row.
- Choose three or four allowed inputs. Include the smallest allowed input. For the card problem, add a row with a repeated number as well.
- Work out the correct output for each chosen input by hand and write it beside the input. Keep the table for testing.
6 Trace
| Row | Allowed? | Output | Explanation |
|---|---|---|---|
| 4 9 2 | yes | 9 | Three cards. 9 is larger than 4 and larger than 2. |
| 7 | yes | 7 | One card is the smallest allowed row. Its number is the largest in the row. |
| 5 5 3 | yes | 5 | The largest number appears twice. The output is still one number, 5. |
| no cards | no | none | The statement allows one or more cards. An empty row is outside the problem, so no output is defined for it. |
7 The trap
The common slip is writing steps before the limits are settled. A statement that says a row of cards and stops there leaves the empty row open. One reader decides the output is 0, and another decides there is none. Decide which inputs are allowed and write the decision into the statement. In this unit the empty row is not allowed.
A second slip is naming the wrong output. The largest number in 5 5 3 is 5. The position of the largest card is a different output, and for this row two positions hold it.
Quick checks
Quick check 1 of 2
A task invented for this question: you are given a list of one or more whole-number scores, and you must report how many of them are 50 or more. Name the input, its limits and the output. Then give the output for the list 50 49 72.
Show the steps and the answer
Input: a list of scores. Limits: one or more whole numbers. Output: how many of the scores are 50 or more. For 50 49 72 the output is 2.
Why: 50 and 72 are each 50 or more, and 49 is not, so the count is 2.
Source: College Board, AP Computer Science Principles Course and Exam Description
Quick check 2 of 2
The card problem allows a row of one or more cards. Three rows are offered: 8, 2 2 and a row with no cards. Which are allowed inputs, and what is the output for each allowed row?
Show the steps and the answer
8 and 2 2 are allowed. Their outputs are 8 and 2. The row with no cards is not allowed, so it has no output.
Why: The statement asks for one or more cards. One card meets that limit, and so do two equal cards. An empty row does not.
Sources
- AP Computer Science Principles Course and Exam Description. College Board. All rights reserved. Read 1 Dec 2026.
- Computer Science Field Guide: Algorithms, 2.1 What's the big picture?. University of Canterbury Computer Science Education Research Group. CC BY-SA 4.0. Read 1 Dec 2026.