9.1_9.2 Algorithm Design 2024_copy
9.1_9.2 Algorithm Design 2024_copy
Computational thinking is used to study a problem and formulate an effective solution that can
be provided using a computer.
Abstraction – the process of extracting information that is essential, while ignoring what is not
relevant, for the provision of a solution.
Many everyday items use abstraction, such as maps, calendars and timetables.
For example, a road map should only show the necessary detail required to drive from one place
in
to another. The road map may reduce the complexity by only showing the essential details
needed, such as roads, road numbers and towns, and removing other information about the
terrain that would not be helpful.
st
The benefits of eliminating any unnecessary characteristics from the model include:
• the time required to develop the program is reduced so the program can be delivered to
the customer more quickly.
u
• the program is smaller in size so takes up less space in memory and download times are
shortened.
g
• customer satisfaction is greater as their requirements are met without any extraneous
features.
u
Decomposition leads us to the concept of program modules and using procedures and
functions.
1
A Level Computer Science P2 N.A
We can set up abstract data types to model real-world concepts, such as queues or stacks.
When a programming language does not have such data types built-in, we can define our own
by building them from existing data types. There are more ways to build data models:
Pattern recognition – the identification of parts of a problem that are similar and could use the
same solution.
There are many standard algorithms to solve standard problems, such as sorting or searching.
in
Algorithms
Algorithm – an ordered set of steps to be followed in the completion of a task.
st
When we design a solution to a problem we express the solution (the algorithm) using
sequences of steps written in structured English, pseudocode and flowchart.
u
Structured English – a method of showing the logical steps in an algorithm, using an agreed
subset of straightforward English words for commands and mathematical operations.
g
Pseudocode – a method of showing the detailed logical steps in an algorithm, using keywords,
identifiers with meaningful names, and mathematical operators.
u
2
A Level Computer Science P2 N.A
in
st
u
g
u
A
r.
• Assignment: a value is given a name (identifier) or the value associated with a given
identifier is changed.
M
3
A Level Computer Science P2 N.A
To input a value:
To assign a value to a variable (the value can be the result of a process or a calculation):
in
st
u
g
Operators used in pseudocode assignment statements:
u
A
r.
M
To perform a selection using IF statements for a single choice or a choice and an alternative,
and CASE statements when there are multiple choices or multiple choices and an alternative:
4
A Level Computer Science P2 N.A
in
st
u
To perform iteration using FOR, REPEAT–UNTIL and WHILE loops:
g
u
A
5
A Level Computer Science P2 N.A
WHILE and REPEAT loops and IF statements make use of comparisons to decide whether
statements within a loop are repeated or a statement or group of statements are executed.
The comparisons make use of relational operators and the logic operators AND, OR and NOT.
in
The outcome of these comparisons is always either true or false.
st
u
Writing pseudocode from a structured English description
g
From a structured English description, the following things need to be possible:
u
• Any variables that need to be used can be identified and put in an identifier table – these
can be items input or output as the results of calculations.
• Input and output can be identified from the wording used, for example,
A
Repeat.
• Any processes needed can be identified from the wording used, for example, Set,
Calculate.
M
6
A Level Computer Science P2 N.A
This can be used to identify the variables required and complete the identifier table:
Using these identifiers, each step of the structured English algorithm can be converted to
pseudocode, as demonstrated below.
in
st
u
g
u
A
r.
M
7
A Level Computer Science P2 N.A
in
st
u
Here is an example of a flowchart of an algorithm that can be used to check an exam grade:
g
u
A
r.
M
8
A Level Computer Science P2 N.A
in
st
u
g
Stepwise refinement – the practice of subdividing each part of a larger problem into a series of
smaller parts, and so on, as required.
u
Look at the first step of the structured English to calculate a time in seconds.
A