A-Level - Paper 3 - Study Guide
A-Level - Paper 3 - Study Guide
Table of Contents
[Click below to immediately navigate to desired topic]
DECLARE newAge
// Note: Data at address of age is accessed
// Useful if value of Age is changing
newAge ← agePointer^
- Composite Data Types
- Can refer to other data types in type definition
- Includes Records, Sets, and Classes/Objects
- Records
- Example:
TYPE Student
DECLARE Name: STRING
DECLARE Id: STRING
DECLARE BirthDate: String
DECLARE GPA: REAL
ENDTYPE
Example
Step 3: Change the exponent such that the mantissa is in the format of a positive
floating number (0.1xxxxxxx)
0.11100000 * 233
Step 3: Change the exponent such that the mantissa is in the format of a positive
floating number (xx1.0xxxxxxx)
111.01100 * 28
Step 4: Remove any extra digits beyond the first digit on the left side of the
decimal point.
1.01100000 * 28
Step 2: Multiply the improper fraction by ½ until the denominator of the fraction is
greater than the numerator.
Step 3: The number of times we have to multiply the improper fraction by ½ such
that the denominator is greater than our numerator becomes our exponent. Once
we find this exponent, we must also convert it to binary.
Step 4: We must find the fewest multiples of ½ that can be added together to
give us our result from Step 2.
Step 5: We are working with a positive decimal number, so the first value in our
mantissa will be 0, corresponding to 20. This is the only value to the left of the
decimal print. We will fill in all the other values in the mantissa to the right of this
first value based on the result from Step 4.
Mantissa: 010000010100
Exponent: 0111
Step 3: Count the number of times we had to multiply our improper fraction from Step 1
to achieve our result in Step 2, and then convert this value to binary.
Step 4: Because we are converting a negative floating point number, our mantissa will
start with 0 and the rest of the mantissa will be the difference between -1 and the result
of Step 2.
Step 5: We must find the fewest multiples of ½ that can be added together to give us our
result from Step 2.
Step 6: We use these multiples of ½ to fill in the rest of the mantissa.
Mantissa: 1000110000
Exponent: 000011
Step 3: Move the decimal point to the right the same number of times as the exponent.
The exponent then becomes 0, which is equal to 1.
Step 4: Calculate the binary value of the resulting mantissa to get your answer.
Answer: -78.25
Step 1: Due to the fact that the binary value is unsigned, assume that the
mantissa will be positive and set up the mantissa accordingly.
Step 2: Move the decimal point in the binary value enough places to the left such
that the result follows the format 0.1xxxxxxxxxxx.
Result: 0.1011100011001 * 27
Step 3: The number of times you move the decimal point will be the value of your
exponent, which you can convert to binary.
Step 4: Given the number of bits allocated to the mantissa, remove any excess
bits on the right side of the mantissa.
Mantissa: 010111000110
Exponent: 0111
14.1: Protocols
- Protocols
- common standard for communication between some group of devices
- allow devices made by different manufactures to communicate with each other
- All data between transmitted between protocol-compatible device must follow
same set of rules
- Protocols as a Stack
- Structured in layers, with each layer responsible for a part of the communication
process
- Data packets transferred one-by-one from top layer to bottom layer before being
set sent off
- Each layer, which corresponds to specific rules and software to validate these
rules, operates independently
- TCP/IP Protocol
- Enables computers to communicate over the internet and other networks
- Application Layer
- User Interface - where the user submits data to be transmitted via web
browser, etc.
- Security - data is encrypted/secured for transmission
- Translation - data is translated/formatted for transmission over network
- Transport Layer
- Segmentation - divides data into data packets
- Sequencing - decides order in which packets will be transmitted, adds this
information to packet header
- Received data from Application layer, sends packets to Network later
- Internet (Network) Layer
- Decides optimum route through which packets will travel
- Addresses packets with their source and destination IP address
- Transmits packets down to Network Access (Physical/Data Link) layer
- Network Access (Physical/Data Link Layer)
- Turns data into raw signal to be transmitted over network
- Controls rate at which data is transmitted
- Responsible for physical connection (wifi, ethernet, etc.)
- Other Protocols
- HTTP - used for sending and receiving webpages
- FTP - used for sending and receiving files over networks
- SMTP - used for sending emails from a mail server using push protocol
- POP3 - used for receiving and downloading emails from a mail server using pull
protocol (users must make request to see new emails)
- IMAP - used for receiving and downloading emails from a mail server using
push protocol (emails are automatically delivered to user)
- BitTorrent - peer-to-peer (P2P) file-sharing protocol used for distributing large
files across the internet
- swarm downloading - files are broken down into different pieces, which
can be stored with different users, but downloaded and assembled back
together by a single user
- RISC + Pipelining
- Allows several instructions to be simultaneously processed
- Processing cycle divided into several stages (Fetch, Decode, Execute, Memory
Access, Results written to register)
- While one instruction is in one stage, the next instruction is in the previous stage
- At each clock cycle, multiple instructions are going through different stages
- Reduces CPU downtime, more instructions processed in a given period of time,
instructions executed more quickly
- RISC + Registers
- Use general purpose registers - can hold multiple data types
- Reduces need to fetch data from memory, which decreases execution time
- Can be used as temporary storage for intermediate results during execution,
which makes pipelining easy
- (Massively) Parallel Computing
- When a large number of computers/processors are connected to each other to
collaboratively complete a large task
- Pass messages to each other to coordinate operations
- Connected by some type of network infrastructure
- On a massive scale, hundreds or thousands of computers can work together
- 4 Basic Computer Architectures
- Refers to how multiple processors are organized to collectively process
instructions
- SISD (Single Instruction, Single Data) - Single instruction used to process single
data input by single processor, one at a time [Most common]
- SIMD (Single Instruction, Multiple Data) - Same operation simultaneously
performed by multiple processors on different data inputs from the same data
set [Graphical applications]
- MISD (Multiple Instruction, Single Data) - Multiple different operations on the
same data input on multiple processors
- MIMD (Multiple Instruction, Multiple Data) - Multiple different operations on data
from multiple different data inputs simultaneously [Multicore systems]
- Virtual Machines
- Emulates a computer system on another host computer system, usually with a
different operating system
- For example, using a virtual machine, you could run a fully functional Linux
system, on a Windows PC
- Components like hard drive, graphic card, memory are all virtual
- Software like Parallels, Boot Camp, VMWare, make this possible
- Advantages & Disadvantages of Virtual Machines
- Data Thrashing
- a situation that occurs in computer systems when the operating system spends a
significant amount of time and resources repeatedly swapping data between
physical memory (RAM) and virtual memory
- Causes
- Insufficient RAM
- Overcommitting memory - total amount of virtual memory exceeds
physical memory
- Excessive multitasking
- Poor memory management - inefficient swapping algorithms
- Effects
- Data loss/corruption
- High disk activity - can reduce life of hard drive
- Reduced multitasking capability
- Stages of Compilation
1) Lexical Analysis - converting a sequence of characters into a sequence of tokens
2) Syntax Analysis - using parsing algorithms to interpret the meaning of a
sequence of tokens
- Checks if code follows the rules of the programming language
3) Optimisation - changing code to minimizing a program’s execution time and
memory usage
4) Code Generation - converting an intermediate representation of source code into
an executable form
- Lexical Analysis
- converting a sequence of characters into a sequence of tokens
1) All characters not required for the program are removed (white space, comments,
etc.)
2) Source code needs to be converted to tokens (tokenization).
- Each keyword or symbol can be matched to a string or number (token)
using a keyword table
- We end up with a sequence of these values.
- Any variables, constants or other identifiers (function, class names) are
added to the keyword table during compilation to aid tokenization
- Backus-Naur Form
- A set of symbols and rules that are used to describe the syntax of a programming
language
- Syntax rules can also be described using syntax diagrams
Syntax Diagram Example
A variable first consists of a letter, and then an unsigned integer, in that order.
An unsigned integer is either a single digit, or two digits put together (concatenated).
A digit is either 1, 2, or 3.
<digit> ::= 1 | 2 | 3
<operator> ::= + | - | *
Syntax Rules
BNF Notation
Syntax Rules
1. 1 characters
2. A digit, multiple digits, a capital letter followed by one or more digits and/or capital
letters, or a digit followed by one or more digits/capital letters
BNF Notation
(a - b)* (a + c) / 7
Step 1: Each individual operation is converted into both the relevant variables,
followed by the relevant operation. We start with parentheses and work our way
outwards.
ab- * ac+ /7
Step 2:
ab- ac+ * /7
Step 3:
ab- ac+ * 7/
ab / 4 * a b + -
Step 1
(a/b) 4 * (a + b) -
Step 2
((a/b) * 4) - (a + b)
ab + cd / /
(a + b) / (c / d)
- RPN: Benefits
- Can be used to evaluate expression from left to right rather than skipping around
- Doesn’t require parenthesis to be taken into account
- Doesn’t require order of operations to be taken into account
Topic 17: Security
- Quantum Cryptography
- Information is represented in qubits, which can be 1, 0, or both 1 and 0 at the
same time
- Each qubit is represented by a photon (unit of light energy) pointing in a specific
direction based on its value
- Photons travel between a sender and recipient via fiber optic cable.
- Also requires a non-quantum “classical” mode of electronic communication
- Data is transmitted as a stream of photons, all in a particular order and
orientation.
- Any attempt to access this data while being transmitted alters the message.
- It is theoretically impossible to intercept a transmission protected by quantum
cryptography.
- Quantum Cryptography: Advantages & Disadvantages
- Protocols (SSL/TLS)
- SSL - Secure Sockets Layer
- TLS - Transport Layer Security
- Process used by web browser to encrypt communication between browser and a
server
- Confirms identity of client and server
- Prevents hackers from intercepting traffic between client and server
- TLS is newer and more secure than SSL
- SSL/TLS Steps
1) Client (on a web browser) tries to access a website which uses SSL/TLS
(a handshake)
2) Websites’ server receives connection and responds with a digital
certificate, which contains a public key and is validated by a certificate
authority.
3) The client’s browser validates the authenticity of the digital certificate.
4) The browser generates a key for the current session using the public key,
which is sent back to the server.
5) The server uses its private key (which is used to generate the public key)
to verify the session key.
6) Any further communication between the client’s browser and server is
encrypted (hashed) through the use of this session key.
- Digital Signatures
1) The sender uses a mathematical function called a hash function to generate a
hash value (also known as a message digest).
2) The result is an alphanumeric value of a fixed-length, which is then encrypted
using a public key.
3) This encrypted hash value is the digital signature and is then attached to
unhashed version of the message to be sent
4) The message is sent to the recipient.
5) The recipient decrypts the signature using their private key and puts the message
they received through a hash function.
6) The recipient compares the contents of the decrypted signature and the hashed
message and if they are equal, the transmission is authentic.
- Digital Certificates
- Verifies the identity of a website
- Contains website’s public key, identifying information, Certificate Authority
information + CA private key, validity period, etc.
- Browser can verify digital certificate using CA public key
- Obtaining a Digital Certificate
1) A website makes an inquiry to a Certificate Authority (CA).
2) The CA investigates the website and any associated entities.
3) The CA verifies the identity and security of the website and issues a public key.
4) The website includes this public key in a certificate sent to a client attempting to
connect using SSL.
5) The client (browser) verifies the certificate using the CAs digital signature in the
certificate and communicates with the website by encrypting data with this
public key.
Topic 18: Artificial Intelligence
- A* Algorithm
- Like Djikstra algorithm, but with heuristic (h) value - predicted distance to goal
- heuristic value (h), and movement value (g), and the sum of these two (f)
- Find the first node with the lowest f
- From the first node, find the next node that produces the lowest f.
- Keep doing this until you get to your objective.
Example
Basically the idea here is that the cost to move from the home node to any given node is the
cost (g). The heuristic is the expected distance from any given node to the ultimate destination,
which is the School node in the above example.
In the problem above, basically you had to calculate first the sum of the cost and heuristic for
routes that minimize the total and are possible routes for approaching the destination node (i.e
School node). Eventually, this will lead you to routes directly to the destination node without a
heuristic), of which you are expected to find the route with lowest cost from the home node.
This is basically an iterative process by which you get closer and closer to the destination and
show cost, heuristic and total of these in the process.
Programming
Programming Languages
- Imperative Programming Languages
- use variables that are modified through assignment statements and rely
on iteration
- provide a sequence of commands for the computer to execute in a
specific order, with each line of code altering the program's state.
- Example: Python, Java, etc.
- Declarative Programming Languages
- specify what needs to be done rather than how to do it, using facts, rules,
and queries to achieve goals.
- can be either logical, stating programs as sets of logical relations, or
functional, constructed by applying functions to arguments in a
mathematical style.
- Used to store information and then recall it
- Examples: SQL, Prolog
- On Paper 3, examples of declarative programming are written using a
variant of Prolog, as shown below
- Code Example:
// Information
student(John)
student(Ali)
student(Valeria)
student(Alice)
student(Vijay)
// Relationships
subject(John, Mathematics)
subject(John, Computer Science)
subject(Ali, Mathematics)
subject(Valeria, Computer Science)
subject(Alice, Biology)
subject(Vijay, Biology)
Query:
// Queries subject relationships
// We follow the same order in which data is presented in the subject
relationships - students and then subject
// Expected output is a students/students, hence Student is written instead
of the name of a specific student and the first letter is capitalized
subject(Student, Mathematics)
Output:
John, Ali
Query:
subject(John, Subject)
Output:
Mathematics, Computer Science
Searching
- Linear Search
- Progress from beginning to end of array and check whether each element is
equal to the target value
Example
INPUT ValueToFind
Found ⟵ FALSE
Index ⟵ 0
MaxIndex ⟵ LENGTH(MyList) - 1
REPEAT
// Note: Check every single element in an array until you find the target value
IF MyList[Index] = ValueToFind THEN
Found ⟵ TRUE
ENDIF
Index ⟵ Index + 1
UNTIL Found OR Index > MaxIndex
IF Found THEN
OUTPUT "Value found at position ", Index
ELSE
OUTPUT "Value not found"
ENDIF
- Binary Search
- Can only be used with an array that is already sorted (by ascending or
descending order)
- Process (assuming an array is used)
1) Compare the target value with the value of the middle element of the
array.
2) If the values match, the value being searched for was found.
3) If the target value is less than the middle elements of the array, then the
action repeats for the value (sub-array) to the left of the middle element.
4) If the target value is greater than the middle element, it repeats on the
right of the middle element.
5) If the remaining array to be searched is empty, the target value was not
found.
Example
Sorting
- Factors for Sorting Algorithm Performance
- The initial order of the data
- The number of data items to be sorted
- The efficiency of the sorting algorithm
- Bubble Sort
- Process
- Goes through the array and compares each pair of elements.
- If ascending, swaps elements where the first element is greater than the
second. Otherwise, if descending, swaps elements where the first is less
than the second.
- Repeats the process, iterating through the entire array as many times as
is necessary until the array is sorted.
- Array will be traversed a maximum of n - 1 times, where n is the length of
the array
Example
Assume the existence of an array called Score with 250 integers that represent the scores of
250 students
NumberOfStudents ← 249
Flag ← TRUE
WHILE Flag = TRUE
Flag ← FALSE
FOR Student ← 1 TO NumberOfStudents - 1
IF Score[Student] < Score[Student + 1] THEN
Temp1 ← Score[Student]
Score[Student] ← Score[Student + 1]
Score[Student + 1] ← Temp1
Flag ← TRUE
ENDIF
NEXT Student
ENDWHILE
- Insertion Sort
- Steps
1. Start from the second element and consider it as the key.
2. Compare the key with elements in the sorted portion of the array.
3. Move elements that are greater than the key one position to the right.
4. Insert the key into the correct position.
5. Repeat until the entire array is sorted.
Example
Assume the existence of an array called Score with 250 integers that represent the scores of
250 students
NumberOfStudents ← 249
FOR Student ← 2 to NumberOfStudents
Temp ← Score[Student]
Counter ← Student
WHILE Counter > 1 AND Score[Counter - 1] < Temp
Score[Counter] ← Score[Counter - 1]
Counter ← Counter - 1
ENDWHILE
Score[Counter] ← Temp
NEXT Student
Recursion
- Must have a base case/stopping condition.
- Must have a general case which calls itself recursively, defined in terms of itself.
- The general case changes its state and moves towards the base case; unwinding
occurs once the base case is reached
Example
factorial(4)→
factorial(0) = 1
Big-O Notation
- Used to describe the amount of time required for an algorithm to complete some task,
based on size
- Used to describe the efficiency of the searching process on the A-level exam
- In Big-O notation, “n” is the number of terms to be searched
Examples
- Linear Search - O(n) - time to search increases linearly (think x = y) relative the the
number of elements (n) in an array that must be searched for a specific value
- Binary Search - O(log(n)) - time to search increases logarithmically relative to the
number (n) of elements in an array that must be searched
- time to search increases less rapidly based on size than for linear search, making
it a faster solution in some, but not all cases
Text File Handling
Example 1
CLOSEFILE "DestinationFile.txt"
CLOSEFILE "TargetFile.txt"
Example 2
CLOSEFILE "amith.txt"
OPENFILE "amith.txt" FOR READ
OPENFILE "destination.txt FOR WRITE
Queues
- Dynamic Data Structure
- FIFO (First in First Out) - the first element to be “enqueued” (inserted) is the last to be
“dequeued” (removed) like a real-life queue
Example
CONSTANT MaxLength = 50
DECLARE FrontPointer : INTEGER
DECLARE RearPointer : INTEGER
DECLARE Length : INTEGER
DECLARE Queue : ARRAY[0:MaxLength - 1] OF STRING
CONSTANT Capacity = 25
// Note: Index of bottom element in stack
DECLARE BasePointer : INTEGER
DECLARE TopPointer : INTEGER
// Note: Array used to represent stack
DECLARE Stack : ARRAY[1:25] OF REAL
// Note: Check if stack is full - the number of elements in the representative array is equal to the
size of the array
FUNCTION StackFull() RETURNS BOOLEAN
IF TopOfStack = Capacity THEN
RETURN TRUE
ELSE
RETURN FALSE
ENDIF
ENDFUNCTION
Order First in last out (FILO) / Last First in first out (FIFO)
in first out (LIFO)
Ends Has only one accessible end Has two accessible ends
Linked Lists
- Consists of nodes that are linked to each other by “pointers”
- Head is first node in linked lists and tail is last node
- The tail’s pointer leads nowhere
- Each node contains of some data and a pointer, which is really the memory address of
the next node in the linked list and can be used to access that node
Example
A linked list can be represented on the A-Level exam by 2 arrays, like in the example below.
1 James 7
2 Alice 10
3 Shi 1 (Head)
4 Muhammad 8
5 Ignacio 6
6 Sumit 0 (Tail)
7 Diego 2
8 Nina 5
9 Fatima 4
10 Sofia 9
HeadPointer ← 3
Pointer ← HeadPointer
Found ← 0
// Note: Allows you to find a specific value in a linked list
OUTPUT "Enter a student name: "
INPUT StudentName
WHILE Pointer <> 0
IF LinkedList[Pointer] = StudentName THEN
Found ← Pointer
Pointer ← 0
ELSE
// Note: Use the indices in the NextPointer array to traverse the LinkedList and
move on the next node in the linked list
Pointer ← NextPointer[Pointer]
ENDIF
ENDWHILE
IF Pointer = 0 THEN
OUTPUT LinkedList[Found], " is found"
ELSE
OUTPUT "The student whose name you wanted is not in the list."
ENDIF