Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
8 views

Algorithms

The document discusses the program development life cycle which includes analysis, design, coding, testing and maintenance stages. It also discusses decomposition, which is breaking down a complex problem into smaller parts. Standard algorithms like totalling, counting, searching and sorting are also explained. Validation is automated checking of data before it is accepted while verification ensures the program meets its specifications.

Uploaded by

nothing12334343
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Algorithms

The document discusses the program development life cycle which includes analysis, design, coding, testing and maintenance stages. It also discusses decomposition, which is breaking down a complex problem into smaller parts. Standard algorithms like totalling, counting, searching and sorting are also explained. Validation is automated checking of data before it is accepted while verification ensures the program meets its specifications.

Uploaded by

nothing12334343
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Program development life cycle:

● A program development life cycle are a series of structure steps


that are followed to produce a system
● The programming development cycle is divided into 5 stages:
○ Analysis
○ Design
○ Coding
○ Testing
○ Maintenance(Not in syllabus)
Analysis:
● In this stage : abstraction, decomposition of the problem,
identification of the problem and requirements takes place.
● The analysis stage uses abstraction and decomposition tools to
identify exactly what is required from the program so that anyone
working on the solution understands.
○ Abstraction:
■ Abstraction keeps the key elements required for the
solution to the problem and discards any unnecessary
details and information that is not required for now.

■ Once we're done with the important parts, we can look


at the other details and add them later. Abstraction
helps us take a big and complicated task and break it
into smaller, simpler steps.

○ 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

_________________________________________________________
___________________________

Computer systems, subsystems and decomposition:


● A computer system is made up sub-systems, which are made up
of further sub-systems

● A computer system is divided into sub-systems to understand how


it is built up and how it works

● Each sub-system can be developed by a programmer as a


sub-routine
● Top-down design is the decomposition of a computer system into a
set of subsystems, then breaking each sub-system down into a set
of smaller sub-systems, until each sub-system just performs a
single action.

● When larger computer systems are being developed this means


that several programmers can work independently and test
different sub-systems for the same system at the same time.
○ This reduces the development and testing time

VERY IMPORTANT POINT FOR YOUR UNDERSTANDING!!! ↓


Decomposition is the idea of breaking down a complex problem into
smaller tasks. A program can be broken down into smaller tasks by
creating sub-systems and these sub-systems can be represented using
structure diagrams, flowcharts and pseudocode.
● So basically decomposition is the idea of creating sub systems and
these sub systems can be represented using structure diagram,
flowcharts and pseudocode.

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.

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


» Structure Diagrams
» Flowcharts
» Pseudocode

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.

● Conditional statements can be used to decide which action


should be taken
● There are 2 types of conditionals:
○ If statements
○ Switch case statements

● When some actions performed as part of an algorithm need


repeating this is called iteration. Loop structures are used to
perform the iteration.
● There are 3 kinds of loop statements:
○ Count-Controlled Loops | FOR loops
■ A set number of repetitions

○ Pre-Conditioned Loops | WHILE loops


■ A repetition, where the number of repeats is not known,
that may never be completed
■ This is a pre-condition loop as the test for exiting the
loop is at the beginning of the loop.

○ Post-Conditioned Loops | REPEAT UNTIL loops


■ A repetition, where the number of repeats is not known,
that is completed at least once
■ This is a post conditioned because the test for exiting
the loop is at the end of the loop
_________________________________________________________
___________________________

Explaining the purpose of an algorithm:


● An algorithm sets out the steps to complete a given task
○ usually shown as a flowchart or pseudocode
○ So that the purpose of the task and the processes needed to
complete it are clear to those who study it.

__________________________________________________
________________________

Standard methods of solution:


» Totalling
» Counting
» Finding maximum, minimum, and average (mean) values
» Searching using a linear search
» Sorting using a bubble sort.

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

● Types of Validation checks:


○ Range Checks
○ Length Checks
○ Type Checks
○ Presence Checks
○ Format Checks
○ Check Digits

○ Different types of check may be used on the same piece of


data:
■ An examination mark could be checked for
reasonableness by using a range check, a type check
and a presence check.

● 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.

● There are 4 types of test data:


○ Normal
○ Abnormal
○ Extreme
○ Boundary
● Normal data:
○ The data lies within the required range and should be
accepted

● 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

_________________________________________________________
___________________________

Trace Tables and Dry Runs:

● 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.

_________________________________________________________
___________________________

You might also like