Unit 1 · Basics of Computer Programming

1.1Algorithms

Before you write any code you need a plan. This topic explains what an algorithm is, the three structures every algorithm is built from, and a step-by-step method for solving problems, with three worked examples.

Key words in this topic

  • Algorithm: a finite list of clear steps that solves a problem.
  • Control structure: one of the three ways steps can be arranged: sequence, selection or iteration.
  • Input, process, output (IPO): what goes in, what is done, and what comes out.
  • Dry run (trace): following the steps by hand with sample values to check that they work.

Why start here? A computer does exactly what it is told, nothing more and nothing less. If the plan is wrong, the program will be wrong, however good your Java is. Learning to write clear algorithms is the skill that every later topic in this module depends on.

In this section