Algorithm Design
Algorithm Design
• Analysis
• Design
• Coding
• Tes�ng
• Maintenance
Analysis
• Before solving a problem, it is essen�al to define and document the problem clearly, known
as the "requirements specifica�on" for the program.
• The analysis stage involves using tools like abstrac�on and decomposi�on to iden�fy the
specific requirements for the program.
• Abstrac�on focuses on the essen�al elements needed for the solu�on while elimina�ng
unnecessary details and informa�on.
• Decomposi�on involves breaking down complex problems into smaller, more manageable
parts that can be solved individually.
• Daily tasks can be decomposed into cons�tuent parts for easier understanding and solving.
Design
• The program specifica�on 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.
• Documenta�on methods such as structure charts, flowcharts, and pseudocode can be used
to document the program's design formally.
• Itera�ve tes�ng is performed, which involves conduc�ng modular tests, making code
amendments if necessary, and repea�ng tests un�l the module meets the required
func�onality.
Tes�ng
• The completed program or set of programs is executed mul�ple �mes using various test data
sets.
• This tes�ng 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 iden�fy and address poten�al issues and
errors.
• The tes�ng phase aims to verify the overall func�onality and performance of the program by
evalua�ng its behaviour with various inputs.
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 un�l each one only performs a single
ac�on. A structure diagram diagramma�cally represents a top-down design. Example below.
• Flowcharts: A flowchart shows diagramma�cally the steps required to complete a task and
the order that they are to be performed
• Algorithm: These steps, together with the order, are called an algorithm
An example of a flowchart is given below from a past paper ques�on in which all of the func�ons 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 un�l the accepted riders are 8. A�er 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 execu�on of the program (due to user
input)
o Constant – Store of data that remains the same during the execu�on of the program
• Input & Output (READ & PRINT) – Used to receive and display data to the user
respec�vely. (It is recommended to use input and output commands)
INPUT Name
// Alterna�vely //
READ Name
• Array: Array is similar to variable but it can store mul�ple values of same datatype under
single name
• Condi�onal Statements:
IF…THEN…ELSE…ENDIF
CASE…OF…OTHERWISE…ENDCASE – Mul�ple condi�ons and corresponding consequences \n
• Loop Structures:
REPEAT… UNTIL – Will run at least once �ll condi�on is sa�sfied; Verifica�on is done a�er running
code
WHILE…DO…ENDWHILE – May not ever run; Verifica�on is done before running code
Note: When using condi�ons in these loop structures and condi�onal 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
2. comparisons made by using coparison operators, where comparisons are made from
le� to right
IF [BOOLEAN VARIABLE]
THEN
OUTCOME
ELSE
OUTCOME
ENDIF
THEN
OUTCOME
ELSE
OUTCOME
ENDIF