Unit7. Algorithm Design and Problem Solving Revision notes IXC
Unit7. Algorithm Design and Problem Solving Revision notes IXC
• Analysis
• Design
• Coding
• Testing
• Maintenance
Analysis
• Before solving a problem, it is essential to define and document the problem clearly,
known as the "requirements specification" for the program.
• The analysis stage involves using tools like abstraction and decomposition to identify the
specific requirements for the program.
• Abstraction focuses on the essential elements needed for the solution while eliminating
unnecessary details and information.
• Daily tasks can be decomposed into constituent parts for easier understanding and
solving.
Design
• The program specification derived from the analysis stage is used as a guide for program
development.
• During the design stage, the programmer should clearly understand the tasks to be
completed, the methods for performing each task, and how the tasks will work together.
• Iterative testing is performed, which involves conducting modular tests, making code
amendments if necessary, and repeating tests until the module meets the required
functionality.
Testing
• The completed program or set of programs is executed multiple times using various test
data sets.
• This testing process ensures that all the tasks within the program work together as
specified in the program design.
• Running the program with different test data can identify and address potential issues
and errors.
• The testing phase aims to verify the overall functionality and performance of the
program by evaluating its behavior with various inputs.
Computer systems
➜ Top-down design is the breaking down of a system into smaller sub-systems, and those
subsystems into further sub-systems, until each sub-system performs a single action.
Decomposition of a problem
➜ These include the inputs, processes, outputs, and storage required for the solution
-Inputs
➜ The data that is to be entered into the system for processing while it is active
- Processes
➜ The tasks that need to be performed on the data input and and/or the data previously
stored in the system
– Outputs
➜ The data that needs to be displayed or printed for the users of the system
➜ The results of the various processes carried out in the system using the input data and/or
the previously stored data
– Storage
➜ Data that needs to be stored in an appropriate medium in the system so that they can be
used throughout the program as needed
Structure Diagrams
• Every computer system is made up of sub-systems, which are in turn made up of further
sub-systems.
• Structure Diagrams – The breaking down of a computer system into sub-systems, then
breaking each sub-system into smaller sub-systems until each one only performs a single
action. A structure diagram diagrammatically represents a top-down design. Example
below.
• Algorithm: These steps, together with the order, are called an algorithm
An example of a flowchart is given below from a past paper question in which all of the
functions of a flowchart are shown:
This flowchart’s task is to check if a rider’s height is more the requirement (1.2) in this case. It
then counts until the accepted riders are 8. After they are 8, it outputs the number of rejected
riders and tells the rest that they are ready to go!
Pseudocode
o Variable – Store of data which changes during execution of the program (due to
user input)
o Constant – Store of data that remains the same during the execution of the
program
INPUT Name
// Alternatively //
READ Name
Conditional Statements:
IF…THEN…ELSE…ENDIF
CASE…OF…OTHERWISE…ENDCASE – Multiple conditions and corresponding consequences \n
Loop Structures:
REPEAT… UNTIL – Will run at least once till condition is satisfied; Verification is done after
running code
WHILE…DO…ENDWHILE – May not ever run; Verification is done before running code
Note: When using conditions in these loop structures and conditional statement, it has to be
kept in mind that it can be done in two ways.
1. use of a Boolean variable that can have the value TRUE or FALSE
THEN
OUTCOME
ELSE
OUTCOME
ENDIF
THEN
OUTCOME
ELSE
OUTCOME
ENDIF
Total ← 0
NEXT Counter
Counting: Keeping a count of the number of times an action is performed is another standard
method.
PassCount ← 0
INPUT Value
THEN
PassCount ← PassCount + 1
ENDIF
NEXT Counter
Maximum, minimum and average : Finding the largest and smallest values in a list are two
standard methods that are frequently found in algorithms
THEN
MaximumValue ← Array[Counter]
ENDIF
THEN
MinimumValue ← Array[Counter]
ENDIF
NEXT Counter
// Average//
Total ← 0
NEXT Counter
Test Data
• Test data refers to input values used to evaluate and assess the functionality and
performance of a computer program or system.
• It helps identify errors and assess how the program handles different scenarios
Normal Data
• Normal data is the test data which accepts values in acceptable range of values of the
program
• Normal data should be used to work through the solution to find the actual result(s) and
see if they are the same as the expected result(s)
• e.g. in a program where only whole number values ranging from 0 to 100 (inclusive) are
accepted, normal test data will be : 23, 54, 64 , 2 and 100
Abnormal Data
• Test data that would be rejected by the solution as not suitable, if the solution is working
properly is called abnormal test data / erroneous test data.
• e.g. in a program where only whole number values ranging from 0 to 100 (inclusive) are
accepted, abnormal data will be: -1, 151, 200, 67.2, “Sixty-Two” and -520
Extreme Data
• Extreme data are the largest and smallest values that normal data can take
• e.g. in a program where only whole number values ranging from 0 to 100 (inclusive) are
accepted, extreme data will be: 0 and 100
Boundary Data
• This is used to establish where the largest and smallest values occur
• At each boundary two values are required: one value is accepted and the other value is
rejected.
• e.g. in a program where only whole number values ranging from 0 to 100 (inclusive) are
accepted, one example of boundary data will be: 100 and 101. 100 will be accepted and
101 will not be accepted
Trace Table
• A trace table is set up with a column for each variable and a column for any output e.g.
Test data is employed to execute a dry run of the flowchart and document the outcomes in a
trace table. During the dry run:
• Whenever a variable's value changes, the new value is recorded in the respective
column of the trace table.
Q: The flowchart below inputs the height of children who want to ride on a rollercoaster.
Children under 1.2 metres are rejected. The ride starts when eight children have been accepted.
Complete the trace table for the input data: 1.4, 1.3, 1.1, 1.3, 1.0, 1.5, 1.2, 1.3, 1.4, 1.3, 0.9, 1.5,
1.6, 1.0
0 0
1 1.4
2 1.3
1 1.1
3 1.3
2 1.0
Riders Reject Height OUTPUT
4 1.5
3 1.2
5 1.3
6 1.4
7 1.3
4 0.9
8 1.5 Ready to
go 4
Identifying errors:
• Trace tables can be used to trace errors in a program. For example, if the requirement
for the previous question would be to accept riders that are of height 1.2 too, rather
than rejecting them, then the error would have been caught in the trace table as when
1.2 is entered, it would increment rejected which it shouldn’t in our example
The ability to write an algorithm is very important for this syllabus and paper. Some key
steps/points to be known in-order to write the perfect algorithm are as follows:
1. Make sure that the problem is clearly understood which includes knowing the purpose
of the algorithm and the tasks to be completed by the algorithm.
2. Break the problem into smaller problems (e.g. in a program which outputs average
values, divide the problem into multiple ones i.e. how to count the number of iterations
and how to count the total of all values)
3. Identify the data that is needed to be saved into variables/constants/arrays and what
datatype it is, and declare all the variables/constants/arrays accordingly, with
meaningfull names
4. Decide on how you are going to construct your algorithm, either using a flowchart or
pseudocode. If you are told how to construct your algorithm, then follow the guidance.
5. Construct your algorithm, making sure that it can be easily read and understood by
someone else. Take particular care with syntax e.g. when conditions are used for loops
and selection.
6. Use several sets of test data (Normal, Abnormal and Boundary) to dry run your
algorithm and check if the expected results are achieved (a trace table can be used for
this purpose) . If error is found, find the point of error in the trace table and fix it in the
code.
Note: The algorithms that you have looked at so far in these notes were not designed with
readability in mind because you needed to work out what the problem being solved was.
To ensure the acceptance of reasonable and accurate data inputs, computer systems must
thoroughly examine each data item before accepting it, and this is where Validation and
Verification come into play!
Validation
Range check
A range check verifies that a numerical value falls within specified upper and lower limits.
REPEAT
INPUT Value
THEN
OUTPUT "The student's mark should be in the range", MinimumValue ," to ", MaximumValue
ENDIF
This can either ensure that data consists of a precise number of characters.
OUTPUT "Please enter your value of ", Limit , " characters "
REPEAT
INPUT Value
THEN
OUTPUT "Your value must be exactly" , Limit ," characters, please re-enter "
ENDIF
It can also check if the data entered is a reasonable number of characters or not
REPEAT
INPUT Value
THEN
ENDIF
Type check
A type check verifies that the entered data corresponds to a specific data type.
REPEAT
INPUT Value
THEN
OUTPUT "This must be a whole number, please re-enter"
ENDIF
Presence check
A presence check checks to ensure that some data has been entered and the value has not been
left blank
REPEAT
INPUT Value
IF Value = ""
THEN
ENDIF
Format Check
A format check checks that the characters entered conform to a pre-defined pattern.
Check Digit
• A check digit is the final digit included in a code; it is calculated from all the other digits.
• Check digits are used for barcodes, product codes, International Standard Book Numbers
(ISBN), and Vehicle Identification Numbers (VIN).
Verification
Verification is checking that data has been accurately copied from one source to another
There are 2 methods to verify data during entry ( there are other methods during data transfer,
but they are in paper 1)
1. Double Entry
2. Screen/Visual check
• A screen/visual check involves the user manually reviewing the entered data.
• After data entry, the system displays the data on the screen and prompts the user to
confirm its accuracy before proceeding.
• The user can compare the displayed data against a paper document used as an input
form or rely on their own knowledge to verify correctness.