You are on page 1of 19

Part 2

❑ Computer systems and sub-systems


• Top-down design
• Structure diagrams
• Flowcharts
• Pseudocode
• Library routines
• Sub-routines

❑ Algorithms
❑ Test data
❑ Validation and verification
❑ Using trace tables
❑ Identifying and correcting errors
❑ Producing algorithms
 An ALGORITHM sets out the steps to complete a given task. This is
usually shown as a flowchart or pseudocode.

 Anyone who studies the flowchart or algorithm should be able to


work out the purpose of the task.
 Algorithms should be evaluated using the following criteria:

1. Efficiency
2. Correctness
3. Appropriateness
1. Efficiency

An algorithm’s efficiency can be judged in terms of:

➢ Speed: How quick the algorithm produces the required output.


➢ Memory requirements: How many lines of code the algorithm
contains.
2. Correctness
Although an algorithm is expected to produce the correct outputs,
correctness can still be measured in terms of:

➢ Accuracy : How many decimal places produce output with greater accuracy
(e.g. more decimal places)

➢ Range: Will the algorithm work with the complete range of inputs? Or can
it only deal with positive numbers, whole numbers, numbers below 1
million, etc.

➢ Reliability: Will the algorithm always produce correct output within the
range that it is designed to work? Or are there values which it will not
accept (e.g. zero).
3. Appropriateness

Appropriateness can be measured in terms of:

➢ Length: If the problem is simple then a short algorithm


would normally be expected.

➢ Speed: if the output needs to be generated quickly, then


the algorithm must be able to generate output quick
enough.

➢ Memory requirements: An algorithm controlling a washing


machine must not require a lot of memory!
 Have a look at the flowchart and pseudocode below. What is the
purpose of the algorithm that they both represent?

 What would be output if the numbers 7 and 18 were input?


Pseudocode Flowchart
 For more complicated tasks just inspecting the flowchart or
pseudocode may not be an accurate way of determining its purpose;
a more structured thorough approach is required.

 This will require the use of test data and trace tables.

 Some tasks are required frequently and there are standard methods
of completing them, for example, taking the square root of a
number or sorting a list of names into alphabetical order.

 These standard solutions can be provided by a high-level


programming language as a standard function or procedure, for
example, mathematical functions such as max or min. Library
routines are also available for standard methods such as sorting or
searching.
 In order to determine whether a solution is working as it should, it
needs to be tested.

 Usually before a whole system is tested each sub-system is tested


separately.

 Algorithms can be tested by a person working through them using


any data that is required and seeing what the result is; computer
programs can be tested by running them on a computer using any
data that is required and seeing what result is output.

 In order to test a solution thoroughly it may need to be worked


through several times with different sets of test data.
 A SET OF TEST DATA is all the items of data required to work
through a solution.

 The set of test data used in the activity above was 7 and 18.

 Testing needs to be done to prove that the solution works correctly.


In order to do this a set of test data should be used together with
the result(s) that are expected from that data.

 The type of test data used to do this is called NORMAL DATA, this
should be used to work through the solution to find the actual
result(s) and see if these are the same as the expected result(s).
 For example, here is a set of normal test data for an algorithm to
record the percentage marks from 10 end-of-term examinations for
a student and find their average mark:

Normal test data: 50, 50, 50, 50, 50, 50 50, 50, 50, 50
Expected result: 50
 Testing also needs to be done to prove that the solution does not
give incorrect results.

 In order to do this, test data should be used that will be rejected as


the values are not suitable.

 This type of test data is called ERRONEOUS or ABNORMAL TEST


DATA; it should be rejected by the solution.
 For example erroneous/abnormal data for an algorithm to record
the percentage marks from 10 end-of-term examinations for a
student and find their average mark could be:

Erroneous/abnormal data: –12, eleven


Expected results: these values should be rejected
 When testing algorithms with numerical values, sometimes only a
given range of values should be allowed.

 For example, percentage marks should only be in the range


 0 to 100. The algorithm should be tested with EXTREME DATA,
which, in this case, are the largest and smallest marks that should
be accepted.

 Extreme data are the largest and smallest values that normal data
can take.

Extreme data: 0, 100


Expected results: these values should be accepted
 There is another type of test data called BOUNDARY DATA; this is
used to establish where the largest and smallest values occur.

 For example, for percentage marks in the range 0 to 100, the


algorithm should be tested with the following boundary data; at
each boundary two values are required, one value is accepted and
the other value is rejected.

Boundary data for 0 is –1, 0


Expected results: –1 is rejected, 0 is accepted

You might also like