AS Computer Science 9618 P2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 34

CH9 - ALGORITHM DESIGN AND PROBLEM SOLVING

COMPUTATIONAL THINKING SKILLS

ABSTRACTION
= the process of extracting information that is essential, while ignoring what is not relevant, for
the provision of a solution
- Encourages the development of simplified models that are suited to a specific purpose
by eliminating any unnecessary characteristics from that model
- Ex: Map, Calendar, Timetables
- Maps to show what is required for a specific purpose: road map
- Only showing essential details needed
Benefits:
+ the time required to develop the program is reduced so the program can be delivered to
the customer more quickly
+ Program is smaller in size so takes up less space in memory and download times are
shortened
+ Customers satisfaction is greater as their requirements are met without any extraneous
features

HOW
- identify the purpose of the model of the situation that is to be built
- Once identified, sources of information need to be identified (observations, view of
potential users, evidence of existing models)
- Use information gathered from appropriate sources to identify what details need to be
included in the model (details to be presented, need to be removed, etc)

DECOMPOSITION
= the process of breaking a complex problem into smaller parts until each part is easy to
examine and understand, hence a solution can be developed for it

Pattern Recognition
= used to identify those parts that
are similar and could use the same
solution
- led to the development of
reusable program code in the form
of subroutines, procedures, and
functions
- When write a comp program,
each final part is defined as a
separate program module that can
be written and tested a separate
procedure or function
ALGORITHMS
= an ordered set of steps to be followed in the completion of a task

METHODS
1. Structured English
- method of showing the logical steps on the algorithm using an agreed subset of
straightforward English words for commands and mathematical operations
2. FlowChart
- a diagrammatic representation of an algorithm
- To show a structure of an algorithm
3. Pseudocode
- a method of showing the detailed logical steps in an algorithm, using keywords, identifier
with meaningful names, and mathematical operators
- Not follow the syntax of a specific programming language, but provide sufficient detail to
allow a program to be written in a high level language
STEPWISE REFINEMENT
= the practice of subdividing each part of a larger problem into a series of smaller parts, and so
on, as required
CH10 - DATA TYPES AND STRUCTURES

DATA TYPES
= a classification of different types of data
- Determine properties like what operations can be conducted on the data and how the
data will be stored

RECORD
= a composite data type comprising several related items that may be of different data types

*Composite Data Type = a data type constructed using several of the basic data types available
in a particular programming language
- must be defined before it can be used
- Any data type not provided by a programming language must be defined before it can be
used
In records there is an IDENTIFIER
- Identifier = a unique name applied on an item of data

ARRAYS
= a data structure containing several elements of the same data types
- Index = the position of each element in an array
- Lower Bound = the index of the first element in an array
- Usually 0 or 1
- Upper Bound = the Index of the last element in an array
- Why?
- Used to store multiple data types in a uniformly accessible manner
- All data types use the same identifier and each data item can be accessed
sepratly by the use of an index
- Hence, list of items can be stored, searched, and put into an order

1D ARRAYS
= a list
2D ARRAYS
= a table, with rows and columns
LINEAR SEARCH
= a method of searching in which each element of an array is checked in order
- uses variables Upperbound and Lowerbound so that the algorithm is easier to adapt for
different lengths of list
- REPEAT UNTIL loop make use of 2 conditions, so that the algorithm is more efficient,
termination as soon as the item is found in the list
IDENTIFIER TABLE
- good practice to provide an identifier table to keep track of and explain the use of each
identifier in an algorithm
- Allows the programmer to keep track of the identifiers used and provides a useful
summary of identifiers and their uses if the algorithm requires modification at a later date

BUBBLE SORT
= a method os sorting data in an array into alphabetical or numerical order by comparing
adjacent items and swapping them if they are in the wrong order
- start from the lower bound and finishing with the element next to the upper bound
- The element at the upper bound is now in the correct position
- This comparison is repeated with 1 less element in the list, until there is only 1 element
left or no swaps are made
FILE
= a collection of data stored by a computer program to be used again

1. OPEN FILE

2. EOF

3. CLOSE FILE
ABSTRACT DATA TYPE (ADT)
= a collection of data and a set of operations on that list

STACKS QUEUES LINKED LISTS

= a list containing several = a list containing several = a list containing several items
items operating on the items operating on the first in, in which each item in the list
last in, first out (LIFO) first out (FIFO) principle points to the next item in the list
principle

➔ uses two pointers ➔ uses two pointers ➔ Uses a start pointer that
➔ A base pointer ➔ A front pointer points points to the first item in
points to the first to the first item in the the linked list
item in the stack
queue and a rear ➔ Every item in a linked list
and a top pointer
points to the last pointer points to the is stored together with a
item in the stack last item in the queue pointer to the next item
➔ When they are ➔ When there are equal, ➔ This is called a node
equal there is only there is only one item ➔ The last item in a linked
one item in the in the queue list has a null pointer
stack

— queue has a finite size, — use two 1D array, one for


so can be come full linked list and one for the
— As items are removed pointers to the next item
from the front and in the list
added to the end, — link list can become full
position of the queue — items can be removed
in the array wont from any position in the
change linked list, the empty
— Therefore queue should position in the array must
be managed as a be managed as an
circular queue to avoid empty linked list (heap)
moving the position of
the items in the array
every time an item is
removed
— Everytime a queue is
updated (removed or
added), front pointer is
updated to the first
element (lowerbound)
and rear pointer to the
last element
(upperbound)

● items can be ● Items can be added to ● In a linked list, a new


added to the stack the queue (enqueue) item is always added to
(push) and and removed from the the start of the list
removed from the queue (de queue)
stack (pop) ● The first item added to
● The first item a queue is the first
added to a stack item to be removed
is the last item to from the queue
be removed from
the stack

- Memory - Management of files - Using arrays to


Management sent to a printer implement a stack
- Expression - Buffers used with - Using arrays to
evaluation keyboards implement a queue
- Backtracking in - Scheduling - Using arrays to
recursion implement a binary tree
STACK
QUEUE

LINKED LIST
CH12 - SOFTWARE DEVELOPMENT

PROGRAM DEVELOPMENT LIFECYCLE


PURPOSE OF A PROGRAM DEVELOPMENT LIFECYCLE
- To develop a successful program or suite of programs that is going to be used by others
to perform a specific task

STAGES

1. Analysis
- A process of investigation, leading to the specification of what a program is required to
do
2. Design
- Uses the program specification from the analysis stage to show how the program should
be developed
3. Coding
- The writing of the program or suite of programs
4. Testing
- The testing of the program to make sure that it works under all conditions
5. Maintenance
- The process of making sure that the program continues to work during use
WATERFALL MODEL
= A linear sequential program development cycle, in which each stage is completed before the
next is begun

PRINCIPLE ● linear, as each stage is completed before the next is begun


● Well documented as full documentaries is completed at every
stage
● Low customer involvement, only involved at the very start and end
of the process

BENEFITS + easy to manage, understand and use


+ Stages do not overlap and are completed one at a time
+ Each stage has specific deliverables
+ Work well for smaller programs when requirements are known and
understood

DRAWBACKS - difficult to change the requirements at a later stage


- Not suitable for programs where the requirements could be subject
to change
- Working program is produced late in the life cycle
- Not suitable for long, complex projects
ITERATIVE MODEL
= a type of program development cycle in which a simple subset of the requirements is
developed, then expanded or enhanced, with the development cycle being repeated until the full
system is deployed

PRINCIPLE ● Incremental development as the program development life cycle


is repeated
● Working programs are produced for parts of the system at every
iteration
● High customer involvement, as part of the system can be shown
to the customer after every iteration

BENEFITS + some working programs developed quickly at an early stage in the


lifecycle
+ Easier to test and debug smaller programs
+ More flexible as easier to alter requirements
+ Customers involved at each iteration therefore no surprises when
final system delivered

DRAWBACKS - whole system needs to be defined at start, so it can be broken


down into pieces to be developed at each iteration
- Need good planning overall and for every stage
- Not suitable for short simple projects
RAPID APPLICATION DEVELOPMENT (RAD)
= a type of program development cycle in which different parts of the requirement are developed
in parallel, using prototyping to provide early user involvement in testing

PRINCIPLE ● Minimal planning


● Reuses previously written code where possible, make use of
automated code generation where possible
● High customer involvement, as customers can use the
prototypes during development

BENEFITS + reduced overall development time


+ Rapid frequent customer feedback informs the development
+ Very flexible as requirements evolve from feedback during
development
+ As parts of the system are developed side by side,
modification is easier because arch part must work
independently

DRAWBACKS - system under development needs to be modular


- Needs strong teams of skilled developers
- Not suitable for short simple projects
PROGRAM DESIGN

STRUCTURE CHART
= a modeling tool used to decompose a problem into a set of sub-tasks
- shows the hierarchy or structure of the different modules and how they connect and
interact with each other
- Show selection
- Show repetition

STATE TRANSITION DIAGRAMS


= A diagram showing the behavior of an FSM

CAN BE CONSTRUCTED BY:


1. States are represented as nodes (circles)
2. Transitiotion are represented as interconnecting arrows
3. Events are represented as label on the arrow
4. Conditions can be specified in square brackets after the event label
5. The initial state is indicated by an arrow with a black dot
6. A stopped state is indicated by a double circle
*Finite State Machine
= a mathematical model of a machine that can be in one of a fixed set of possible states
- 1 state is changed to another by an external input (TRANSITION)

PROGRAM TESTING AND MAINTENANCE

WAYS OF AVOIDING AND EXPOSING FAULTS IN PROGRAMS


- Faults in an executable program = faults in design of the program
- Avoid?
- provision of a comprehensive and rigorous program specification at the
end of the analysis phase of the program development life cycle
- followed by the use of formal methods such as structure charts, state
transition diagrams
- Coding Stage
- Avoid?
- Information hiding, encapsulation, and exception handling
- Faults or Bugs = exposed at the testing stage
- Can appear during the lifetime of a program and may be exposed during live
running
- Faults are then corrected as part of the maintenance stage of the program
lifecycle

TYPES OF ERRORS

1. SYNTAX ERROR
= errors in the grammar of a source program
- during the program development life cycle, program are either compiled or
interpreted so they can be executed
- During this operation, the syntax if the program is checked, and errors need to be
corrected before the program can be executed
- Many IDE offers suggestion about what syntax errors are and how to correct
them
2. LOGIC ERROR
= errors in the logic of a program => program does not do what it’s supposed to do
- found when the program is being tested
- Many IDE allows you to single step through the program to find errors
- Manually check using trace table
- Trace Table = shows the process of dry-running a program with columns
showing the values of each variables as it changes
3. RUN-TIME ERRORS
= an error found in a program when it is executed, the program may stop unexpectedly
- when program is tested in IDE, this type of error may be managed, and a suitable
error message given
- If program has been released for use and a run-time error occurs, the developer
should be informed so that the program can be updated and re-released or a
patch can be sent out to all customers to solve the problem
- Patch = a small program, released by the developers, to run with an
existing program to correct an error or to provide extra functionality

PROGRAM TESTING
TEST STRATEGY
= an overview of the testing required to meet the requirements specified for a particular program
- shows how and when the program is to be tested

TEST PLAN
= a detailed list showing all the stages of testing and every test that will be performed for a
particular program
- to clarifier what tests need be perform
During the program design stage, pseudocode is written
- Tested using a dry run on trace table
- Dry Run = a method of testing a program that involves working though a program
or module from a program manually
WALKTHROUGH
= formalized version of a dry run using predefined test cases
- When another member of the development team independently dry runs the
pseudocode, or the developers takes the team members through the dry run process
- Often does as a demonstration
- During the program development and testing, each module is tested as set out in the
test plan

TYPES OF TEST DATA


1. Normal
- Data that is to be accepted by a program and is used to show that the program is
working as expected
2. Abnormal
- Data should be rejected by a program as it unsuitable or could cause problems
3. Extreme
- Data that is on the limit of that accepted by the program
- Ex: Number >= 12 AND Number <= 32
- 12 would be lower limit
- 32 would be upper limit
4. Boundary
- Data that is on the limit of that accepted by a program or that data is just outside
the limit of that rejected by the program
- Ex: Number >= 12 AND Number <= 32
- Accept data 12 and 11 as lower limit
- Accept data 32 and 33 as upper limit
- Or
- 11 and 33 should be rejected
TYPES OF TESTING DURING DEVELOPING PROCESS
1. White Box
- the detailed testing of how each procedure works
- Involves testing the structure and logic of every path through a program module
2. Black Box
- Tests a module’s input and output
3. Integration
- the testing of any separately written modules to ensure that they would work
together, during the testing phase of the program development life cycle
- If any of the models have not been written yet, this can include Stub Testing
- Stub Testing = make use of dummy modules for testing purposes

TYPES OF TESTING AFTER DEVELOPMENT


1. Alpha Testing
- The testing of a completed or nearly completed program in-house by the
development team
2. Beta Testing
- The testing of a completed program by a small group of users before it is
released
3. Acceptance Testing
- The testing of a completed program to prove to the customer that it works as
required

TYPES OF PROGRAM MAINTENANCE


1. Corrective Maintenance
- The correction of any errors that appears during use
- Changes to correct a bug in the program
2. Perfective Maintenance.
- The process of making improvements to the performance of a program
3. Adaptive Maintenance
- The alteration of a program to perform new tasks
- Changes due to change in specification/requirements

You might also like