Aqa A Level Computer Science Programming v1
Aqa A Level Computer Science Programming v1
ORG
AQA A LEVEL
COMPUTER
SCIENCE
SUMMARIZED NOTES ON THE SYLLABUS
AQA A LEVEL COMPUTER SCIENCE
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
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
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
WWW.ZNOTES.ORG
AQA A LEVEL COMPUTER SCIENCE
Enqueue
Pushing: adding a new item to the stack
Check if Queue 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
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
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
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
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
Uses
IF empty at HashTable[index] THEN
Information retrieval
Insert at index
Run-length encoding
Follow linked list to find empty
Example
Insert and update pointers
index ← HashFunction(key)
3.8. Vectors
IF HashTable[index] = value THEN
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
αu + βv
Where α + β = 1 and α, β ≥ 0
WWW.ZNOTES.ORG
AQA A LEVEL COMPUTER SCIENCE
l.Bound ← 0
u.Bound ← List.Length – 1
found ← false
Evaluation on a stack
l.Bound = midPoint + 1
END IF
ENDWHILE
END IF
WWW.ZNOTES.ORG
AQA A LEVEL COMPUTER SCIENCE
Larger number bubble to one end, and smaller ones UNTIL Pointer = Array.Length
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
Array[y] ← Array[y+1]
Array[y+1] ← Temp
END IF
NEXT y
NEXT x
FUNCTION MergeSort(Array)
END IF
L.Array = MergeSort(L.Array)
R.Array = MergeSort(R.Array)
END FUNCTION
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
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
WWW.ZNOTES.ORG
AQA A LEVEL COMPUTER SCIENCE
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
WWW.ZNOTES.ORG
AQA A LEVEL COMPUTER SCIENCE
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