0% found this document useful (0 votes)
3 views

CH07 - Algorithm Design and Problem Solving

The document discusses the different stages of the program development life cycle including analysis, design, coding, testing and maintenance. It then provides details about each stage such as the use of abstraction and decomposition in analysis and structure diagrams, flowcharts and pseudocode in design.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

CH07 - Algorithm Design and Problem Solving

The document discusses the different stages of the program development life cycle including analysis, design, coding, testing and maintenance. It then provides details about each stage such as the use of abstraction and decomposition in analysis and structure diagrams, flowcharts and pseudocode in design.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 39

CH07 - Algorithm design and Problem solving

Program development life cycle


• When a person, or organisation, creates a new
1.
computer program they will use a structured, Analysis

organised plan of how to create the program.


This is called the program development life 4.Testing
2.
Design
cycle. The program development life cycle is
divided into five stages: analysis, design,
3.
coding, testing and maintenance. Coding

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


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.

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

• 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

• Decomposition breaks down a complex problem into smaller parts, which


can then be subdivided into even smaller parts, that can be solved easily.
Any daily task can be divided into its constituent parts.
• For example, getting dressed:
• Select items to wear
• Remove any clothes being worn
• Put selected items on in order.

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.

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

3. Coding and iterative testing


• The program or set of programs is developed. Each module of the
program is written using a suitable programming language and then
tested to see if it works. Iterative testing means that modular tests are
conducted, code amended, and tests repeated until the module performs
as required.

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

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.

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

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.

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

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.

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

Example pseudocode:
INPUT Number1
IF Number1 < 10
THEN
OUTPUT "too small"
ELSE
OUTPUT "valid"

ENDIF

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

• There are many different valid pseudocode formats.


• Some will always use capitals for the commands, e.g. INPUT, IF, FOR.
• Some will use ← instead of an = for assignment.
• What is important is that the program is split into steps that can be easily
converted into a real program.

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

Table 7.2 shows some examples of valid and invalid pseudocode.

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

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.

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

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.

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

• 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.

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

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.

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

Input and Output

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

Selection
• Selection is a very useful technique, allowing different routes through the
steps of a program.
• IF statements
• Case statements

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

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

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

DECLARE day: INTEGER


INPUT day
CASE OF day
1 : OUTPUT “Monday”
2 : OUTPUT “Tuesday”
3 : OUTPUT “Wednesday”
4 : OUTPUT “Thursday”
5 : OUTPUT “Friday”
6 : OUTPUT “Saturday”
7 : OUTPUT “Sunday”
OTHERWISE OUTPUT “Please enter a valid number”
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.

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

Count-controlled loops
• FOR loops are used when a set number of iterations are required.
• Count-controlled loops are written as follows:

FOR <identifier> ← <value1> TO <value2>


<statements>
NEXT <identifier>

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.

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/


CH07 - Algorithm design and Problem solving

• An increment can be specified as follows:

FOR <identifier> ← <value1> TO <value2> STEP <increment>


<statements>
NEXT <identifier>

• The increment must be an expression that evaluates to an integer. In this


case the identifier will be assigned the values from value1 in
successive increments of increment until it reaches value2. If it goes past
value2, the loop terminates. The increment can be negative.

CIE IGCSE LEVEL: COMPUTER SCIENCE /0478/

You might also like