Algorithms
Algorithms
○ Decomposition:
■ Decomposition breaks down a complex problem into
smaller parts, which can then be subdivided into even
smaller parts, that can be solved easily
■ For example, getting dressed:
» Select items to wear
» Remove any clothes being worn
» Put selected items in order.
Design:
● In this stage we use the program specifications from the analysis
stage to show how a program should be developed.
● This helps the programmer:
○ Know what is to be done
○ How each task is to be performed
○ How tasks work together
● To show how a program can be developed we use:
○ Structure diagrams
○ Flow charts
○ Pseudocode
○ Decomposition
Coding:
● In this stage the program or set of programs is developed.
● A suitable program is written then it is tested to see if it works.
○ This can be done using Iterative testing
■ Iterative testing means that modular tests are
conducted, code is amended(changed), and tests are
repeated until the module performs as required
Testing:
● In this the program code is tested with the use of test data
● This ensures that all the tasks completed work together as
specified in the program design
_________________________________________________________
___________________________
Decomposing a problem:
● A problem can be decomposed into its component parts.
● The component parts of any computer system are:
○ Inputs: Data used by the system that needs to be entered while the
system is active
○ Processes: The tasks that need to be performed using the input data
and any other previously stored data
○ Outputs: Information that needs to be displayed for the users of the
system
○ Storage: Data that needs to be stored in files on an appropriate
medium for use in the future
● For example, an alarm app can be decomposed into:
» inputs – time to set the alarm, remove a previously set
alarm time, switch an alarm off, press snooze button
» processes – continuously check if the current time matches
an alarm time that has been set, storage and removal of
alarm times, management of snooze
» outputs – continuous sound/tune (at alarm time or after
snooze time expired)
» storage – time(s) for alarms set.
Structure Diagrams:
● Used to show the top-down design in a diagrammatic form
○ It is called top to down because first we take the whole
system in consideration(top) then we break it into smaller
parts as we go down
Flowcharts:
● A flowchart shows diagrammatically the steps required to complete
a task and the order that they are to be performed.
● These steps, together with the order, are called an algorithm.
● Flowcharts are an effective way to communicate how the
algorithm that makes up a system or sub-system works.
Pseudocode:
● A simple method of showing an algorithm
● Describes what the algorithm does by using English key words that
are very similar to those used in a high level programming
language
» a non-proportional font is used throughout
» all keywords (words used to describe a specific action e.g. INPUT)
are written in capital letters
» all names given to data items and subroutines start with a capital
letter
» where conditional and loop statements are used, repeated or
selected statements are indented by two spaces.
__________________________________________________
________________________
Totalling:
● Totalling means keeping a total that values are added to.
Counting:
● Keeping a count of the number of times an action is performed is
another standard method.
● Counting is also used to count down until a certain value is
reached
Linear search:
● Used to check if a value is stored in a list
○ performed by systematically working through the items in
the list.
Bubble Search:
● Lists can be more useful if the items are sorted in a meaningful
order.
● Each element is compared with the next element and swapped if
the elements are in the wrong order, starting from the first element
and finishing with next-to-last element.
● Once it reaches the end of the list, we can be sure that the last
element is now in the correct place.
● Each element in the list is compared again apart from the last one
because we know the final element is in the correct place.
● This continues to repeat until there is only one element left to
check or no swaps are made.
_________________________________________________________
___________________________
Validation and Verification:
Validation:
● Validation is the automated checking by a program that data is
reasonable before it is accepted into a computer system.
● When data is validated by a computer system, if the data is
rejected a message should be output explaining why the data was
rejected and another opportunity given to enter the data.
○ This point is useful for board exams when solving
pseudocode or 15 marker.
○ This means that every time the user does an error we have
to ask him once again for the input and give a good output
message
● Range Check:
○ A range check checks that the value of a number is between
an upper value and a lower value.
● Length Check:
→ A Length check checks either:
○ It checks whether the data contains an exact number of
characters.
■ A password must be exactly eight characters in length
so that passwords with seven or fewer characters or
nine or more characters would be rejected.
○ It checks whether the data entered is a reasonable number
of characters.
■ A family name could be between two and thirty
characters inclusive so that names with one character
or thirty-one or more characters would be rejected.
● Type Check:
○ A type check checks that the data entered is of a given data
type.
■ number of brothers or sisters would be an integer
● Presence Check:
○ A presence check checks to ensure that some data has been
entered and the value has not been left blank.
■ email address for an online transaction must be
completed
● Format Checks:
○ Checks that the characters entered conform to a pre-defined
pattern.
● Check Digits:
○ A check digit is the final digit included in a code
○ It is calculated from all the other digits in the code
○ Check digits are used for barcodes, product codes, ISBN
and Vehicle Identification numbers
○ Check digits are used to identify errors in data entry caused
by mis-typing
Verification:
● Verification is checking that data has been accurately copied from
one source to another
● Verification methods for input data include:
» Double entry
» Screen/visual check
● Double Entry:
○ The data is entered twice
■ Sometimes by different operators
○ The computer system compares both entries and if they are
different outputs an error message requesting that the data is
entered again.
● Screen/VisualCheck:
○ It is a manual check completed by the user who is entered
the data.
○ When Data entry is complete the data is displayed on the
screen and the user is asked to confirm that it is correct
before continuing.
○ The user either checks the data on the screen against a
paper document that is being used as an input form or,
confirms whether it is correct from their own knowledge.
○ Visual check is used in the Medical field, When a teacher
takes students attendance and before submitting they are
asked.
_________________________________________________________
___________________________
Test Data:
● In order to determine whether a program is working as it should, it
needs to be tested.
● Usually before a whole system is tested each sub-system is tested
separately.
● The program can be tested using any data that is required and
seeing what the result is.
● In order to test a solution thoroughly it may need to be worked
through several times with different sets of test data.
● Abnormal data:
○ Abnormal data is called called erroneous test data
○ In this a couple scenarios are possible:
■ The data type entered is wrong thus it will be rejected
■ The data entered is not in the range thus will be
rejected
■ The data entered is not valid thus will be rejected
● Extreme Data:
○ Extreme data is the largest/smallest acceptable value
● Boundary Data:
○ Boundary data is the largest/smallest acceptable value and
the corresponding smallest/largest rejected value
_________________________________________________________
___________________________
● A trace table can be used to record the results from each step in
an algorithm.
● The manual exercise of working through an algorithm step by step
is called a dry run.
_________________________________________________________
___________________________