You are on page 1of 4

PROBLEM SOLVING NOTES

REPRESENTING ALGORITHMS (METHOD TO SPEAK TO


COMPUTER)
What is an algorithm?
An algorithm is a sequence of instructions that has a FINITE number of steps,
which once followed would give the precise solution to the given problem. At
the end of each instruction, there is no doubt as the next step. There is a flow of
control from one step to the other. ALGORITHMS produce an
UNAMBIGUOUS result and always come to an end.

Three ways to represent an algorithm:


1) Narrative (using your own words in English, for example speaking to
SIRI)
2) Flowcharts (uses symbols to represent different stages in solving a
problem)
3) Pseudocode (closest resemblance to actual programming code, similar in
structure)
Designing an algorithm test questions - KS3 Computer Science Revision - BBC Bitesize.

NARRATIVE CODE –
NARRATIVE CODE: (resembles sentences, cannot be understood by a
computer)
Write a program to read three numbers and display the sum.
Start
Get three numbers
Add the numbers
Store the result in a sum
Display the sum
End

PSEUDOCODE
Uses shorter variable names
Uses the shortest method to complete a task

1|Page
PSEUDOCODE TERMS / KEYWORDS
INPUT TERMS: INPUT, READ, GET
OUTPUT: WRITE, DISPLAY, PRINT
TO SET A VALUE: STORE, , =
OTHER CONSTRUCTS:
IF, ELSE, ELSEIF
FOR
WHILE, REPEAT UNTIL
ALL COMPUTER PROCESSSES BOIL DOWN TO 10101010 (ones and
zeros)

VARIABLES:
A variable is assigned a position in memory. Some variables may have to be
initialised. Variables are values that can changed.
Examples of the use of variables: number 1  n1, number 2  n2.

CONSTANTS : pi (always be 3.812232)

MATHEMATICAL OPERATORS:
+ ADDITION
- SUBTRACTION
* MULTIPLICATION
/ DIVISION

RELATIONAL OPERATORS:
> GREATER THAN
< LESS THAN
>= GREATER THAN OR EQUAL
TO
<= LESS THAN OR EQUAL TO
!= or NOT EQUAL TO
<>

LOGICAL OPERATORS: AND, OR NOT

2|Page
DATA TYPES:
INTEGERS – whole numbers that can be positive or negative. Eg. 77, -90,234
FLOATING POINT NUMBERS OR REAL NUMBERS. They can be positive
or negative but always have a decimal point. Eg 3.45, 0.45, -0.21
CHARACTERS – anything that can be entered from a keyboard. (&, #, g, 7, *)

PSEUDOCODE examples.
Write a program to read 3 numbers and display the sum
Answer:
Start
Read a (can be substituted for input, get)
Read b
Read c
Sum = a+b+c
Display sum
Stop

Example 2.
Read 3 numbers, find the average of the 3 numbers and multiply the average by
the sum of the 3 numbers.
Start
Read a
Read b
Read c
Sum = a+b+c
Avg = sum/3
Answer = avg * sum
Print answer
Stop

Write a program to find and print the area of a rectangle.


Read l
Read w

3|Page
Area = l * w
Print area

4|Page

You might also like