Problem Solving

Algorithm

Students follow a sequence of picture cards to assemble a small toy.

Algorithm definition

An algorithm is a precise sequence of steps for solving a problem or producing a result.

In Spanish
algoritmo
Topic
Algorithms and problem-solving

Algorithm in a picture

Algorithm diagramTo find the larger of two numbers, compare them and return the greater value.Input: two numbers a and bStart with the two given valuesCompare a and bIf a ≥ b, choose aOtherwise choose bReturn the chosen value and stop
To find the larger of two numbers, compare them and return the greater value.

How it works

An algorithm specifies its input, the actions it takes, and what it returns or when it stops. A correct algorithm gives the intended result for every valid input. You can write its steps in words, pseudocode, or a programming language.

Worked examples

Give an algorithm for finding the total of a list.

Start a total at 0. Add each list item to it, one at a time, then return the total.

Can two algorithms solve the same problem?

Yes. They may use different steps or require different amounts of work.

Why specify the valid input?

It tells you when the procedure is expected to produce the promised result.

Common mistake

State a stopping condition. Steps that keep repeating forever do not finish the computation for that input.

Quick check

What must a correct algorithm do for a valid input?

Can an algorithm be written without code?

Show answer

Yes, if the steps are precise enough.

Is a worked answer by itself a general algorithm?

Show answer

No. A general algorithm gives steps that apply to its valid inputs.

Sources

Flashcard

Algorithm

Reveal the definition

An algorithm is a precise sequence of steps for solving a problem or producing a result.

Effortless Math. “Algorithm.” Math Dictionary.