Αρχική » 1. algorithms » BBC Representing an algorithm: Pseudocode and flowcharts

BBC Representing an algorithm: Pseudocode and flowcharts

There are two main ways that algorithms can be represented – pseudocode and flowcharts.

Representing an algorithm: Pseudocode

Most programs are developed using programming languages. These languages have specific syntax that must be used so that the program will run properly. Pseudocode is not a programming language, it is a simple way of describing a set of instructions that does not have to use specific syntax.

Writing in pseudocode is similar to writing in a programming language. Each step of the algorithm is written on a line of its own in sequence. Usually, instructions are written in uppercase, variables in lowercase and messages in sentence case.

In pseudocode, INPUT asks a question. OUTPUT prints a message on screen.

A simple program could be created to ask someone their name and age, and to make a comment based on these. This program represented in pseudocode would look like this:

OUTPUT 'What is your name?'
INPUT user inputs their name
STORE the user's input in the name variable
OUTPUT 'Hello' + name
OUTPUT 'How old are you?'
INPUT user inputs their age
STORE the user's input in the age variable
IF age >= 70 THEN
OUTPUT 'You are aged to perfection!'
ELSE
OUTPUT 'You are a spring chicken!'

In programming, > means ‘greater than’, < means ‘less than’, ≥ means ‘greater than or equal to’ and ≤ means ‘less than or equal to’.

Representing an algorithm: Flowcharts

A flowchart is a diagram that represents a set of instructions. Flowcharts normally use standard symbols to represent the different instructions. There are few real rules about the level of detail needed in a flowchart. Sometimes flowcharts are broken down into many steps to provide a lot of detail about exactly what is happening. Sometimes they are simplified so that a number of steps occur in just one step.

Flowchart symbols

bbc flowchart

A simple program could be created to ask someone their name and age, and to make a comment based on these. This program represented as a flowchart would look like this:

bbc algo 2

Αλλαγή μεγέθους γραμματοσειράς
Αντίθεση