0% found this document useful (0 votes)
34 views

Computer Science Paper 2 Notes

My Notes on Cambridge's Computer Science (9618/21)

Uploaded by

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

Computer Science Paper 2 Notes

My Notes on Cambridge's Computer Science (9618/21)

Uploaded by

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

Computer Science: Part 2

Chapter 12: Algorithm design and Problem-Solving


1. Computational thinking is a problem-solving process where a number
of steps are taken in order to reach a solution.
2. Computational thinking involves five key strands: abstraction,
decomposition, data modelling, pattern recognition and algorithmic
thinking.

Four basic types of constructs for an algorithm:

1. Assignment: a value is given a name (identifier) or the value associated


with a given identifier is changed.
2. Sequence: A number of steps are performed, one after the other.
3. Selection: under certain conditions some steps are performed,
otherwise different (or no) steps are performed.
4. Repetition: a sequence of steps is performed a number of times. This is
also known as iteration or looping.

Modules:

1. The difference between Procedures and functions are that functions


return a value, whereas procedures just run a number of instructions.
And both are classified under modules.

Loops:
1. A rogue value is a value used to terminate a sequence of values. The
rogue value is of the same data type but outside the range of normal
expected values.

Stepwise Refinement = Break a problem into sub-problems


Chapter 13: Data types and structures
Primitive Data Types
1. Primitive data types are those variables that can be defined simply by
commands built into the programming language.
2. Primitive data types are also known as atomic data types.

The Record Type


1. A record type is also known as a composite type.
2. Basically a class with just variables (C# wise).
3. It’s a user-defined data type which holds the relevant pieces of
different information of a transaction from start to finish using different
data-structures.
For example, personal data which could contain Name, DoB, Age, etc.

It’s defined as:

TYPE BookType
Title : STRING
YoP : DATE
Price : REAL
ISBN : INTEGER
ENDTYPE

And used as:

DECLARE MyBook : BookType


MyBook.Title <- “MyBookTitle”
OUTPUT MyBook.Title
Arrays
1. Arrays is a dataset of different values of varying/same data types
organized in a list or table/matrix. Usually the same data type is
used in arrays.
2. Arrays are fixed in size and are set when you initialize them.

Text Files
1. A text file consists of a sequence of characters formatted into lines.
Each line is terminated by an end-of-line marker. The text file is
terminated by an end-of-file marker.

Abstract Data Types


An Abstract Data Type is a collection of data and a set of associated
operations:

 Create a new instance of the data structure


 Find an element in the data structure
 Insert a new element into the data structure
 Delete an element from the data structure
 Access all elements stored in the data structure in a systematic
manner.

Stacks
1. When an element is popped (removed) from the stack, the
TopOfStackPointer will decrease to point to the element now at the
top of the stack.
2. When the stack is empty, TopOfStackPointer will have the value –1.
Queues

When the queue is empty, the EndOfQueuePointer will have the value –1.

Note: Stacks are ordered from 0 to # from bottom up, whereas queues are
ordered from top to bottom (though still being ordered from 0 to #)

Chapter 14: Programming and Data Representation


Programming Languages
Algorithms: The basic constructs of an algorithm consists of 5 things:
1. Assignment
2. Sequence
3. Selection
4. Iteration
5. Input and output.

Arithmetic Operators

The result of integer division is the whole number part of the division. For
example, 7 DIV 2 gives 3.

The result of the modulus operation is the remainder of a division. For


example, 7 MOD 2 gives 1.

Loops
1. Count-Controlled Loops are For loops.
2. Post-Condition Loops are loops that execute the code within the
statements at least once, and this loop repeats as long as the
condition is False. (e.g. REPEAT ... UNTIL)
3. Pre-Condition Loops evaluate the condition before the loop starts
and repeats as long as the condition is True. (e.g. While loop)

Which loop structure to use?


If you know how many times around the loop you need to go when the
program execution gets to the loop statements, use a count-controlled
loop. If the termination of the loop depends on some condition
determined by what happens within the loop, then use a conditional
loop. A pre-condition loop has the added benefit that the loop may not
be entered at all, if the condition does not require it.

Modules/Subroutines
1. BYRef (Variables) that are a parameter of a procedure actually
affects the variable value outside the scope of the procedure.
2. Parameters are defined as variables that are defined at a
function/procedure’s input variables.
3. Arguments are the variables/constants that are passed to the
function/procedure from the outside.
4. An interface refers to the whole process of passing in an argument
and it being used as the parameter defined.

Chapter 14: Programming and Data Representation


Stages in the program development life cycle
1. Analysis
a. Investigate the Issue
b. Plan a macro-solution
c. How to solve a problem?
i. Bottom-up: Start with a small sub-problem and then
build on this
ii. Top-down: Stepwise refinement using pseudocode,
flowcharts or structure charts.
2. Design
a. Technical Specifications
3. Coding (Implementation)
4. Testing
5. Maintenance

The Waterfall Model

The arrows going down represent the fact that the results from one stage are
input into the next stage. The arrows leading back up to an earlier stage
reflect the fact that often more work is required at an earlier stage to
complete the current stage.

Benefits include:
1. Simple to understand as the stages are clearly defined.
2. Easy to manage due to the fixed stages in the model. Each stage
has specific outcomes.
3. Stages are processed and completed one at a time.
4. Works well for smaller projects where requirements are very well
understood.

Drawbacks include the following:


1. No working software is produced until late during the life cycle.
2. Not a good model for complex and object-oriented projects.
3. Poor model for long and ongoing projects.
4. Cannot accommodate changing requirements.
5. It is difficult to measure progress within stages.
6. Integration is done at the very end, which doesn’t allow
identifying potential technical or business issues early.

The Iterative Model

An iterative life cycle model does not attempt to start with a full specification
of requirements. Instead, development starts with the implementation of a
small subset of the program requirements. Repeated (iterative) reviews to
identify further requirements eventually result in the complete system.

Benefits Include:

 There is a working model of the system at a very early stage of


development, which makes it easier to find functional or design flaws.
Finding issues at an early stage of development means corrective
measures can be taken more quickly.
 Some working functionality can be developed quickly and early in the
life cycle.
 Results are obtained early and periodically.
 Parallel development can be planned.
 Progress can be measured.
 Less costly to change the scope/requirements.
 Testing and debugging of a smaller subset of program is easy.
 Risks are identified and resolved during iteration.
 Easier to manage risk – high-risk part is done first.
 With every increment, operational product is delivered.
 Issues, challenges and risks identified from each increment can be
utilised/applied to the next increment.
 Better suited for large and mission-critical projects.
 During the life cycle, software is produced early, which facilitates
customer evaluation and feedback.
Drawbacks Include:

 Only large software development projects can benefit because it is


hard to break a small software system into further small serviceable
modules.
 More resources may be required.
 Design issues might arise because not all requirements are gathered at
the beginning of the entire life cycle.
 Defining increments may require definition of the complete system.

The Rapid Application Development (RAD) Model

RAD is a software development methodology that uses minimal planning.


Instead it uses prototyping. A prototype is a working model of part of the
solution.

In the RAD model, the modules are developed in parallel as prototypes and
are integrated to make the complete product for faster product delivery.
There is no detailed preplanning. Changes are made during the development
process.

The analysis, design, code and test phases are incorporated into a series of
short, iterative development cycles.

Benefits Include:

 Changing requirements can be accommodated.


 Progress can be measured.
 Productivity increases with fewer people in a short time.
 Reduces development time.
 Increases reusability of components.
 Quick initial reviews occur.
 Encourages customer feedback.
 Integration from the very beginning solves a lot of integration issues.

Drawbacks Include:

 Only systems that can be modularised can be built using RAD.


 Requires highly skilled developers/designers.
 Suitable for systems that are component based and scalable.
 Requires user involvement throughout the life cycle.
 Suitable for projects requiring shorter development times.

Program Design using structured charts


The difference between structured charts and flowcharts is that flowcharts
show the flow of a program from top to bottom, essentially the algorithm.
Whereas a structure chart shows how different modules of a program
interact with one another, in a hierarchical way.

A semicircle shows that those modules will repeat until the condition is met.
Note that a structure chart does not give details about how parameters are
passed: by reference or by value.

Program Design using state-transition diagrams


A computer system can be seen as a finite state machine (FSM). A FSM
has a start state. An input to the FSM produces a transformation from one
state to another state.

The information about the states of an FSM can be presented in a state-


transition table.

 If the FSM is in state S1, an input of a causes no change of state.


 If the FSM is in state S1, an input of b transforms S1 to S2.
 If the FSM is in state S2, an input of b causes no change of state.
 If the FSM is in state S2, an input of a transforms S2 to S1.

A state-transition diagram can be used to describe the behaviour of an FSM.


The start state is denoted by •-->. If the FSM has a final state (also known as
the halting state), this is shown by a double-circled state (S1 in the example).
If an input causes an output this is shown by a vertical bar. For example, if
the current state is S1, an input of b produces output c and transforms the
FSM to state S2.

A Finite State Machine with outputs is also known as a Mealy Machine.

Types of Errors
1. Syntax Errors
2. Logic Errors
3. Run-time Errors

Logic and Run-time Errors are harder to find.

Testing Methods
Stub Testing

Used for testing a structure of code (by print statements (or a procedure that
contains a print statement)) before the functions of the structure are coded

Black Box Testing


This testing method is used by people who don’t have access/knowledge to
the code of the software. Therefore, the program is a ‘black box’ to them.

The way it is used is that:

1. The tester understands the purpose of the code/program


2. The tester creates test data. Test data usually consists of normal data
values, extreme/boundary data values and erroneous/abnormal data
values.
3. If any errors are found, the tester reports it to the programmers.

After that, typically the programmer will use debugging software or dry-
running have to be used to find the lines of code that need correcting.

White Box Testing

How can we check that code works correctly?


We choose suitable test data that checks every path through the code.
This is called white-box testing.

Dry-running an Algorithm

Dry-run = going through the code, step-by-step in your head without


executing it.

A good way of checking that an algorithm works as intended is to dry-run


the algorithm using a trace table and different test data. This is also known
as a walk through.

The idea is to write down the current contents of all variables and conditional
values at each step of the algorithm.

Trace Table:
We only make an entry in a cell when an assignment occurs. Values remain
in variables until they are overwritten. So a blank cell means that the value
from the previous entry remains.

It is important to start filling in a new row in the trace table for each iteration
(each time around the loop).

Types of testing:

 Integration Testing
o Software often consists of many modules, sometimes written by
different programmers. Each individual module might have
passed all the tests, but when modules are joined together into
one program, it is vital that the whole program is tested. a.k.a.
Integration Testing.
o Integration testing is usually done incrementally. This means
that a module at a time is added, and further testing is carried
out before the next module is added.
 Alpha Testing
o It is where software is tested in-house by software testers before
being released to customers.
 Acceptance Testing
o Bespoke software (written for a specific customer) will then be
released to the customer. The customer will check that it meets
their requirements and works as expected. This stage is called
acceptance testing.
o It is generally part of the hand-over process. On successful
acceptance testing, the customer will sign off the software.
 Beta testing
o Where the software is being produced for general sale (no
specific customer).
o After alpha testing, a version is released to the beta testers
(limited users of the general public) to find errors on their end
and report it to the developers.

Test Strategy, Test Plans and Test Data


It is important to recognise that large programs cannot be exhaustively
tested but it is important that systematic testing finds as many errors as
possible. We therefore need a test plan. In the first instance, an outline plan
is designed, for example:

 Flow of control: does the user get appropriate choices and does the
chosen option go to the correct module?
 Validation of input: has all data been entered into the system correctly?
 Do loops and decisions perform correctly?
 Is data saved into the correct files?
 Does the system produce the correct results?

Types of test data:

A major cause of errors is poor requirements analysis.

Maintenance
Corrective Maintenance

Corrective maintenance of a program refers to the work required when a


program is not working correctly due to a logic error or because of a run-time
error.
Adaptive Maintenance

Programs often get changed to make them perform functions they were not
originally designed to do.

Adaptive maintenance is the action of making amendments to a program to


enhance functionality or in response to specification changes.

Perfective Maintenance

The program runs satisfactorily. However, there is still room for


improvement. For example, the program may run faster if the file handling is
changed from sequential access to direct access.
Questions:
1. Is it necessary to write in Cambridge’s pseudocode style, or are we
free to change the syntax to our will? (to a certain extent).
Other Notes:

The Dimond represents that only 1 out of the 3 methods will be run.

This is how a linked list (with both a data linked list and free linked list) is
implemented with arrays.

You might also like