You are on page 1of 18

ZNOTES.

ORG

UPDATED TO 2015 SYLLABUS

AQA A LEVEL
COMPUTER
SCIENCE
SUMMARIZED NOTES ON THE SYLLABUS
AQA A LEVEL COMPUTER SCIENCE

Multiplication: product of two values


Real/Float division: dividing one number by another
1. Programming may produce an answer with a fractional part
Integer division: dividing one number by another may
produce an answer with a remainder
1.1. Data Types
Modulo: dividing one number by another to find
A data type determines what type of data is going to be the remainder
stored, and how the program should deal with it Exponentiation: raising a number two a power
Rounding: reducing number of decimal digits, while
Integer: positive or negative whole number, inc 0 keeping value approximately accurate
Real/Float: number has a fractional or decimal part Truncating: cutting of a number after so many
Boolean: value is either true or false decimal places or characters
Character: stores a single character Relational: compare two values
String: stores a string of characters
Date/Time: stores data so it is easily identifiable as a date
or a time
Pointer/Reference: created at runtime dynamically, to
identify a particular location/element in a data structure
Records: one line of a text file
Arrays: a collection of values with the same data type, can
be multi-dimensional
Element: a single value within a set/list/array Boolean: result in TRUE or FALSE
Built-in: data types provided with programming language
User-defined: user combines multiple built-in data types
to create their own
Improves efficiency, or makes code more elegant

1.2. Programming Concepts 1.4. Constants and Variables


Combining sequence, iteration and selection are basic to all Constants: an item of data whose value does not change
imperative programming languages during the running of the program
Advantages: speed increase on running, program is
Variable declaration: defining a variable in terms of name
easier to read and maintain (especially for a team),
and data type
values such as Pi only need to be assigned once
Constant declaration: same as variable, but assigning a
Variables: an item of data whose value can change while
value in addition
the program is running
Assignment: giving a value to a variable/constant
Fixed Value: initialised then not changed
Iteration: repeating processes, or sections of code
Pi = 3.142
Definite: repeats for a set number of times
Stepper: steps through a succession of values
FOR loop
Count = Count + 1
Indefinite: repeats until certain conditions are met
Most Recent Holder: holds last value encountered, or
WHILE loop
last input value
Selection: choosing to take action based on criteria
UserInput = Console.ReadLine()
IF/SELECT CASE statements
Most Wanted Holder: holds most appropriate value
Subroutine/Procedure: named section of code that
encountered
performs a specific task
Max = Scores[Count]
Function: subroutine that returns a value
Gatherer: accumulates individual values
Nested code: placing instructions inside of another set of
Total = Total + Scores[Count]
instructions
Transformation: gets new value from a calculation
Meaningful names: produces self-documenting code and
based on the value of other variables
is easy to debug. Use CamelType
Remaining = Old - New
Follower: gets value from the old value of another
1.3. Arithmetic Operations variable
lastPosition = currentPosition
Arithmetic Temporary: holds a value for a short amount of time
Addition: sum of two values temp = score[i]
Subtraction: one value minus another

WWW.ZNOTES.ORG
AQA A LEVEL COMPUTER SCIENCE

Global Variable: can be accessed by any part of the Dealing with events that cause the current subroutine to
program. Should be avoided where possible stop, prevents a fatal program error
Local Variable: can only be seen by the subroutine it is
declared in, or ones that its passed into by reference, and Process
only exist while the subroutine executes Error is thrown so current subroutine pauses/stops
Advantages: value cannot be accidentally changed by Current state is saved to the stack
another part of the program. Same variable name can Catch block/exception handler executes
be used in different subroutines. Frees memory, as is Subroutine pops off the stack and continues
deleted once subroutine stops executing
1.8. Subroutines
1.5. String Handling
Subroutines are named blocks of code that perform specific
Actions that can be performed on sequences of characters tasks, run when triggered by an event, or they form part of
modules
Length: calculate the length of a string
Position: find the position of a character in a string ‘Out of line’: do not execute as part of the main program.
Substring: extracting a section of the string to a new Must be called by a statement
string variable Advantages
Concatenation: joining two strings together Call same code at anytime using its name; removed
Character codes: binary representation of a particular duplicated code
letter, number or special character Easy to see overview of program; use top-down
Code → Character: design
Easy to debug, test and maintain by one or multiple
convert.ToChar()
programmers
Parameter: identifies data to be passed to a subroutine
Character →Code: Argument: actual data passed to a subroutine
encoding,ASCII,GetBytes()
Interface: describes the data being passed from one
subroutine to another
String conversion (and vice-versa) Functions: subroutines that return values
String → integer: Advantages
Removing duplicated code: no need to rewrite
.ToInteger each time, and only need to amend one section
.ToString
Streamlining solution: complex and long code that
produces a single value can be separated into a
String → float:
function; easy to find and understand
ConvertToDateTime(string)
Stack frames: store return addresses, parameters, and
DateTime.Parse()
local variables for each subroutine call
When a subroutine is called, a frame is pushed to the
String → date/time: stack
That subroutine will then execute
.ToInteger
Once complete, the stack frame is popped, and the
.ToString

stack frame below allows execution to return to the


previous subroutine
1.6. Random Number Generation
Creating a random number, normally between two fixed
values

Uses
Creating a set of test data for a program 1.9. Recursive Techniques
Producing data for a computer simulation
Creating random events in games When a subroutine/function calls itself
Selecting a random sample from a dataset
Pseudo-random generation: most languages apply an Base case: terminating condition that must be met at
algorithm to a seed value, so are not truly random. some point during the program’s execution, where
Insufficient for encryption recursion is not used to produce a result
Iterative solutions are easier to program, whereas
recursive solutions can be more compact
1.7. Exception Handling

WWW.ZNOTES.ORG
AQA A LEVEL COMPUTER SCIENCE

2. Programming Paradigms
2.1. Paradigms
Different types/ways of thinking
Programming paradigms: classification of languages
based on their characteristics
Eg: procedural languages execute statements line by
line to produce a result
Eg: object orientated languages rely on performing
actions to objects 2.3. Object Orientated
Turing complete: most modern languages are able to
solve all problems that a computer can solve Characteristics
Models real world objects
2.2. Procedural Orientated Interactions between objects
Inheritance from other objects
Characteristics Use: models real-world objects and relationships
Instructions and sequence Examples: C++, Java
Selection and iteration Advantages
Predefined functions Written in modules, so only small amounts of code
Functions and procedures need updating to make changes
Modules and variables Easy to add new modules and libraries, therefore new
Passing of parameters functionality
Use: scripting, calculations, step-by-step algorithms Objects can inherit attributes and behaviours, so code
Examples: C, VB.net, Python is easily reusable
Advantages Data changes occur in objects not program, less likely
Good for general purpose programming to cause bugs is code affects other routines.
Simple to program, easy to translate
Easy to track program flow 2.4. Object Orientated Principles
Reuse of code
Less memory intensive Concepts
Design
Hierarchy charts: Class: defines methods and property/attribute fields that
capture an objects common behaviours and
characteristics
Instantiation: process of creating an object from a class
template – creates an instance of the class, using
properties and methods described

person1 = new Person(“Reuben”, “Allan”)

Object: created from a class using a constructor (implicit


or explicit), and a reference to the object assigned to a
reference variable of the class type
Encapsulation: concept of protecting attributes and the
methods so that they cannot be accessed by other
objects – objects are self-contained
Private: cannot be seen outside the class, must use a
public method to access it
Methods: code and subroutine contained inside a
Flow charts: class
Attriutes: defining features of an object or a class in
terms of its data.
Inheritance: objects can be created using properties and
methods from a superclass
Sub-classes can implement their own methods
‘Is a’: relationship

WWW.ZNOTES.ORG
AQA A LEVEL COMPUTER SCIENCE

Association: creating an object that contains other objects Private (-): private and can only be used in that class
Aggregation: other objects continue to exist if the Protected (#): can be used in that class and any of its
containing object is destroyed – ‘has a’. Objects are subclasses
independent of each other Class diagrams
Composition: other objects cease to exist if the
containing object is destroyed – ‘has a’. Objects
depend on each other

Overriding: method in the subclass has the same name as


a method in the base class. Overridden method takes 2.5. Assembly
priority, and replaces parent ‘supermethod’ in the base
class Characteristics
Adding .super would bypass the overridden method Mnemonics for opcodes
Polymorphism: methods have different meanings See AQA Assembly Language Instruction Set
associated with it depending on the context Specific to processor
A method inherited from the base class can be Use: microprocessors, since very close to machine code.
redefined and used in different ways depending on Offers greater access to processor and registers than a
the data in the subclass that inherited it HLL
Eg. an object implements methods with the same
name as the base class. Polymorphism makes the
decision between using the base class method, or the 3. Data Structures
method in the sub-class
Principles
3.1. Data Structures and Abstract Types
Encapsulate what varies: everything that varies should
be put into its own class. Properties and methods
Array: list or table of data. 1D array forms a list (shows
should be subdivided into as many classes as
vectors), 2D array forms a table (shows a matrix). Static
required to reflect real world situation. Aids
structure
maintenance, and testing
Files: contains lines of human readable characters, each
Favour composition over inheritance: use aggregation
line is a record and different items of data stored are
or composition rather than inheritance. Classes
fields. May contain headers and internal structures
should be polymorphic and reuse code by
Binary Files: stores a sequence of 0s and 1s, normally
composition, not by inheriting it. Less error prone,
grouped into bytes. Contain binary codes and some
allows simpler maintenance, greater flexibility
header information. Not easily human understandable
Program to interfaces, not implementation: design is
Static Structures: amount of data stored/memory used is
focussed on what code does, not how it does it. So
fixed
program to an interface, which is a collection of
Inefficient: allocated memory that might not be
abstract methods. Specific classes them implement
needed
this interface, to add the ‘how’ to solution
Fast: fixed location in memory
Methods
Contiguous: quicker access
Abstract: method not described in the base class, so
More predictable: fixed size
must be described in the sub-class. Object is used as
Relationship: doesn’t change between elements
an interface between the method and the data
Dynamic Structures: amount of data stored/memory
Virtual: method described in base class but can be
used varies as program is ran. Uses heap
overridden by the method in the subclass where it will
Efficient: varies memory needed
be used
Slow: iterate through each element to find one
Static: method can be used without an object of the
Fragmentation: slower access
class being instantiated
Size varies: needs mechanism to know structure size
Specifiers: properties and methods are
Relationship: can change between elements
Public (+): public to all classes

WWW.ZNOTES.ORG
AQA A LEVEL COMPUTER SCIENCE

3.2. Queues 3.3. Stacks


FIFO: first in first out data structure LIFO: last in first out data structure
Linear: simple 1D array where FIFO applies

Enqueue
Pushing: adding a new item to the stack
Check if Queue is full

   → Stop, report error


Check if Stack is full

backPointer ← backPointer + 1
→ Stop, report error

Insert at Queue[backPointer]
pointer ← pointer + 1

Insert at Stack[pointer]

Dequeue
Popping: removing an item from the stack
Check if Queue is empty
Pointer: a data item that identifies a particular
   → Stop, report error
element in the structure. Normally first/last element
Remove/Print Queue[frontpointer]

frontPointer ← frontPointer + 1
Check if Stack is empty

→ Stop, report error

Circular: fixed size ring where the back of the queue is Remove/Print Stack[pointer]

connected to the front. Pointers move instead of the data pointer ← pointer - 1

Empty: pointers are at same index


Normal: remove from front first, add to the back Peeking: returns the value of the top element without
Full: pointers are at adjacent indices removing it from the stack
Stack Over/Underflow: overflow occurs when more
memory is needed than available to push. Underflow
occurs when there is nothing to pop off
Stack Frames: store information about running program.
A collection of data about a subroutine call. Uses a call
stack
Recursion: details of a recursive function are stored on
the stack
Uses: store subroutine data

3.4. Graph
Mathematical structure that models more complex
relationships between pairs of objects. Graph theory is
the underlying mathematical principles behind the use
Structure
Vertex (nodes): an object in a graph
Edges (arcs): link two vertices together
Undirected graph: the relationship between vertices can
be in either direction
Priority: each element is given a priority value. Higher Directed graph: arrows indicate a one-way relationship
priority elements can ‘jump the queue’, and elements of between vertices
the same priority are dealt with relative to their location Weighted graph: a value is assigned to each edge
in the queue
Uses: CPU scheduling, buffers

WWW.ZNOTES.ORG
AQA A LEVEL COMPUTER SCIENCE

Root: starting node from which other nodes branch


off
Parent: a node with further nodes below it
Child: a node with nodes about it in the hierarchy
Leaf: a node with no other nodes below it

Uses of graphs
Human networks: edges represent relationships, and
a vertex is a person
Transport networks: can be used to calculate the
quickest routes, timetable planning, staffing,
scheduling
Computer science: to work out quickest data
transmission route, to limit latency Rooted tree: one vertex is a designated root, allowing for
Medical research: linking cases of a virus (as vertices) parent child relationships. The root is the only node with
with a weighted graph (distance virus travelled) to no parent; all other nodes are descendants
determine extent of an outbreak Uses of trees
Game theory: each edge could represent the outcome Hierarchy: an OS’s file management system, to store
of an action taken (shown with a vertex) files, directories and folders
The Internet: graphs can be used to show every Dynamic structures: easy to add/remove nodes
connection, and ‘map out’ the internet Easy to: search and sort using standard traversal
Adjacency List: a data structure that stores a list of Syntax processing: natural and programming
vertices alongside their adjacent vertices (ones that it has statements when compiling
a connection to)/ Magnitude can be added for a weighted Binary trees: is directed and rooted. Each node can have
graph, for each adjacent vertex no more than 2 branches on it. A common use would be
Adjacency Matrix: a 2D data structure showing if there is a binary search tree
an edge between two vertices. Magnitude added instead Dynamic data structures
of Boolean value if weighted graph Root node assigned first then for next values:
Choose a list over a matrix when graph is sparse, and If less, branch left. If greater, branch right
edges are rarely changed Repeat until no further edges, add a new node

Adjacency List Adjacency Matrix


· Stores data for every
· Only stores data is there is
an edge – uses less memory
combination – requires more 3.6. Hash Tables
memory
· List must be searched to Data structure that stores data in a hash table at an
· Every combination already index, calculated by applying the hash function to key
find edges – takes longer to
stored – quicker to execute Hash value maps directly to hash table location
execute
· Better for sparse graph · Better for dense graph Very efficient search technique

· Space = 2 x (# of nodes) · Space = (# of nodes)^2

3.5. Tree
A data structure that is a connected, undirected graph
with no loops. It does not have to have a root
Structure
Vertex (nodes): an object in a graph
Edges (arcs): link two vertices together

WWW.ZNOTES.ORG
AQA A LEVEL COMPUTER SCIENCE

Enough slots: enough to store all records, and to


reduce the risk of collisions
Load factor: ratio of how many indices are
available, to how many there are in total
Balance speed and complexity: some algorithms may
require speed over complexity
Collisions: two key values compute the same hash
Next available index: data placed at the next free
index in the hash table, results in clustering if relied
on
Chaining (overflow): creates a linked list at the
Hashing algorithm: applied to data (key) to decide what collision slot, to allow collided hashes to be stored in
slot (bucket) to place the data in the same index
Searching Rehashing: rerunning the hashing algorithm, or
running another, until a unique key is created
index ← HashFunction(key)

IF HashTable[index] = value THEN

Print “Found at [index]”


3.7. Dictionaries
ELSE
Search linked list
A collection of key-value pairs (decided by a hash
END IF
function) in which the value is accessed via the associated
key
Inserting Not stored in an order
General purpose
index ← HashFunction(key)

Uses
IF empty at HashTable[index] THEN

Information retrieval
Insert at index

Add, retrieve and update data


ELSE

Run-length encoding
Follow linked list to find empty

Example
Insert and update pointers

“The green, green grass grows”


ENDIF
{ ‘grass’ : 1, ‘green’ : 2, ‘grows’ : 3, ‘the’ : 4 }
Deleting 42213 (ignoring letter case)

index ← HashFunction(key)
3.8. Vectors
IF HashTable[index] = value THEN

Delete item at index/mark empty


Dynamic data structure where direction and magnitude
ELSE are stored (R2  = 2 vector over R)
Follow linked list, delete/mark empty and update pointers
R4 : 4 vector over R for position, velocity, acceleration and
END IF

force
Uses Rn : how many numbers make up the vector
Databases: create indices for fast storage/retrieval R4 Representations
Memory addressing: generating addresses for cache List: [x, y, z, v]
memory where data is temporarily placed Dictionary: {0:x, 1:y, 2:z, 3:v}
Operating systems: store and locate executable files 1D array:
of all programs and utilities
Encryption: encrypt data in a complex enough 0 1 2 3
manner so that it cannot be reverse engineered x y z v
Checksums: calculating a value to ensure data is
correctly transmitted Function:
Programming: indexes keywords and identifiers the
compiler needs to quickly access as it compiles the 0↦x
program 1↦y
Considerations 2↦z
Unique indices: avoids collisions as much as possible 3↦v
Uniform index spread: reduces risk of collisions *2D array: [x, y]
Clustering: uneven distribution of indices, often
caused by a poor has function that deals with Visualising on a graph
collisions by placing data in next index

WWW.ZNOTES.ORG
AQA A LEVEL COMPUTER SCIENCE

Application: shortest path for an unweighted graph


Queue traversal
Start with first node, add to front of queue
Add all connected vertices to queue
Remove first node (front pointer). Front pointer
moves to second vertex added to the queue
Add all connected vertices to queue
Repeat until all unvisited visited
Remove if no connections to vertex
Repeat until queue is empty

Addition: used to translate vectors

A = (5, 3)  B = (10, 5)


A + B = (15, 8)
Depth-first: starts at a chosen node and explores as far as
Subtraction: used to translate vectors possible along each branch away from the starting node
before backtracking
A = (5, 3)  B = (10, 5) Application: navigating a maze
A − B = (−5,  −2) Stack traversal
Start with first node and push to stack, visited
Multiplication: used to scale vectors Continue along that edge to push all nodes
If node has no vertex, pop off to return to the one
A = (5, 3)
above it, and continue traversing
2A = (10,  6) Repeat until all nodes have popped off the stack,
Convex combination: multiplying vectors to produce a which shows that all have been visited
resultant within the convex hull (area between two
vectors)
u and v are two vectors

αu +  βv
Where  α + β = 1 and α, β  ≥ 0

Dot product: multiply value at each index, and add to


produce one single value
[3, 4, 6, 2] • [1, 7, 2, 4] = [3, 28, 12, 8]
3 + 28 + 12 + 8 = 51
Application: finding the angle between two vectors
4.2. Tree Traversal
cos−1 ( ∥A∥∥B∥
A∙B
)    (∥ X ∥ = magnitude)   
Pre-order: visit root, traverse left subtree, then right

subtree. Place mark to the left of each element for tracing

4. Fundamentals of Use: copy a tree


Post-order: traverse left subtree, then right subtree, then
Algorithms visit root. Place mark to the right of each element for
tracing
Use: infix to reverse polish conversion, emptying a
4.1. Graph Traversal tree, producing a post fix expression from an
expression tree
Graphs: unordered data set In-order: traverse left tree, then visit root, then traverse
Breadth-first: explores nodes closest to the starting node right tree. Place cross underneath element for tracing
before progressively exploring nodes that are further Use: output a binary search tree in ascending order
away

WWW.ZNOTES.ORG
AQA A LEVEL COMPUTER SCIENCE

4.3. Reverse Polish Notation


An unambiguous way of writing out expressions with the
operators after the operand
Conversion: turn into a binary tree and traverse in post-
order
Infix traversal = infix: 3*(10+5)
Pre-order traversal = Polish Notation: * 3 + 10 5
Post-order traversal = Reverse Polish: 3 10 5 + *
Binary Search

Time complexity: O(log n)

l.Bound ← 0

u.Bound ← List.Length – 1

found ← false

WHILE found = false AND l.Bound != u.Bound

   midpoint ← l.Bound + u.Bound / 2

   IF List[midPoint] = item THEN

      found = true

   ELSE IF List[midPoint] < item THEN

Evaluation on a stack
      l.Bound = midPoint + 1

   ELSE u.Bound = midPoint – 1

   END IF

ENDWHILE

IF found = true THEN Print “Found @ midPoint”

ELSE Print “Not found in list”

END IF

Reasons for use


Eliminates the need for brackets in sub-expressions
Expressions are in a form suitable for evaluation on a
stack
Used in stack-based interpreters (Postscript and
bytecode) Binary Tree
Infix notation is ambiguous
Uses Time complexity: O(log n)
Vector graphics Search uses recursion
Mathematical evaluation on computers
Traversal
In-order: produces and infix format
Post-order: produces Reverse Polish Notation
Pre-order: produces prefix notation

4.4. Searching Algorithms


Linear Search

Time complexity: O(n)

4.5. Sorting Algorithms

WWW.ZNOTES.ORG
AQA A LEVEL COMPUTER SCIENCE

Bubble sort: sorts by iterating through the array, Pointer2 = 0

comparing adjacent elements and swapping them until REPEAT

the array is sorted R.Array[Pointer2] = Array[Pointer]

Time complexity: O(n2) Pointer = Pointer + 1

Generally considered inefficient, time-wise Pointer2 = Pointer2 + 1

Larger number bubble to one end, and smaller ones UNTIL Pointer = Array.Length

to the other END SUB

Improve efficiency
Flag variable on inner loop Merge List Function
n = n-1 on outer loop

FOR x = 1 to Array.Length – 1

FOR y = 1 to Array.Length – 1

IF Array[y] > Array [y+1]

Temp ← Array [y]

Array[y] ← Array[y+1]

Array[y+1] ← Temp

END IF

NEXT y

NEXT x

4.6. Optimisation Algorithms


Merge sort: splits the list into individual elements, and
Dijkstra’s shortest path: finds the shortest path from a
then reconstructing the data by combining elements into
single source, to all of the other nodes
increasingly larger ordered lists
Tracing: for A→E, shortest path is ACBDE at 23.
Time complexity: O(n log n)
Known as ‘divide and conquer’, because the problem
is broken down until a point where it can be solved
Merge Sort Function

FUNCTION MergeSort(Array)

IF Array.Count = 1 THEN Return Array

END IF

SplitList(Array, L.Array, R.Array)

L.Array = MergeSort(L.Array)

R.Array = MergeSort(R.Array)

Return Merge(L.Array, R.Array)

END FUNCTION

Split List Subroutine

SUB SplitList(Array, L.Array, R.Array)

MidPoint = Array.Count / 2
Applications
Pointer = 0
Geographic Information Systems: satellite navigation,
REPEAT
offering shortest time or distance
L.Array[Pointer] = Array[Pointer]
Computer network planning: physical cable distance
Pointer = Pointer + 1
or bandwidth constraints
UNTIL Pointer = MidPoint

WWW.ZNOTES.ORG
AQA A LEVEL COMPUTER SCIENCE

Network routing: sending packets along the shortest Erroneous: lies outside of the condition
distance Flow charts
Logistics: transport links along most optimum route

5. Abstraction and
Automation
5.1. Problem Solving
Simple problems can be solved by drawing out a logic
problem grid, and working through all possibilities

5.3. Abstraction
Hiding unnecessary details to highlight necessary;
separates ideas from reality
Representational: remove unnecessary details
Example: London Underground tube map removes all
geographical references to highlight the tube lines
Generalisation/Categorisation: grouping of common
characteristics to arrive at a hierarchical relationship of
the ‘is kind of’ type
Moving up the tree, it becomes more general
Moving down the tree, it becomes more specialised
Example: an aircraft is a kind of/type of vehicle

Procedural: removing actual values used in computations


to produce a computational pattern (procedure)
Example: (5 * 7) + 3 contains actual values, but (a * b)
+ c is a procedural abstraction of that computation
Functional: further abstraction upon procedural, where
5.2. Following and Writing Algorithms computation pattern (procedure) is hidden
Creates a series of reusable functions
Algorithm: sequence of unambiguous steps that can be Example: (a * b) + c is a procedural abstraction
followed to complete a task, always terminates, and is whereas CalculateResult() is a functional abstraction
programming language independent Data: methodology that allows isolation of a compound
Pseudocode: can be used to represent algorithmic data object from the details of how it works and how it is
steps/instructions
constructed
Test data Allows new kinds of data objects to be constructed
Normal: should fit the condition Example: a stack could be implemented as an array
Boundary: hits the limits of the condition and a pointer, but data abstraction removes those

WWW.ZNOTES.ORG
AQA A LEVEL COMPUTER SCIENCE

details, so it is only considered as one data object A machine that knows its current state and will change
Problem (reduction): removing details until the problem is state depending on input
represented in a way that is easy to solve, because it has Can only be in one state at a time
been broken down into smaller problems that have Has no knowledge of previous states
already been solved Finite: countable number of states
Example: turn chess board into a connected graph, to Uses
work out possible routes between squares. Possible Conceptual model used when designing/describing
to unfold graph and work out fastest route computer systems
Information hiding: hiding all of the details that do not Check language syntax
contribute to an object’s essential characteristics State transition diagrams: circles show each state with
Keeps the inner workings hidden, linked to arrows to represent input and the transition
encapsulation of data Starting state: state the machine begins in,
represented by an arrow coming in from nowhere
Transition arrows: directional arrows between states
5.4. Decomposition
Transition conditions: condition that causes a move
Breaking down a large problem into a series of smaller between states
tasks Accepting state: the goal state of the machine,
identifies if input has been accepted. Denotes with
double circle
State transition tables: show input, current state, next
state and possibly output
With no output: state transitions are only labelled with
the input

5.5. Composition
Building up a solution from proven abstracted pre-
existing components
Example: building up Lego bricks to form a Lego
model
Do not need to re-write procedures, or worry about
how they are actually written. Can just use them Mealy machine: finite state machine with output
Combine procedures → compound procedures Each transition is in the form INPUT/OUTPUT
Combine data structures → compound structures Can be used for shift ciphers

5.6. Automation
Building clean models of messy real-world problems
using the minimum amount of data necessary to create a
model, to solve a problem to the required level of
accuracy
Creating abstracted computer models of real-life
situations/problems and putting the into action, by:
Abstracting data to remove what isn’t needed
Create an abstract model
Create an algorithm based on that abstract model
Implementing models in data structures and code 6.2. Maths for Regular Expressions
Executing the code
Allows for new discoveries Set: unordered collection of values in which each value
occurs only once
Set comprehension: describes set elements rather than
6. Regular Languages listing every element
A is a set consisting of objects x so that x values are
6.1. Finite State Machines natural numbers greater than 1
A: name of the set
An abstracted model of computation {}: set contents

WWW.ZNOTES.ORG
AQA A LEVEL COMPUTER SCIENCE

x|: represents actual set values described after | | : OR between two terms
∈ : ‘is a member of’ () : groups regular expressions
N: all natural numbers (used for counting) FSM relationship: regular expressions and FSMs are
∧: ‘and’ equivalent ways of defining a regular language
≥ 1 : for values greater than 1 Eg. x(yz)*
Empty sets: a set that contains no values
Represented with {} or ∅
Compact set representation: to describe all strings with
an equal number of 0s and 1s:
Finite sets: set whose elements can be counted off by
natural numbers up to a particular number
Infinite sets: a set that has no end value (…)
Countable set: a set with the same cardinality of some
subset of natural numbers String searching
Countably infinite sets: can be counted off by the natural . : wildcard that can match any character
numbers, despite never reaching the end [] : matches a single character to any in the brackets
A set of real numbers is not countable [^] : matches a single character to any but those in the
Cardinality of finite sets: the number of elements in a set brackets
Cartesian product of sets: combining multiple sets to * : matches preceding character 0 or more times
create a set of ordered pairs (X x Y) {m,n} : matches preceding character at least m, but no
= {(a,1), (a,2), (a,3), (b,1), (b,2), (b,3), (c,1), (c,2), (c,3)} more than n times
Subset: where two sets are the same and can be said to
be subsets of each other 6.4. Regular Language
Proper subset: a subset of a set that has fewer elements
than the set A language is regular if it can be represented with a
Set operations: regular expression
Membership: represented by ∈ A regular language is any that a Finite State Machine will
Union accept

7. Context Free Languages


7.1. Backus-Naur's Form
Intersection
Context free languages: unambiguous way of describing
the syntax of a language. Useful where the language is
complex
Used when counting and matching is infinite
Support recursion
Can be clearer than regular expressions
Difference: A\B or A-B Backus-Naur Form: describes programming language
syntax in an unambiguous way
Set: created that defines acceptable strings
Terminal: final element that needs to further rules
<>: represents a symbol or element
::= : defines the rule for the symbol or element
| : means ‘or’
Recursion: BNF supports recursion, so can represent
6.3. Regular Expressions some languages that cannot be represented by
regular expressions. Means it is not necessary to
Describes a set and allows particular types of language to
define exactly how many characters are needed
be described in a convenient shorthand notation
Do not have recursive features, unlike BNF
eg. a(a|b)* = { a, aa, ab, aaa, aab, aba.. }
String manipulation and matching
* : 0 or more repetitions
+ : 1 or more repetitions
? : optional, 0 or 1 repetitions

WWW.ZNOTES.ORG
AQA A LEVEL COMPUTER SCIENCE

Permutations: number of possible ways a set can be


7.2. Syntax Diagrams
ordered
Graphical representation of BNF The number of permutations for n number of objects
is n!
Factorial (n!): is the product of all positive integers less
than or equal to n. (eg. 5! = 5x4x3x2x1 = 120)
Number of permutations for a word with 3 letters is 6
(3! = 6): {dog, dgo, odg, ogd, gdo or god)

8.4. Order of Complexity


Big O Notation: distils an algorithm down to a single
expression, indicating how it will perform (time and space
wise) with more inputs.
Algorithms with the same Big O will not run in the
same amount of time, only the time/input relationship
is the time.
Constant time O(1): no matter the input size, the result
will always be retuned in the same amount of time. Best
Logarithmic time (logN ): runtime increases with a
logarithmic function where an exponent is used to to
raise the value of the base number to produce the
8. Classification of Algorithms desired number. 2 nd best
Linear time O(n): runtime increases directly
proportionally to the input size. 3 rd best
8.1. Introduction
Polynomial time O(n2 ): runtime increases proportionally
Algorithm: sequence of unambiguous steps that can be to the square of the input size. Other derivatives occur
followed to complete a task, always terminates, and is when n is raised to another power. Weak
programming language independent Exponential time O(2n ): runtime increases as an
exponential function of the input size (doubles with every
additional input unit increase). Least efficient, considered
8.2. Comparing Algorithms intractable. Bad - avoid
Efficiency: O(1) → O(logN ) → O(n) → O(n2 ) → O(2n )
Computational complexity: worst case complexity of the
best algorithm, also considers algorithm correctness
Time complexity: time required
Space complexity: resources (memory) required
Some algorithms are more efficient in one than the
other
Input size is the key factor, not time (this is relative across
different computer systems)
Identify basic operation, then consider how many times it
will run, and what happens if input is doubled
Asymptotic decision: take worst case complexity in an
algorithm as the overall complexity
Effective automated abstractions (best designed
algorithms) take the least time and minimal resources

8.3. Maths and Big-O Notation Calculate complexity: using number of lines of code
Remove all terms expect one with largest
Functions: mapping a relationship between one set of factor/exponent o Remove constants
values (domain) and another set of values drawn from Example: for a program with 2 nested loops, then 6
the codomain (range). lines in 3 nested loops, then a single loop with 2 lines,
Linear: y = 2x then 1 line of code
Logarithmic: y = log10 ​

Polynomial: y = 2x
2 n2 + 6n3 + 2n + 1
Exponential: y = 2x
= O(n3 )

WWW.ZNOTES.ORG
AQA A LEVEL COMPUTER SCIENCE

Derive complexity: define worst case scenario. halt, without running it


O(1): requires no data, has no loops/recursion. Describes the unsolvable problem of determining
Indexing an array. whether any program will stop, given particular input
O(logN ): logarithmic algorithms where time
complexity halves with each increase in input size
O(log2 N ) = binary search.

O(n): looping through an array accessing each data


item once.
Linear array search.
O(nn umberof loops): two nested loops.
O(n2 ): Bubble sort.
O(aN ): an algorithm using recursion (exponential)
Intractable problems: not solvable within a
reasonable time frame and for which no efficient
algorithm exists

8.5. Limits of Computation Halting solution


H takes program and inputs, to determine if program
Computable problems are limited by will finish executing
If input is replaced with the program, H has data input
Hardware limits (memory if exponential)
Intractable complexity in the form of 0s and 1s
Creating program K causes looping forever is H’s
Impossibility of producing an algorithm
Solvable: finite set of inputs result it to halt, or half if H’s result it to keep looping
Unsolvable: infinite set of inputs Significance
Proves that some problems cannot and will never be
solved on a computer
8.6. Classification of Problems Highlights that some problems can be solved by
computers, but not in a reasonable time frame
Tractable: have a time complexity of polynomial or better.
Solved quickly enough for solution to be practical
Time complexity of <= O(k )
n
9. Model of Computation
Intractable: problems that do not have a solution of
polynomial time complexity, or less
Time complexity of > O(k n ) 9.1. Turing Machine
Often solvable with small input size, but quickly grows
to be impractical to solve on a computer
Travelling salesman problem: must travel the shortest
distance between all cities, visiting them all once, without
knowing distance between them
Heuristics: added to solutions to provide an
incomplete/approximate solution which add a bias, or
ignore certain complexities of the problem

8.7. Computable/Non-Computable Computer model with a single fixed program, models


which problems are computable or not
Problems Structure
Finite alphabet: acceptable symbols for the machine
Computable: can create an algorithm to solve Read/write head: can travel along the tape, one cell at
Non-computable: cannot create an algorithm a time, to read, erase and write/overwrite the
Eg. Halting problem contents
Algorithm: a description of a set of unambiguous Control unit: effectively a FSM. Defines start/halt
steps/rules/instructions that describe a solution to a states, transition rules etc…
problem Infinite tape: marked off cells (represent memory
addresses in modern computers) that are considered
8.8. Halting Problem one at a time. Makes machine more powerful
Halting state: has no outgoing transitions – Turing
It is not possible to, write a program that given any machine will stop
program and inputs, decide that program given to it it will Start state: initial state of the Turing machine

WWW.ZNOTES.ORG
AQA A LEVEL COMPUTER SCIENCE

Use: theoretical machine to carry out an algorithm – a


9.2. Universal Machine
model of what is computable
Development: as a concept to solve the ‘decision Universal machines: a single machine that can simulate
problem’ (is it possible to solve any maths problem
Turning machines by taking in a description on the
with a finite number of steps and inputs?)
machine, and its respective input
Transition functions and state transition diagrams are
Transition function is stored alongside the data to be
equivalent processed
Transition functions
Effectively an interpreter
δ(Current state, Input) = (Next state, Output, Move)

Importance
If a Turing machine can compute a problem, then a
real-world computer can, and likewise
Is a general purpose computer that defines what is
computable
State transition diagram Purpose can be changed by changing the machine
description
Programs and data are the same (sequences of
symbols and data)

WWW.ZNOTES.ORG
AQA A LEVEL
Computer Science

Copyright 2021 by ZNotes


These notes have been created by Rueben Allan for the 2015 syllabus
This website and its content is copyright of ZNotes Foundation - © ZNotes Foundation 2022. All rights reserved.
The document contains images and excerpts of text from educational resources available on the internet and
printed books. If you are the owner of such media, test or visual, utilized in this document and do not accept its
usage then we urge you to contact us and we would immediately replace said media.
No part of this document may be copied or re-uploaded to another website without the express, written
permission of the copyright owner. Under no conditions may this document be distributed under the name of
false author(s) or sold for financial gain; the document is solely meant for educational purposes and it is to remain
a property available to all at no cost. It is current freely available from the website www.znotes.org
This work is licensed under a Creative Commons Attribution-NonCommerical-ShareAlike 4.0 International License.

You might also like