CH07 - Algorithm Design and Problem Solving
CH07 - Algorithm Design and Problem Solving
1. Analysis
• This first stage involves looking at the problem and the system that is
needed. The problem is explored, and the requirements of the program
are identified.
• The analysis stage uses abstraction and decomposition tools to identify
exactly what is required from the program.
• Abstraction keeps the key elements required for the solution to the
problem and discards any unnecessary details and information that is not
required.
For example, a map only shows what is required for travelling from one place to another. Different methods of transport
will require different types of map.
CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/
CH07 - Algorithm design and Problem solving
2. Design
• Once the requirements have been identified, the program designers can
begin planning how the program will work in the design phase. This can
include an overview of the program using a structure diagram, and the
designing of algorithms using structure charts, flowcharts and
pseudocode.
Structure diagram
• A structure diagram is developed by decomposing a program into its
subprograms. The diagram has the name of the program at the top, and
below this its subprograms. Each subprogram can be split down further as
well if required.
Flowcharts
•A flowchart is a diagrammatic
representation of an algorithm. Flowchart
has the standard symbols.
• A flowchart shows each step of a
process, in order that each step is
performed. Each shape has one
statement within it.
Pseudocode
• Pseudocode refers to any code that is not written on a computer to run.
There is no one set pseudocode, because if there was then this would be
code with a specific language. Instead it’s a term for any readable code-like
statements that all programmers will understand. This means that it uses
keywords, and constructs such as IF statements, WHILE loops, etc. These
constructs occur in almost all languages, so any programmer would be
expected to read them and translate them into the actual programming
language they are using.
Example pseudocode:
INPUT Number1
IF Number1 < 10
THEN
OUTPUT "too small"
ELSE
OUTPUT "valid"
ENDIF
Coding
• Once you have decomposed your problem into subproblems, and you have
designed the algorithms using flowcharts and/or pseudocode then you can
start writing the program in your chosen programming language. This is
often referred to as coding.
Testing
• When you have finished your program, you need to carry out testing to
make sure it:
• fully works
• does not crash
• meets all requirements.
• You will need to identify appropriate test data to use to test the program.
There are four types of test data:
• Normal – data that the program should accept.
• Abnormal– data that the program should not accept.
• Extreme– data that is at the edge of what is allowed.
• Boundary– data that is on the edge of being accepted and being rejected.
Data types
• Data in programs can be of different types.
For example, it could be numeric or text. You
will need to tell your program what type of
data you want it to store. Some
programming languages need you to declare
what type of data your variable will store
when you first use it.
Selection
• Selection is a very useful technique, allowing different routes through the
steps of a program.
• IF statements
• Case statements
Case statements
• Case statements are used when there are multiple choices to be made.
• CASE statements are written as follows:
CASE OF <identifier>
<value 1> : <statement>
<value 2> : <statement>
...
OTHERWISE <statement>
ENDCASE CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/
CH07 - Algorithm design and Problem solving
Iteration
• There are three types of loop structures available to perform iterations so
that a section of programming code can be repeated under certain
conditions.
• These are:
• Count-controlled loops (for a set number of iterations)
• Pre-condition loops – may have no iterations
• Post-condition loops – always has at least one iteration.
Count-controlled loops
• FOR loops are used when a set number of iterations are required.
• Count-controlled loops are written as follows:
The variable is assigned each of the integer values from value1 to value2 inclusive, running the statements inside
the FOR loop after each assignment. If value1 = value2 the statements will be executed once, and if value1 >
value2 the statements will not be executed.