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

Algorithm Design and Problem-Solving

Uploaded by

wanziwa17
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Algorithm Design and Problem-Solving

Uploaded by

wanziwa17
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 81

26 May 2023

7
Algorithm Design and
Problem-Solving
Banani International School © 2025 - 0478

0478/Banani/2015/Student Notes
LESSON OBJECTIVES
1. Understand the program development
life cycle, limited to: analysis, design,
coding and testing
2. (a) Understand that every computer
system is made up of sub-systems,
which are made up of further
sub-systems
(b) Understand how a problem can be
decomposed into its component parts
LESSON OBJECTIVES
(c) Use different methods to design and
construct a solution to a problem
3. Explain the purpose of a given
algorithm 4. Understand standard
methods of solution

7.1
The program development life
cycle
Banani International School ©2025 - 0474
✔The program
development life cycle
is divided into five
stages: Analysis,
Design, Coding, Testing
and maintenance.
✔In this lesson will only
consider four stages
1. analysis
2. design
3. coding
4. testing

7.1.1
Analysis
Banani International School ©2025 - 0474
✔Before any problem can be
solved, it needs to be clearly
defined and set out so anyone
working on the
solution understands
what is needed.
✔This is called the
‘requirements specification’ for
the program. ✔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.
✔Decomposition breaks
down a complex problem
into smaller parts, which
can then be subdivided
into even smaller parts,
that can be solved easily.
For example,
getting dressed:
✔Select items to
wear ✔Remove
any clothes
being worn
✔Put selected
items on in
order
7.1.2

Design

Banani International School ©2025 - 0474


✔The program specification from the
analysis stage is used to show to how the
program should be developed.
✔When the design stage is
complete, the programmer
should know
✔what is to be done, i.e. all the tasks that
need to be completed,
✔how each task is to be performed
✔and how the tasks work together.

This can be
formally
documented
using
structure
charts,
flowcharts
and
pseudocode
7.1.3
Coding and iterative testing Banani

International School ©2025 - 0474

✔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.
7.1.4

Testing
Banani International School ©2025 - 0474
✔The completed
program or set of
programs is run
many times with
different sets of test
data. This ensures
that all the tasks
completed work
together as
specified in the
program design.
7.2.1

The computer system and its sub


systems
Banani International School ©2025 - 0474
A COMPUTER SYSTEM is made up of five
components: ✔Data,
✔Hardware,
✔Communications,
✔People and
✔Software
✔In order to understand how
a computer system is built
up and how it works it
is often divided up
into sub-systems.
✔This division can be
shown using top-down
design to
produce structure diagrams
that demonstrate the
modular construction of the
system.
✔Each
sub-system can be
developed by a
programmer as a
sub routine.
✔How each
sub-routine works
can be shown by
using flowcharts or
pseudocode.
TOP DOWN DESIGN

BANANI INTERNATIONAL SCHOOL © 2025 - 0478

✔Top-down design is the


breaking down of a computer system
into a set of sub-systems, ✔Or
Top-down design is a process that
moves
from a high-level design concept
towards a lower level.
✔A high-level level design concept
design concept is is smaller, more
larger, broader and specific and
more general; a low- detailed.
High Level ✔ Large ✔ Specific ✔ Detailed
✔ Broad
✔ General

Low Level ✔ Small


Digital Clock app for
smartphone
This is the effective way of designing a
computer system to provide a solution to
a problem, since each part of the problem
is broken down into smaller more
manageable problem.
✔The
process of
breaking down
into smaller
sub-system
s is called
‘STEPWISE
REFINEMENT’
✔When large computer
systems are being
developed this means
that several programmers
can work independently to
develop and test different
sub-systems for the same
system at the same time.
✔We do this all the dinner.
time in every day life, ✔A complete
for example, algorithm for solving
suppose your parent this problem might
need milk for your begin:
young sister’s ✔Find the car
keys ✔Go to the about feeding
garage ✔Get in
the kids, we do
the car
not plan our
✔Put the key in the
ignition algorithm in
✔Start the car such detail.
✔Back the car out of Instead our
the driveway
algorithm might
✔…
be:
✔However; when ✔Drive to the
we are worried store ✔Buy milk
✔Drive home level about the
✔We can do the major steps to be
done
same kind of ✔And then for each
segmental design of these subtasks,
for our programing design a separate
algorithm to solve
tasks: it
✔Begin by thinking
at a more abstract
7.2.2
DECOMPOSING A PROBLEM

BANANI INTERNATIONAL SCHOOL © 2025 - 0478


Any problem that uses a
computer system for its
solution needs to be
decomposed into its

component parts. The


component parts of any
computer system are:
✔inputs
✔processes
✔Outputs
✔storage
✔inputs – the data used by the system that
needs to be entered while the system is
active
✔processes – the tasks that need to be
performed using the input data and any other
previously stored data
✔outputs – information that needs to be
displayed or printed for the users of the
system
✔storage – data that needs to be stored in
files on an appropriate medium for use in
the future.
Example 1 For example, the alarm app can be
decomposed into: ✔inputs – time to set the alarm, remove a
previously set
alarm time, switch an alarm off, press snooze button
✔processes – continuously check if the current time
matches an alarm time that has been set, storage and
removal of alarm times, management of snooze ✔outputs –
continuous sound/tune (at alarm time or after snooze time
expired)
✔storage – time(s) for alarms set.

Class
Activity 1
Using one of the computer systems
that you identified, decompose it into
its component parts of inputs,
processes, outputs and storage
7.2.3

METHODS USED TO DESIGN AND


CONSTRUCT A SOLUTION
TO A PROBLEM

BANANI INTERNATIONAL SCHOOL © 2025 - 0478

Solutions to problems need to be designed and


developed rigorously. The use of formal methods
enables the process to be clearly shown for
others to understand the proposed solution. The
following methods need to be used by IGCSE
Computer Science students:
✔structure diagrams
✔Flowcharts
✔pseudocode.
Structure diagrams Banani

International School ©2025 - 0478

✔To show
top-down
design in a
diagrammatic form,
structure diagrams
can be used.
✔with each level
giving a more
detailed
breakdown of the
system into
sub-systems.

STRUCTURE
DIAGRAM shows
the design of a
computer system
in a hierarchical
way,
with
each
level
giving
a
more
detailed
breakdown of the
system into
sub-system
Alarm
app for a smartphone
Activity 2
1. Draw a structure diagram for borrowing a book
from the school library.
2. Draw a structure diagram for making and
serving coffee.
3. Using a structure diagram illustrate the
process of ordering a burger, with options of
fries and drink or both or non
Borrowing a Book from a school library
Borrowing a
Book

Reader Books Identification

Book

Member Non
Secondary Primary Text Book Non Text

Member
Flowcharts Banani International School ©2025 - 0478

✔A Flowchart shows
diagrammatically the
steps required for a
task (sub-system)
and the order that
they are to be
performed.
✔These steps together
with the orders are
called an
ALGORITHM

2.2.1
PROBLEM-SOLVING & DESIGN
ALGORITHM

WHAT IS AN ALGORITHM?

BANANI INTERNATIONAL SCHOOL © 2017 - 0478

1. An algorithm is
simply a sequence
of instructions
written to solve a
given problem.
2. Or A set of steps to
get you from State A
to State B.
3. Is a sequence of
steps to solve a given
problem or execute a
given task.
Flowcharts are drawn
using standard
flowchart symbols. 1.
Begin/End
Terminator
flowchart symbols
are used at the
beginning and end
of each flowchart.
2. Process
Process flowchart
symbols are used to
show actions, for
example, when
values
are assigned to
variables. If a
process has been
defined elsewhere then
the name of that
process is shown.
3. Input and
output The
same
flowchart
symbol is
used to show
the input of
data and
output of
information.
4. Decision
Decision flowchart symbols are used to decide which
action is to be taken next; these can be used for
selection and repetition/iteration. There are always two
outputs from a decision flowchart symbol.

Yes/no
5. Flow lines
Flowchart flow
lines use arrows
to show the
direction of flow,
which is usually,
but not always,
top to bottom and
left to right.

Example 1 Using a flowchart


illustrate the process of ordering a burger, with
options of fries and drink or both or non.
Class Activity 3

Write an algorithm in a form of a flowchart that allows


users to do the following:
✔Allows the users to think of a
number ✔Ask users to write the number
down
✔If the number is even, divide it by 2 ✔If
the number is not even, multiply it by 3 and
add 1
✔The number (resultant) should be 1
✔Include appropriate loops (if necessary)
START

Think of a
Number
Write down the
Number Multiply
Even? by three
YES
and add
Divide number by Number one
the two NO
Is
NO

Answer One
NO
YES
Is
STOP
Class
Activity 4

Write an algorithm in form of a flowchart outlining the


steps required in borrowing a computer science
book from the school library.
Purpose: Borrowing a Computer Science Book
✔START
✔Input student ID
✔Is it a varied ID, if yes proceed, if no loop to
student ID
✔Input book
✔Is it a computer Science book?, if yes, sign for
it. if no loop to input book
✔Input barcode number
✔Input Name
✔Input period of borrowing.
✔Sign out
✔STOP
Class
Activity 4

Tickets are sold for a concert at $20 each, if 10


tickets are bought then the discount is 10%, if 20
tickets are bought the discount is 20%. No more
than 25 tickets can be bought in a single
transaction.
Solution
1. Prompt the user to enter tickets to buy
2. Input ticket numbers
3. Is number of tickets more than or equal than 1 and
less than 26
4. If no loop
5. If yes, is it less than 10, if no, no discount 6.
If yes, is number less than 20,if yes 10% discount
7. If no, 20% discount
8. Cost equals to number of tickets * price -
discount 9. Output cost

Flowchart
Class Activity 4

Banani International School runs a private clinic.


Patients are charged according to number of days
they are admitted. Patients admitted over 4 days,
are charged K 200:00, patients over 2 days are
charged K 100.00 and patients less than a day incur
K0.00 charge.

Write an algorithm, in the form of a flowchart, to


show the charge on any patient admitted by the
clinic.
Pseudocode Banani International School ©2025 -

0478

✔Pseudocode is a simple method of


showing an algorithm.
✔It describes what the algorithm does by using
English key words that are very similar to
those used in a high-level programming
language.
✔Data items to be processed by the
algorithm are given meaningful names in
the same way that variables and
constants are in a high-level
programming language.
✔However,
pseudocode is not
bound by the
strict syntax rules
of a programming
language.
✔It does what its
name says, it
pretends to be
programming
code!
To ensure that
pseudocode is
easily
understandable by
others it is useful to
be consistent in the
way that it is
written
✔All keywords
(words used to
describe a specific
action e.g.
INPUT) are
written in capital
letters
✔all names given
to data items and
subroutines start
with a capital
letter
✔where
conditional and
loop statements
are used,
repeated or
selected
statements are
indented by two
spaces
The pseudocode for
an assignment
statement ✔A value
is assigned to
an item/variable
using the ←
operator.
✔The variable on the
left of the ← is
assigned the value
of the expression on
the right.
✔The expression on
the right can be
a single value
or several
values
combined with any
of the following
mathematical
operators.
✔The expression on
the right can be
a single value
or several
values
combined with
any of the
following
mathematical
operators.
Class
Activity 5
26 May 2023

What values will the following variables have after


the assignments have been completed?
Conditional
Statements The pseudocode for
conditional statements

You might also like