KEMBAR78
Notes For Chapter 7 | PDF | Software Development | Computer Engineering
0% found this document useful (0 votes)
6 views16 pages

Notes For Chapter 7

Uploaded by

Hasin Eshrak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views16 pages

Notes For Chapter 7

Uploaded by

Hasin Eshrak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

CHAPTER 7: ALGORITHM DESIGN & PROBLEM-SOLVING

7.1: Understand the program development life cycle, limited to: analysis, design, coding and
testing

PROGRAM DEVELOPMENT LIFE CYCLE

When a person, or organization, creates a new computer program they will use a structured,
organized plan of how to create the program. This is called the program development life cycle.

Program development life cycle consists of mainly 4 stages:

1. ANALYSIS:

➢ Identification of the problem and requirements.


➢ Decomposition: Breaking down a complex problem into smaller, easier-to-solve
parts.
➢ Abstraction: Removal of unnecessary details and identification of the key
elements of the problem.

2. DESIGN:

➢ Pseudocodes
➢ Flowcharts
➢ Structure diagrams
➢ How the problem is to be solved, what tasks are required for it and how they work
with each other, and the order of those tasks is found out in this stage

3. CODING:

➢ Program code is written using a programming language


➢ Iterative testing of the separate modules of the program is carried out, ensuring they
work as they are meant to
➢ Most amendments to the code are carried out in this stage

4. TESTING:

➢ The completed program is tested with test data to spot any errors
➢ When you have finished your program, you need to carry out testing to make sure
it fully works, does not crash and meets all requirements
7.2.1: Understand that every computer system is made up of sub-systems, which are made
up of further sub-systems

COMPUTER SYSTEMS

➢ Made up of subsystems, which are made up of further sub-systems, and so on


➢ Made up of software, data, hardware, communications, and people
➢ The division can show using top-down design.

TOP-DOWN DESIGN: It 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

EXAMPLE OF A TOP-DOWN DESIGN (↓)


7.2.2: Understand how a problem can be decomposed into its component parts

A problem can be decomposed by the identification of its component parts

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/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
7.2.3: Use different methods to design and construct a solution to a problem

Solutions to problems need to be designed using thorough methods, to ensure that their purpose is
clearly understood

The 3 main ways to design and construct a solution to a problem are:

1. Structure Diagrams
2. Flowcharts &
3. Pseudocodes

1. STRUCTURE DIAGRAMS

A structure diagram is developed by decomposing a program into its subprograms. The diagram
has the name of the program at the top, and below this its subprograms. Each subprogram can be
split down further as well if required.

EXAMPLE # 1 OF A STRUCTURE DIAGRAM (↓)

➢ INPUT: This component gathers the necessary data from the user, which includes the two
numbers to be operated on and the mathematical symbol representing the desired operation.

➢ PROCESS: This is the core of the calculator where the actual calculation takes place. It
receives the input data, performs the specified operation, and stores the intermediate results
before producing the final answer.

➢ OUTPUT: This component displays the final result of the calculation to the user.
EXAMPLE # 2 OF A STRUCTURE DIAGRAM (↓)

The following is a structure diagram of a part of a satellite navigation system that:

➢ Allow the user to enter details for a new destination or select a previously saved destination
➢ Displays directions in the form of a visual map or as a list

2. FLOWCHARTS

A flow chart 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.
EXAMPLE # 1 OF A FLOWCHART: A CALCULATOR (↓)
EXAMPLE # 2 OF A FLOWCHART: A PASSWORD VALIDATION PROGRAM (↓)
3. PSEUDOCODES

Pseudo-code is a simplified form of programming code that uses common programming


terminologies but does not use the strict syntax rules of a programming language.

Pseudocode refers to any code that is not written on a computer to run. There is no one set
pseudocode, because if there was then this would be code with a specific language. Instead, it’s a
term for any readable code-like statements that all programmers will understand. This means that
it uses keywords, and constructs such as IF statements, WHILE loops, etc. These constructions
occur in almost all languages, so any programmer would be expected to read them and translate
them into the actual programming language they are using.

EXAMPLE # 1 OF A PSEUDOCODE (↓)

INPUT Number
IF Number < 10 THEN
OUTPUT "too small"
ELSE
OUTPUT "valid"
ENDIF

This uses the keywords INPUT, IF and OUTPUT. These can then be translated into whatever
language the programmer is using.

There are many different valid pseudocode formats. Some will always use capital for the
commands, e.g. INPUT, IF, FOR. Some will use ← instead of an = for assignment. If you write
your pseudocode in almost perfect ‘code’, i.e. you actually write Python code, because it is not to
be run, and you can have all sorts of syntax errors it is still pseudocode. What is important is that
the program is split into steps that can be easily converted into a real program.
7.3: Explain the purpose of a given algorithm

WHAT IS AN ALGORITHM?

An algorithm is a well-defined, step-by-step procedure or set of rules designed to solve a specific


problem or accomplish a particular task. Think of it as a recipe for problem-solving, providing a
structured approach to achieve a desired outcome.

WHAT IS THE PURPOSE OF AN ALGORITHM?

An algorithm sets out the steps to complete a given task. This is 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.

TYPES OF ALGORITHMS THAT WE ARE GOING TO LEARN!

1. Searching Algorithm (Linear Search): A search algorithm checks a set of data to identify
whether a specific value exists in the data, or not. One example of this is a linear search.

2. Sorting Algorithm (Bubble Sort): A sorting algorithm takes a set of data and rearranges
it to be in a specific order, e.g. in ascending alphabetical order. One example of this is a
bubble sort.

OTHER STANDARD METHODS OF SOLVING A PROBLEM

➢ Totaling
➢ Counting
➢ Finding Maximum, Minimum & Average Values
7.4: Understand standard methods of solution

1. LINEAR SEARCH

➢ Used to search for a certain value/variable, etc.


➢ Checks all the elements of the data structure being searched

EXAMPLE # 1 OF A LINEAR SEARCH (↓)

OUTPUT "Please enter the name to find”


INPUT Name
Found ← FALSE
Counter ← 1
REPEAT
IF Name = StudentName[Counter]
THEN
Found ← TRUE
ELSE
Counter ← Counter + 1
ENDIF
UNTIL Found OR Counter > ClassSize
IF Found
THEN
OUTPUT Name, “ found at position ”, Counter, “ in the list ”
ELSE
OUTPUT “ Name not found ”
ENDIF

/ / pseudocode to find the name stored


2. BUBBLE SORT

➢ Used to arrange elements in a data structure in ascending or descending order


➢ Always has a variable to temporarily store data in between swaps
➢ Compare each element with the next consecutive one, and swap if needed

EXAMPLE # 1 OF A BUBBLE SORT (↓)

DECLARE StudentAge : ARRAY [1:10] OF INTEGER


Last ← 10
FOR Counter ← 1 TO 10
OUTPUT "Enter student's age"
INPUT Age
StudentAge[Counter] Age
NEXT counter
REPEAT
Swap ← FALSE
FOR counter 1 TO Last - 1
IF StudentAge[Counter] > StudentAge[Counter + I]
THEN
Temp StudentAge[Counter]
StudentAge[Counter] StudentAge[Counter +1]
StudentAge[Counter + 1] Temp
ENDIF
NEXT counter
Last ← Last – 1
UNTIL (NOT swap) OR Last = 1

/ /pseudocode to arrange the students’ ages in StudentAge in ascending order

3. TOTALING

➢ The process of keeping a running total of values in a program

EXAMPLE # 1 OF TOTALING (↓)

TotalCost ← TotalCost + FurnitureCost


TotalBaskets ← TotalBaskets + BananaBaskets
4. COUNTING

➢ Number of times an action is performed in a program

EXAMPLE # 1 OF COUNTING (↓)

Counter ← Counter + 1
NumberInStock ← NumberInStock – 1

5. MAXIMUM, MINIMUM, & AVERAGE

➢ Maximum value is found out by comparing all the values input in the program and
identifying the largest one
➢ Minimum value is found by comparing all the values input in a program and identifying
the smallest one
➢ Average (mean) value is found by totaling all the values, and dividing that total with the
number of values added
7.5.1: Understand the need for validation checks to be made on input data and the different types
of validation checks

VALIDATION: Checking that the data entered is reasonable/sensible There are several kinds of
validation checks, the table below represents the types of validation checks.

TYPE OF
# VALIDATION FUNCTION (check if:) EXAMPLE
CHECK

1 Range The data is within a set range REPEAT


OUTPUT “Enter your marks”
INPUT Marks
UNTIL Marks > -1 AND Marks < 101

2 Length The data is either an exact number of REPEAT


characters, or within a range of OUTPUT “Enter your password”
number of characters INPUT Password
UNTIL LENGTH(Password) >= 8

3 Type The data conforms to the required REPEAT


data type OUTPUT “Enter your age”
INPUT Age
UNTIL DIV(Age, 1) = Age

// This may not be needed as the data type of Age can


be declared INTEGER

4 Presence Data has been entered REPEAT


OUTPUT “Enter your name”
INPUT Name
UNTIL Name < > “ ”

5 Format The data conforms to a specific REPEAT


format OUTPUT “Enter your device code”
INPUT DeviceCode
UNTIL SUBSTRING(DeviceCode, 1, 3) = “XYX”
AND LENGTH(DeviceCode) = 6
6 Check Digit The final digit entered in a code is REPEAT
correct OUTPUT “Enter your device number”
INPUT DeviceNumber
OUTPUT “Enter your device code”
INPUT DeviceCode
UNTIL SUBSTRING(DeviceCode, 6, 1) = (2 *
DeviceNumber)

// DeviceCode contains a six-digit number


7.5.2: Understand the need for verification checks to be made on input data and the different types
of verification check

VERIFICATION: The checking if data has been accurately copied from one medium to another.
It does not check for any ranges, boundaries, etc. It only checks if the data is identical to the
original source.

There are several kinds of verification checks, the table below represents the types of verification
checks.

TYPE OF
# VERIFICATION FUNCTION EXAMPLE
CHECK

1 Double Entry Requires data to be entered twice so REPEAT


that both entries can be compared OUTPUT “Enter your password”
to confirm that they are the same. INPUT Password1
OUTPUT “Enter your password again”
INPUT Password2
UNTIL Password1 = Password2

2 Visual Manual check done by the user to Data is displayed on the screen and the user is asked
see if the data entered is correct to confirm their accuracy
7.6: Suggest and apply suitable test data

TEST DATA: Data that has been specifically identified for testing a program. It is used to work
through a program to find any errors and ensure that it is working like it is meant to.

TYPES OF TEST DATA:

1. Normal Test Data: Data that will be accepted by the program

2. Abnormal/Erroneous Test Data: Data that will be rejected by the program

3. Extreme Data: The largest and smallest accepted values

4. Boundary Test Data: The largest/smallest accepted values, and their corresponding
largest/smallest rejected values

7.7: Complete a trace table to document a dry run of an algorithm

--- HANDS ON LEARNING ---

7.8: Identify errors in given algorithms and suggest ways of correcting these errors

--- HANDS ON LEARNING ---

7.9: Write and amend algorithms for given problems or scenarios, using: pseudocode, program
code and flowcharts

--- HANDS ON LEARNING ---

You might also like