Quarry School

State inputs and outputs — quick review

In plain words

A friend slides a row of number cards across the table and asks for the largest number.

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.

Step

  1. Write the word Input and say what the algorithm is given. For the card problem, that is a row of cards.

  2. 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.

  3. Write the word Output and say what must be handed back. Here it is the largest number in the row.

  4. Choose three or four allowed inputs. Include the smallest allowed input. For the card problem, add a row with a repeated number as well.

  5. Work out the correct output for each chosen input by hand and write it beside the input. Keep the table for testing.

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.