You are on page 1of 27

2.

1 Algorithm design and


problem-solving
Syllabus criteria
● show understanding that every computer system is made up of subsystems,
which in turn are made up of further sub-systems
● use top-down design, structure diagrams, flowcharts, pseudocode, library
routines and subroutines
Top down design
● When designing a system - dividing up of the system into sub systems and
then further dividing each sub system into more sub systems and so on till
each sub system performs only one task
● This process is called top-down design
Structure diagram
● To show a top-down design in a visual format.
● It shows the hierarchy of the systems and the different levels.

Video
Syllabus criteria
● flowcharts, pseudocode, library routines and subroutines
● work out the purpose of a given algorithm ( only practice questions)
● suggest and apply suitable test data
pseudocode
● Simple way of
representing an
algorithm using
english-like words
● Look at the
pseudocode
structure -
document posted on
google classroom
flowcharts
● Graphically illustrate an
algorithm.

Video
Library routines
● A library routine is a set of programming instructions for a given task that is already
available for use.
● It is pre-tested and usually performs a task that is frequently required.
● Already present in the software .
● Saves a lot of time for the programmer

E.g. in Python Pygame or Pygame Zero are libraries that allow programmers to write games
in Python. They provide easy to use functions and structures to create a Window, Sprites
and carry out common tasks like detecting collision and drawing the screen.

Video
Subroutines ( Procedures and Functions)
● A Subroutine is a set of programming instructions for a given task (sub system) - called from the main
program
● It could be a task that is repeated a lot
● It is created by the user to divide the system into smaller sub-systems and it saves time and improves
efficiency.
● Subroutines can be a : 'procedures' or 'functions'

Video
Procedures and Functions
Return Value - An answer/ result returned to the main program

Procedure: A subroutine that does not return a value to the main program

Function: A subroutine that returns a value to the main program

What is the difference between library routines and subroutines?

Video
Test data for testing code
● In order to determine whether a solution is working as it should, it needs to be
tested.
● We enter different types of data into the algorithm to see that it is error free.

Types of Test Data

Normal data - data that should be accepted as input to the algorithm and cause no errors

Extreme/Boundary - largest and smallest data that can be accepted by the system ; at each
boundary two values are required, one value is accepted and the other value is rejected.

Erroneous/ Abnormal data - data that is not suitable and should be rejected as input to the
system
Video
Syllabus criteria
• understand the need for validation and verification checks to be made on
input data

• use trace tables to find the value of variables at each step in an algorithm

• identify errors in given algorithms and suggest ways of removing these


errors ( Only practice problems)

• comment on the effectiveness of a given solution


Validation
Validation - Validation is the automated checking by a program that data is reasonable before it is
accepted into a computer system.

Video
Verification
Verification - checking that data has been accurately copied onto the computer or transferred from one
part of a computer system to another.

Video
Drawing a Trace Table
INPUT x Trace the opposite algorithm with the following inputs:
5,2
INPUT y

Sum = 0

FOR i = 0 to y x y i Sum OUTPUT

5 2 0 5
Sum = Sum + x
1 10
NEXT i
2 15

OUTPUT i , Sum 2 15

Video
Trace tables
● A TRACE TABLE can be used to record the results from each step in an
algorithm;
● it is used to record the value of an item (variable ) each time that it changes.
● It can help detect errors in the algorithm
Effectiveness of a solution
New Curriculum
Add on content
Understand the program development life cycle
The various stages are:

1) Analysis
● to find out what is required before solving the problem
● Uses abstraction tools and decomposition tools to find the requirements
● Abstraction - keeping the key details and discarding the unnecessary details
● Decomposition - breaking problem in into smaller parts

2) Design
● to create a blueprint / structure of the solution to be created
● Methods used - structure diagrams, flowcharts and pseudocode

3) Coding
● The various modules of a program are written using a programming language
● The modules are tested and then changes are made and then tested again - till module performs
perfectly . This is called iterative testing
Understand the program development life cycle
The various stages are:

4) Testing
● The complete program is run using various sets of test data to see if all parts of the program are
working.

Video
Decomposing a problem
● Any problem on a computer system can be decomposed in the following four parts:
○ Inputs - data that is entered into the system
○ Processes - tasks done by the system using the input data and any other stored data
○ Outputs - information that needs to be displayed
○ Storage - data that needs to be stored in the computer memory for future use

Video
Methods used to design and construct a solution to a problem

● Structure diagrams ( refer to slide 4)


● Flowcharts ( refer to slide 7)
● Pseudocode ( refer to slide 6)

Examples:

Video
Standard programs :
1. Totaling

2. Counting
Standard programs :
3. Maximum, minimum - there are 2 methods

Method 1: When largest and smallest values are known


Standard programs :
Method 2: When largest and smallest values are not known

( take the first value as the maximum and minimum values )


Standard programs :
4. Linear Search - search process to find if an element exists in a list by going through each element
in the list one by one

Video
Standard programs :
5. Bubble sort - sorting a list in ascending or descending order

- Each element in the list is compared with the element next to it.
- If in incorrect order, the positions are swapped
- Go though the entire list again and repeat this process till there are no more swaps.

Video

You might also like