Computer Algorithms

KS3 Computer Science

11-14 Years Old

48 modules covering EVERY Computer Science topic needed for KS3 level.

GCSE Computer Science

14-16 Years Old

45 modules covering EVERY Computer Science topic needed for GCSE level.

A-Level Computer Science

16-18 Years Old

66 modules covering EVERY Computer Science topic needed for A-Level.

KS3 Algorithms Resources (14-16 years)

  • An editable PowerPoint lesson presentation
  • Editable revision handouts
  • A glossary which covers the key terminologies of the module
  • Topic mindmaps for visualising the key concepts
  • Printable flashcards to help students engage active recall and confidence-based repetition
  • A quiz with accompanying answer key to test knowledge and understanding of the module

A-Level Introduction to Algorithms (16-18 years)

  • An editable PowerPoint lesson presentation
  • Editable revision handouts
  • A glossary which covers the key terminologies of the module
  • Topic mindmaps for visualising the key concepts
  • Printable flashcards to help students engage active recall and confidence-based repetition
  • A quiz with accompanying answer key to test knowledge and understanding of the module

Candidates should be able to:

  • understand algorithms (written in pseudocode or as flow diagrams), explain what they do, and correct or complete them
  • produce algorithms in pseudocode or flow diagrams to solve problems.

What is an algorithm and how can algorithms be represented?

A computer algorithm is a sequence of statements (instructions) that can be executed (carried out) by a computer to perform a particular task.

Pseudocode and flow diagrams are two ways to represent algorithms.

  • Everyday language is not used because the statements would be too long and rely too much on how the reader interprets them.
  • Formal programming languages are not used because algorithms are intended to be independent of the programming language.

What is a pseudocode algorithm?

Pseudocode algorithms use adapted everyday language. This means that the instructions are readable by a human but still look something like the statements available in many programming languages.

Pseudocode is not a strict list of commands since it is not meant to be understood by a computer. There are therefore no universal standards but pseudocode should ideally follow the following guidelines:

  • Sequential instructions should be arranged on separate lines with the first instruction at the top.
  • Indentation should be used with blocks of instructions that are part of control operations (such as conditional and iterative operations)
  • Keywords should be in uppercase and the rest of the pseudocode should be in lower case.
  • It should only be possible to interpret the pseudocode in one way
  • The pseudocode must actually be computable, it must be possible for the program code equivalent of the pseudocode to be carried out by a computer.
  • Descriptions/comments can be included but should be as brief as possible.
  • It must be complete, with nothing is left out.
  • It must have an end, so it does not continue for ever.

Pseudocode will often end with a list of all the variables used in the algorithm.

Once a programmer is happy with the pseudocode it can then be developed into a working program written in the source code of the programming language to be used. One example of how an algorithm can be used in a real world application is the BIN number checker. The algorithm here must take the number input by the user, search through entries in a database, and find the relevant information to return and be displayed on the page.

Some examples of key word operations used in pseudocode

  • WHILE / ENDWHILE is an example of top-test iterative operation where the algorithm repeats a block of instructions until the condition tested at the start of the block is FALSE.
  • REPEAT / UNTIL is a bottom-test iterative operation where the algorithm repeats a block of instructions until the condition tested at the end of the block is FALSE (the instructions will always be carried out at least once).
  • CASE OF is a multiple decision branch based on the value of an expression.
  • INPUT, READ, OBTAIN and GET are used to input data.
  • OUTPUT, PRINT, DISPLAY and SHOW are used to output data.
  • COMPUTE, CALCULATE, DETERMINE and = are use to carry out calculations.
  • SET and INIT are used to initialise variables.
  • INCREMENT is used to increment a variable.
  • IF / THEN / ELSE / ENDIF is used to select different instructions based on the result of a TRUE/FALSE test.
  • FOR / ENDFOR is used for repeating a block of instructions a specific number of times.

What is a flow diagram algorithm?

Flow diagram algorithms use labelled shapes to represent the instructions in the program and arrows to show the order of the instructions. Some examples of the standard shapes used in flow diagrams are shown below.

Computer Algorithm: Some of the common symbols used in flow diagrams
Some of the common symbols used in flow diagrams

Constructing an algorithm using a flow diagram rather than pseudocode can often make it easier to follow the sequence of steps involved and make it easier to find logic errors.


What does an algorithm look like as pseudocode and as a flow diagram?

Example 1 – An algorithm to calculate the Sales Tax (VAT) of an item and then use it to work out the final price of an item.
Pseudocode Flow Diagram
This algorithm uses the sequential instructions: INPUT and OUTPUT.

Example 1 – An algorithm to calculate the Sales Tax (VAT) of an item and then use it to work out the final price of an item.
PseudocodeFlow Diagram
This algorithm uses the sequential instructions: INPUT and OUTPUT.

 

INPUT item_price
INPUT vat_rate
vat_amount = item_price x vat_rate
final_price = item_price + vat_amount
OUTPUT final_price
END

 

Variables: item_price, vat_rate, vat_amount, final_price

Flow Diagram 1
Example 2 – An algorithm to calculate weekly wages when gross pay depends on the pay rate and the number of hours worked per week. If more than 35 hours are worked, time-and-a-half is paid for the extra hours.
PseudocodeFlow Diagram
This algorithm uses the sequential instructions: INPUT and OUTPUT and the conditional control operations IF / THEN / ELSE / ENDIF.

 

INPUT hours_worked
INPUT pay_rate
IF hours_worked <= 35 THEN
gross_pay = pay_rate x hours_worked
ELSE
gross_pay = (pay_rate x 35)+
(1.5 x pay_rate x
(hours_worked - 35))
ENDIF
OUTPUT gross_pay
END

 

Variables: hours_worked, pay_rate, gross_pay

Flow Diagram 2
Example 3An algorithm to calculate the average price for a number of items.
PseudocodeFlow Diagram
This algorithm uses the sequential instructions: INPUT, SET and OUTPUT and the iterative control operation WHILE / ENDWHILE.

 

INPUT total_items SET total_cost = 0 SET count = 0 WHILE count < total_items INPUT item_price total_cost = total_cost + item_price count = count + 1 ENDWHILE average_price = total_cost / total_items OUTPUT average_price END

 

Variables: total_items, total_cost, count, item_price, average_price

Flow Diagram 3

Why do teams of programmers need to agree standards when developing software?

When programmers work as a team then all the team members:

  • need to understand each other’s code so clear commenting is important;
  • must agree of a consistent format for naming variables;
  • need to agree on a consistent interface and navigation system between the modules they work on;
  • must agree on consistent protocols, for example when accessing network resources of data files.

Further Readings: