Topic 7 - Algorithm Design
Topic 7 - Algorithm Design
Life-cycle
Abstraction and Decomposition
When designing a computer system, abstraction is the process of getting out all the important
details. For example in the previous example about the toy company we need to know about:
• the people in the business (designers, sales people) and what they actually do.
• we may also need to know how much it costs to make a toy
• how much a toy sells for.
But do we need to know about where the staff room is located? (no we don't)
Do we need to know where employees park their cars? (no we don't)
Decomposition
Is the process of breaking down every important process in an organisation in order to create
a computer system that will consider everything the organisation does
Structure Diagram
To create a computer program we must go through different stages before we can come up with
a complete solution we call this the program life cycle
Analysis
This is the fact finding stage where everything is analysed. All the process that are performed by the
organisation. How they are performed and how everything is linked together.
Design
Elements of the new system are designed using structure charts, flow diagrams,
Coding
The actual stage of writing code. This could be a team of developers or a single developer
Testing
Once the program is complete various types of testing are performed to ensure the program functions as it
should.
TASK:
For each section of the Program Life Cycle make a list of tasks that must be carried out in each stage. What is
it? Who does the task?
Topic 7 - Algorithm Design
Sub-Systems
Sub-systems / Top-down Design
When thinking about a computer system many organisations have various departments
and process. For example a school can contain a Primary and Secondary section. In the
secondary section there are various faculties such as English and Science. A school also has
students and teachers. Teachers must get paid there is a process of paying a salary
Students must be registered which is another process. Exam results must be stored
somewhere that is another process.
Verification,Validation
WHAT WE ALL EXPECT
Verification is the process of checking that data has been copied accurately
from one medium to another such as paper to computer.There are generally
two methods:
1. Double entry
Data is entered twice and the computer checks that they match up
e.g type in email twice to confirm its correct
1. Visual Check
The user manually reads and compares the newly inputted data against the original
source to ensure they match
E.g double check we enter a bank account correctly
Validation is the process of checking user inputted data and making sure it is sensible,
reasonable, appropriate. It does not check the accuracy of data!
Range Check Checks the data falls between an acceptable upper and lower value, within a set range. e.g
age can only be between 0-120
Length Check Checks the number of characters meets expectations, e.g. an 8 character password
Presences Check Checks that the user has at least inputted something, stopping them from accidentally
entering nothing
Type Check Checks that the data entered is of an expected type, e.g. text or a number
Format Check Checks that the format of the data is correct . e.g dates dd//mm/yyyy or mm/dd/yy
Check digit An extra digit added to a number which is calculated from the other digits, this ensures the
rest of the number has been entered properly
Testing
CODE MAINTAINABILITY
1. Normal: tests with normal/expected data. e.g. a secondary school age, 11-16, normal
would be any number between 11 to 16.
2. Abnormal (erroneous): data that cannot be accepted, incorrect inputs. E.g. you type
in a string instead of an integer. E.g. two instead of 2.
3. Boundary: tests under extreme conditions. The largest/smallest value that is acceptable
and also checks what largest/smallest values must be rejected. e.g. firstname max length
of 25. Range driving license age min 17 and max 65, the boundary would be low 17, high
65.
4. Extreme: extreme data is test data at the upper or lower limits of expectations that
should be accepted by the system.
Test Plan Example
A test plan is created for every input. Testing is carried out once the program is complete.
In this test plan below we are testing the input for age. A person's age can only be between 1 and 110 years old.
Test Num Type Field / Input Purpose Test Data Expected Output Actual
Results Results
1 Normal Age To test normal age 5,22,55 Accepted -
entry
2 Abnormal Age Test to make sure 20.2, twenty Rejected Message
abnormal values for name can
age are rejected only be 15
characters
Searches, Sorting
Linear Search
Start at the beginning and go through each item till you find the
item.
2 3 11 1 9 5 8 10 6
● A very simple search compared with others
● Not as efficient, can take a very long time or a short time depending where the item
is.
Trace Table
Trace Table
1 3
2 3
number ← 3 3 1
PRINT number 4 8
FOR i from 1 to 3
5 8
number=number+5
3 2
PRINT number
4 13
5 13
PRINT “?”
3 3
The algorithm below contains 1 variable (num), 1 condition (num < 500) and 1 output
(OUTPUT num). The trace table shows how this algorithm would run if the user
entered an input of 4.
OUTPUT num 32
64
128
256
512 FALSE
512
Example 3
Although the algorithm above only contains 1 variable, trace tables can keep track of multiple
variables by using additional columns. The algorithm below is an extension of the algorithm
above, and this time the program will also keep track of how many times the while loop has
repeated. In this example the user enters an input of 16.
count ← 0 16 0 true
WHILE num < 500 THEN 32 1
num ← num * 2 64 2
count ← count + 1 128 3
END WHILE 256 4
512 5 False
OUTPUT num 512
OUTPUT count 5