Teach Any Computer Science Class
We have put together a full GCSE Computer Science curriculum that will give you all the teaching materials you need to teach any topic.
Whether you're a brand new Computer Science teacher, or you've been teaching ICT for years, our resources will save you hours and hours of lesson preparation every single week.View the Lessons →
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?
An 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.
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.|
|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
|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.|
|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
|Example 3 – An algorithm to calculate the average price for a number of items.|
|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
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.