c7 Algorithm Design & Problem Solving
c7 Algorithm Design & Problem Solving
Analysis Design
C7.1
Program
Development
Life Cycle
Coding Testing
Cycle
Life
C7.2 - System,
sub-system
and Structured Diagram
Computer system
•
•
Computer system
Example
• Made up of software,
data, hardware,
communications and
people.
• Each computer system
can be divided up into a
set of sub-systems
• Each sub-systems can be
further divided into sub-
systems and so on until
each sub-system just
performs a single
action.
Computer system Example
• Made up of software,
data, hardware,
communications and
people.
• Each computer system
can be divided up into a • Software - the code
set of sub-systems • Data - users' preference (like and
• Each sub-systems can be follow)
further divided into sub-
• Hardware - server to store all the
systems and so on until
data (posts, stories, etc)
each sub-system just
performs a single
• Communication and people -
action. instagram's employees
Computer system Example
• Made up of software,
data, hardware,
communications and
people.
• Each computer system
can be divided up into a
set of sub-systems
• Each sub-systems can be
further divided into sub-
systems and so on until
each sub-system just
performs a single
action.
post story reel
Computer system
Normal
• Made up of software,
data, hardware,
communications and
people.
• Each computer system
can be divided up into a
set of sub-systems
• Each sub-systems can be
further divided into sub-
systems and so on until story
each sub-system just Close
performs a single friends
action.
Other examples of a
computer system
•
•
•
to aspiring programmer
Top-down design
Structured diagram in application
(alarm clock)
Alarm Clock
Structured diagram in application
(alarm clock)
Alarm Clock
Inputs Outputs
Processes
Structured diagram in application
(alarm clock)
Alarm Clock
Inputs Outputs
Processes
Set Time
Turn alarm
Check Time Sound Turn off
on and off
Alarm alarm
Definition of algorithm
An algorithm is a set of
instructions for solving a
problem or accomplishing a task.
Example of an algorithm (Real Life)
Example of an algorithm (Real Life) - Driving a car
Walk to the
parking space Letgoooo!
Turn on the
engine
Example of an algorithm (Software) - Alarm clock
If both matches,
send signal to
sound system
Flowchart and pseudocode are an effective way to
communicate how the algorithm that makes up a
system or a sub-system work.
Flowchart and pseudocode are an effective way to
communicate how the algorithm that makes up a
system or a sub-system work.
Have a look at a
flowchart showing
how the checking for
the alarm time
subsystem works, can
you understand what
is it doing?
Components of a flow chart
Terminator process Input/output
Used at the Show the input of
Represent an
beginning and end data and output
instruction
of each flowchart of information
No matter how Protecting the
small the environment is
ecosystem on the same as
earth, everything protecting the
is interconnected ecosystem
Components of a flow chart
Decision
• Used to decide which action is to be taken
next
• There are always two outputs from a decision
flowchart symbol
Components of a flow chart
subroutine Flowline
• Represents a smaller • Use arrows to show the
procedure running within direction of flow
the large program.
• Abstraction in action
• Could be
another
flowchart
defined
elsewhere
Input/
output
Terminator
subroutine
process
Decision
A computer program allows a user to
input two numbers. It multiplies the
Analysis
numbers together and if the answer is
larger than 100 it outputs the message Input:
"Greater than 100". The program loops
until the user does not want to input
Output:
any more numbers. Process:
Draw a flowchart that represents an
algorithm for the computer program.
A computer program allows a user to
Analysis
input two numbers. It multiplies the
numbers together and if the answer is Input: Number 1 & 2
larger than 100 it outputs the message
"Greater than 100". The program loops
Output: Message >100
until the user does not want to input
any more numbers.
Process:
- if N1 + N2 > 100,
Draw a flowchart that represents an
algorithm for the computer program. output message >100
- process continue until
user does not want to
input numbers
A computer program allows a user to
input two numbers. It multiplies the
numbers together and if the answer is
larger than 100 it outputs the message
"Greater than 100". The program loops
until the user does not want to input
any more numbers.
Terminator
•
•
•
•
•
•
•
•
•
• ←
• ←
• ←
• ←
• ←
←
←
←
•
•
•
←
←
←
←
←
←
←
←
←
←
←
←
←
←
←
←
←
•
←
←
←
←
•
←
←
←
←
←
←
←
←
•
•
←
←
←
←
←
•
←
←
←
←
←
•
•
←
←
Totalling
←
←
•
←
←
←
←
•
Say,we want to search for a
student called Lyn ..
Found!
←
•
•
Find this video on YouTube for a
thorough explanation!
←
←
←
←
←
←
←
←
←
C7.6
VALIDATION AND
VERIFICATION
James Gan
IN ORDER FOR COMPUTER SYSTEMS TO ONLY ACCEPT DATA INPUTS THAT ARE
REASONABLE AND ACCURATE, EVERY ITEM OF DATA NEEDS TO BE EXAMINED
BEFORE IT IS ACCEPTED BY THE SYSTEM.
VALIDATION VERIFICATION
VALIDATION
VALIDATION
Range
DEFINITION
Check
A RANGE CHECK CHECKS THAT THE VALUE OF A NUMBER
IS BETWEEN AN UPPER VALUE AND A LOWER VALUE
VALIDATION
Range
Check
VALIDATION
length
Check
DEFINITION
A LENGTH CHECK EIHTER CHECKS THAT DATA CONTAINS
- AN EXACT NUMBER OF CHARACTERS (EG. 8)
- THE DATA ENTERED IS A REASONABLE NUMBER OF CHARACTERS (EG. 8-20)
VALIDATION
length
Check
VALIDATION
TYPE
DEFINITION
Check
A TYPE CHECK CHECKS THAT THE DATA ENTERED IS OF A
GIVEN DATA TYPE, FOR EXAMPLE, THAT THE NUMBER OF
MEALS ORDERED MUST BE A NUMBER
VALIDATION
TYPE
Check
VALIDATION
Presence
check
DEFINITION
A PRESENCE CHECK CHECKS TO ENSURE THAT SOME DATA HAS BEEN ENTERED
AND THE VALUE HAS NOT BEEN LEFT BLANK.
VALIDATION
Presence
check
DEFINITION
A PRESENCE CHECK CHECKS TO ENSURE THAT SOME DATA HAS BEEN ENTERED
AND THE VALUE HAS NOT BEEN LEFT BLANK, FOR EXAMPLE, AN EMAIL ADDRESS
FOR AN ONLINE TRANSACTION MUST BE COMPLETED.
Format VALIDATION
check DEFINITION
A FORMAT CHECK CHECKS THAT THE CHARACTERS ENTERED CONFORM TO A
PRE-DEFINED PATTERN.
Check
digit CHECK DIGIT
Check digits are used to identify errors in data entry
caused by mis-typing or mis-scanning a barcode.
TEST YOUR
UNDERSTANDING
Discuss, what checks are required for the following validations
•
•
VERIFICATION(1) - DOUBLE ENTRY
VERIFICATION(2) - SCREEN/VISUAL CHECK
C7.7
TESTING
TESTING
•
•
DATA THAT CAN BE USED FOR TESTING
WE NEED TO INCORRECT
TEST THAT OUR AVERAGE
PROGRAM WILL
SCORE
REJECT THIS
DATA
NORMAL DATA THAT WOULD BE EXPECTED
EXTREME EXTREME DATA ARE THE LARGEST AND SMALLEST
DATA VALUES THAT NORMAL DATA CAN TAKE
EXAMPLE 1 EXAMPLE 2
EXAMPLE 1 EXAMPLE 2
EXAMPLE 1 EXAMPLE 2
1 9 9 9
2 9 7 7
3 9 3 3
4 9 1 1 91
0 0 100
1 19 19 19
2 27 19 27
3 31 19 31
4 31 14 14 31 14
0 0 100
1 9 9 9
2 9 7 7
3 9 3 3
4 9 1 1 91
0 0 100
1 13 13 13
2 17 13 17
3 21 13 21
4 21 11 11 21 11
Explanation
Explanation
We can fix it - quick fix
We can fix it - quick fix
Ultimate
solution
Problem statement
←
Answer
←
←
create some test
data to check the ←
correctness of an
algorithm
←
←
eg.
Test data = 12
Discount = 10%
Calculation=
←
(12 x 20) * 0.9 =
$216
←
Now, go through
←
the algorithm to
check if it works
as expected with ←
the test data.