Edexcel IGCSE Computer Science
Edexcel IGCSE Computer Science
Problem Solving
Understanding Algorithms
What is an algorithm?
o An algorithm is a sequence of steps that can be followed in all order to complete a task.
Example:
o Produce a written description of an algorithm for borrowing a book from the library.
o Enter the library
o Choose a book you would like to read.
o Check if you have read it before.
o Record your details.
o Walk out of the library with the book.
Algorithms
o Algorithms are divided into 2 different formats.
o Flowchart- graphical representation
o Pseudocode- Structured format
Flowcharts
o Flowcharts can be used to show an algorithm as a diagram. It’s a graphical
representation of an algorithm.
Example:
o Produce a flowchart describing an algorithm for borrowing an book from the library.
Start
End
Controlled Structures
What are the three types of control structures used in an algorithm?
o Sequence- If the steps from the beginning to the end of an algorithm are carried out in a
strict order.
o Selections- A construct that allows a choice to be made between different alternatives.
o E.g.: - Simple IF, IF < > THEN ELSE ENDIF, NESTEDIF, CASE < > OF
o Repetitions/ loops- If one or several steps of an algorithm are repeated until a condition
is satisfied.
o E.g.: - REPEAT, FOR NEXT, WHILE DO
Pseudocode keywords
Input SEND “Enter Number 1” TO DISPLAY
RECEIVE Number1 FROM KEYBORD
Process SET total TO 0
SET total TO Number1+Number2
Output SEND “The total is”, total TO DISPLAY
Example:
o Write a pseudocode to find perimeter and area of a rectangle.
Answer:
SEND “Enter length” TO DISPLAY
RECEIVE length FROM KEYBOARD
SEND “Enter width” TO DISPLAY
RECEIVE width FROM KEYBOARD
SET Area TO length * width
SET Perimeter TO (width+length)*2
SEND “The Area is” & Area TO DISPLAY
SEND “The Perimeter is” & Perimeter TO DISPLAY
Arithmetical Operations
Function Operator
Addition +
Subtraction -
Multiplication *
Real division /
Quotient // / DIV
Modulus/modulo % / MOD
Exponentiation ** / ^
What is a variable?
o The data stored in a variable is referred to as a value. The value stored in a variable is not
fixed. The same variable can store different values during the course of a program and
each time a program is run.
What is a constant?
o A container that holds a value that never changes: like variables, constants have unique
identifiers.
Selections
What is a selection?
o A construct that allows a choice to be made between different alternatives.
Simple IF condition
Is
expression
?
IF …. THEN …. ELSE …. ENDIF
IF <expression>THEN
<command>
ELSE
<command>
ENDIF
NESTED ‘IF’
IF <expression> THEN
<command>
ELSE
IF <expression> THEN
<command>
ELSE
<command>
ENDIF
ENDIF
Logical Operators
‘AND’ operator
o If two conditions are joined by the ‘AND’ operator, then they must both be true for the
whole statement to be true.
‘OR’ operator
o If two conditions are joined by the ‘OR’ operator, then either one must be true for the
whole statement to be true.
Loops
o Loops are used to make a computer repeat a set of instructions more than once.
o Definite- when the number of repetitions of loops is known in advance
o FOR loop
FOR <id> FROM <expression> TO <expression> DO
<command>
ENDFOR
o Repeat loop
o Indefinite
o While loop
o Repeat until