Systems Architecture -
• The CPU performs the FDE cycle (fetch, decode, execute)
- This is followed by a processor to process an instruction. The memory address held in the PC is
copied into the MAR. The address in the PC is then incremented by one, so now holds the address
of the next instruction.
- The processor sends a signal along the address bus to the memory address held in the MAR. The
instruction is sent along the data bus to the MDR. This is copied into the CIR. This is decoded and
executed. Results are stored in the ACC.
- The cycle then repeats back to step one.
• Factors that affects CPU performance:
- Clock speed: Sends out pulses in fixed intervals, measured in Hertz. Higher clock speed means
more FDE cycles per second.
- Cache size: Fast memory that stores frequently used instructions and data. Reduces time lost
whilst waiting to retrieve data from RAM.
- Number of cores: Number of processes that can happen at one time. Cores carry out FDE cycles,
more cores more instructions processed at one time. Only benefits in programs that can use multiple
cores. If lower clock speed but more cores, may still be faster.
• Components of a CPU:
- Control Unit (CU): Sends control signals around the CPU that control hardware.
- Registers: Small amounts of high speed memory that store data.
- Cache: Very fast memory that stores frequently used instructions so they don’t have to be fetched
(saves time).
- ALU (arithmetic logic unit): Performs calculations and logic checks.
• Registers:
- MAR (Memory Address Register): Holds address of current instruction to be fetched or to be
transferred.
- MDR (Memory Data Register): Holds contents found at address in the MAR, or data to be
transferred.
- PC (Program Counter): Holds memory address of next instruction to be fetched from primary
memory.
- ACC (Accumulator): Holds results of calculations from the ALU.
• An embedded system is a system built inside a larger device to perform a specific task. The
opposite is a general-purpose system such as a laptop (multiple purposes e.g. using the
internet). An example of an embedded system is a washing machine, drone, kettle, toaster, etc.
• Software licensing:
- Open source (e.g. Linux, Python): Program/application where the source code is available to the
public. It can be edited by users for their own purpose (a derivative) and is free, giving advertising
and a reputation. Many authors can contribute.
- Proprietary (e.g. Windows, Microsoft Office): Copyrighted software, can only be used with a paid
license (usually). The source code cannot be seen or modified. Usually free of bugs due to
development (regular bug patches). Support available, updates/patches online information such as
video guides to use it.
• Primary storage:
- Primary storage stores programs and data currently in use. They are loaded from the disk to
primary storage.
- ROM (read-only memory) is a non-volatile memory (retained after power is turned off). It is stored
permanently and stores the BIOS (basic input output system) and boot-up sequence. BIOS has
instructions that load the OS from secondary storage to RAM.
- RAM (random access memory) temporarily stores data/programs/instructions currently in use by
the CPU. It is volatile meaning data is lost when the PC is turned off. It is much faster than
secondary storage so much more expensive.
• Secondary storage:
- Secondary storage is used for long-term storage of data/programs when not immediately needed.
It remains when the PC is turned off. Stores backups if original is damaged/destroyed.
- Magnetic (e.g. Hard drives, tapes, floppy disks): Large capacity for a low price. Reliable but not
robust due to moving parts. Slower R/W speeds.
- Solid state (e.g. SSDs, flash drives/USBs): Very fast speed, robust and portable (as no moving
parts), large capacity. However quite expensive.
- Optical storage (e.g. CDs, DVDs, blu-ray): Cheap and small capacity, low R/W speeds, unreliable
as prone to scratching.
- Factors to consider: Cost, capacity, speed, portability, durability, reliability.
• Units (denary, binary, hexadecimal):
- Bit, nibble (2 bits), bytes (8 bits), KB, MB, GB, TB, PB. Multiple or divide by 1000 to get between
each.
- Data needs to be in binary format to be understood by a computer as it works in on/off switches.
Transistors with two states.
- A shift multiplies or divides a number by 2. Shift left = x2. Shift right = /2.
- Hex: 10 = A, 11 = B, 12 = C, 13 = D, 14 = E, 15 = F.
• Characters:
- Each character is represented with a unique binary code.
- A character set is all of the characters that can be represented in a computer system.
- ASCII = 8 bits in character, 2^8 (256) possible characters.
- Unicode = 16 bits in character. 2^16 (65,536) possible characters. Enough to represent multiple
languages and emojis.
- Images are represented with pixels. The number of pixels is the resolution. The number of bits per
pixel is the colour depth.
- Metadata is data about data such as resolution, colour depth, file size, file type, author, height in
pixels, width in pixels.
- Larger colour depth = more bits per pixel = more possible colours = larger file size = better image
quality.
- Bitmap images are made up of individual pixels. For black and white it is just on and off (1 and 0),
however coloured imaged need additional binary code to store the colour. The more bits available to
store a colour, the higher the colour range (colour depth).
• Sound -
- Whole sound is known as a sample. Measured by taking a measurement of the height of the wave
at regular intervals (sample rate, Hertz) and storing it as binary code.
- A sound wave/sample is converted into the nearest binary equivalent.
- The sample rate is the number of samples in a given time (Hertz, Hz). Higher rate = closer to
original value = larger file size.
- The duration is the length of an audio (in seconds).
- The bit depth is the number of bits to record each sample (usually between 16 and 24). Higher bit
depth = higher quality = bigger file size.
- Sound must be converted into digital (0,1) to be processed (sampling). The height of a sound
wave is its amplitude.
- Size of sample = sample rate x bit depth x duration
• Compression:
- Files are compressed to reduce file size so they take up less space in secondary storage and
are faster to upload/download (and use less bandwidth).
- Lossy compression is used for image, video and sound. It results in permanent loss of data
that cannot be restored, resulting in a smaller file size. For example, it can lower the resolution
or bit depth. The removal of data is not noticeable to us. RRR à R.
- Lossless compression is used for text files or programs. Data can be restored to its original
quality. It results in a larger file size compared to lossy. RRR à 3R.
• Networks:
- A LAN is a network in one building or site (over a small geographical area). A WAN is in a wide
geographical area and has communication/data sharing. The internet is an example of a WAN.
- The internet is a collection of computer networks. Is has a client-server model (data hosted on a
server, accessed by clients). These servers include web servers (web content), mail servers
(web-based email), media servers (streaming music and videos).
- Hosting refers to the storing of files and data in a web server. The URL (uniform resource locator)
for a website consists of three hierarchical levels in reverse order. Includes the root (e.g. .com, .uk,
.net), the organisation (.co, .org, .sch, .ac) and the organisation name (e.g. bbc, ocr, Microsoft,
apple). These create unique domain names.
- Domain name servers (DNS): Every website has an a network address such as [Link].
Addresses like this are hard to remember so we use domain name servers instead. Users enter the
domain name as a URL. The browser sends it to the DNS and finds the corresponding network
address, linking it to an IP. The user’s request is then forwarded to corresponding server.
- Factors that affect the performance of a network: Number of devices on a network, bandwidth of
transmission media, type of traffic, network latency (delay), number of transmission errors.
- Bandwidth is the amount of data that can be transferred over a given period of time.
- Latency is how long it takes for a message to travel from one device to another across a network.
- Transmission errors are when devices try to communicate at the same time and their signals fail.
• Wired vs wireless networks:
- Wired networks: Installation costs can be expensive and requires technical knowledge and space
to install cables. Up to 1GB/s for Ethernet. Up to 100 metres range for reliable communication, or
2km for fibre optic. It is more secure as a physical connection is required to intercept data. However,
not portable/can’t move about due to cables. Could create a tripping hazard.
- Wireless networks: Cheaper to set up, devices can easily connect if in the range of a WAP.
Installation is simple as most devices are wifi-capable already. Maximum transmission speed of
50MB/s. Up to 50m reliable communication range. Less secure as wireless signal cannot be
contained within a building and no physical connection is needed to intercept data.
- Bluetooth: Enables two devices to connect, small private network. Often used to connect wireless
devices such as keyboards, mice, speakers or smartphones to a car’s multimedia system. It is
simple, however transmission is often limited to 2MB/s and has a small range.
• In a peer to peer network (P2P), all computers have equal status. No computer has control over
the network. There are no servers or clients. Best suited to small organisations.
- Advantages: Simple to set up and cheap as no server. Not reliant on a server (could go wrong).
Perfect for quickly sharing files/data.
- Disadvantages: No central device to manage security or backups. Performance will decrease if
more devices are connected.
• A client server separates computers into servers and clients. A server manages and stored files or
provides services (file application, web, print, mail). Clients rely on servers to provide and manage
data. Suited to organisations with many computers.
- Advantages: Can be controlled centrally to easily backup data and update software. Improved
scalability, more clients easily added to central server.
- Disadvantages: Traffic congestion causes it to slow down, if a fault in server then the whole
network fails, IT technicians need to maintain it, malware can spread quickly across.
• Local area network hardware:
- To connect a computer to a network, you need an NIC (network interface controller, ethernet card),
a transmission medium (wired or wireless, ethernet or WIFI), and a point to connect to (router, hub,
switch, WAP).
- A network interface controller offer an interface port for a wired connection or a radio transceiver
for connecting wirelessly. Most devices already have them.
- Transmission media carries data from one computer to another. Wired include twisted copper
wires (cheap, up to 1GB/s, up to 100m reliably) and fibre-optic cables (expensive, 10GB+/s, 100km
reliably). A wired device has to stay in place.
- Wired connections use radio waves which are limited in range (up to 50m) but are subject to
magnetic interference and can be blocked by walls.
- A hub is a small device allowing wired devices to connect to a network. They have no knowledge
of devices connected. Any traffic is transmitted to all computers connected resulting in unnecessary
signals.
- Switches are similar to hubs but record which computers are connected to which port and forward
traffic to its intended recipient only. This improves network performance.
- A wireless access point uses a radio transceiver to allow wireless connections. It creates its own
wireless network, then sends traffic to the main network. Can extend the range of a network.
Receives and transmits data, or connected via a cable.
- Routers send data signals across the internet. They collect knowledge of available routes. Also
commonly used in homes, containing a hub and a WAP creating a small P2P network. Has a modem
which connects users via a telephone line.
- Switches and routers both connect devices, determine the correct destination, and transmit to
destination. A switch uses MAC addresses, routers use IP addresses. A switch connects nodes
(devices), router connects networks. Router stores addresses of devices, switch has to look for
correct address.
• The cloud allows people to remotely access storage through the internet on a server. It can also
offer software facilities such as spreadsheets (ideal for low powered devices).
- Advantages: Can access from any location with an internet connection. Access can be granted to
other users for collaboration. Reduced need to create backups.
- Disadvantages: Less security of data, no guarantee data is backed up is someone else isn’t using
it. Requires an internet connection.
• Star topology: Any device connected is a ‘node’. In star all nodes connect to each other through a
central hub or switch.
- Advantages: Each node connected separately therefore failure of one does not affect others. New
nodes can be added simply by connecting to the switch. Tends to have high performance as data
only sent to intended recipient.
- Disadvantages: If switch fails, the whole network fails. Wired which required a lot of cable
(expensive).
• Mesh topology: Each node connected to 1+ other node, sends and receives to others. They act as
relays, passing to its final destination. Types include full mesh (every node interconnected) and
partial mesh (only some connections, fewer routes so simpler to implement). Popular due to
efficiency. Wired mesh is uncommon. Used where reliability is important (military, emergency
services, etc.).
- Advantages: Messages can be received quickly is route is short, should always get through as
there’s many possible routes, multiple connections means no node is isolated, each node can
transmit to and receive from more than one node at once, new nodes can be added without
interruption.
- Disadvantages: Impractical to set up because high number of connections. Requires a lot of
maintenance.
• System Threats -
- Malware: Malicious software to hack a system/ cause harm. Use anti-malware software, don’t click
on suspicious links.
- Social engineering: Exploiting human weaknesses to gain access to a system. Ensure phone calls
are verified/safe.
- Phishing: Emails sent by criminals to steal login details (and therefore money). Contains links
or attachments and pretends to be someone else (e.g a bank).
- Brute force attack: Using trial and error (often through programs/bots) to guess a password.
To prevent use a strong password.
- Denial of service (DoS) attacks: Overloading a server with requests making it difficult to
respond to genuine requests. DDoS is distributed (uses multiple computers/machines). To
prevent use firewalls to block suspicious traffic.
- Data interception and theft: Using a packet sniffer (monitors network traffic) to intercept
personal data, or via shouldering (stealing data over someone’s shoulder). Encrypt your data.
- SQL injection: Using SQL to gain entry to a website’s database. Typing code into a web form.
To prevent do penetration testing to find weaknesses.
• Prevention Methods -
- Penetration testing – Determines how resilient a network is through testing for potential
weaknesses.
- Anti-malware software – Detects, prevents and removes malicious software. Scans files and
compares to a database of virus definitions. If found, quarantines and deletes. Database regularly
updated.
- Firewalls – Monitors traffic going in and out of a computer/network and can block it based on rules
for legitimate cause.
- User access levels – Determines the facilities a user has access to (e.g. software, internet,
settings). The network manager controls this.
- Passwords – Verify if a user is who they say they are. However often forgotten. Should be secure
with 8+ characters, numbers and symbols to prevent brute force attacks.
- Encryption – Disguising/scrambling data so it cannot be understood if intercepted or gained
access to. It requires the use of a key to unscramble it. Turns plaintext into cyphertext.
- Physical Security – Includes methods such as use of CCTV, security guards and locked doors.
• Asymmetric encryption: Extra security method for encryption where it generates two keys – a
public and private one. A public key can be given to another to encrypt a message, but cannot
decrypt it. The private key is used to decrypt it. Online banking makes use of this.
• An example of it in use is for purchases made online (to prevent theft of credit card details). Tools
enable a user to encrypt a document such as a spreadsheet before it is send. Satellite TV
transmissions are encrypted to prevent users who are not subscribed from watching TV shows.
Protocols:
• A protocol is a set of rules for how messages are turned into data packets and sent across
networks.
• IP Addresses: When connected to a network each device is given a unique IP address consisting
of four sets of up to three digits, each with a maximum value of 255. For example, [Link].
Static always has the same address, dynamic changes every time it connected to a network.
- 4 sets of digits is known as IPv4 and allows for up to 4.3 billion addresses. The huge increase in
internet devices has seen it begin to run out of addresses. IPv6 has eight sets of four digit
hexadecimal values y:y:y:y:y:y:y:y. This gives it 340 trillion trillion trillion possible addresses.
• MAC addresses: Unique serial number assigned to each NIC, allowing a network to uniquely
identify any device. A string of hexadecimal numbers, for example 1A:5B:6H:98:87:35.
• Comparison: IP across multiple devices, MAC limited to one. IP 4 bytes, MAC 6 bytes. IP denary,
MAC hex. IP configured by software, MAC configured by hardware. IP can be changed, MAC
cannot. IP for WAN routing, MAC only on LAN.
• Other protocols include…
- TCP/IP (Transmission Control Protocol/Internet Protocol): Enables communication over the
internet.
- HTTP and HTTPS (Hypertext Transfer Protocol): Governs communication between a webserver
and a client. HTTPS include secure encryption to allow transactions over the internet.
- FTP (File Transfer Protocol): Governs the transmission of files across a network and the internet.
- SMTP (Simple Mail Transfer Protocol): Governs the sending of emails over a network to a mail
server.
- POP (Post Office Protocol) and IMAP (Internet Message Access Protocol): Govern retrieving
emails from email servers. POP is older, largely replaced by IMAP.
• Layering involves breaking up the sending of messages into separate components and activities.
Each component handles a different part of the communication. This can be referred to as the
TCP/IP model.
• Layering allows standards to be developed over time and for them to be adapted to new hardware
and software.
• Application (encodes/decodes), transport (breaks down into packets, assemble, missing, number),
network (adds IP addresses/destination), link (transfer of packets between nodes and networks).
• A standard is an agreed set of specifications of use in computers (hardware or software). They
make it possible for manufacturers and producers to create products and services which are
compatible with each other. Example include: HTML (on the WWW), ASCII / Unicode, IEEE,
Ethernet and file type (PDF, PNG, MP3, etc.).
• Operating Systems -
- Memory Management and Multitasking – Appears that multiple processes are occurring at once.
Programs move in and out of memory, temporarily stored in RAM. Programs given small allocated
run time by CPU.
- Peripheral Management and Drivers – Interface to interact with external input/output devices with
the CPU. Drivers provide the interface to communicate with them.
- User Management – Make, create and delete accounts with different permissions. Users granted
different access rights (guest, admin).
- File management – Logical system to organise files. Name, open, copy, save, delete files.
Properties.
- User interface – Interact with computer, interface including widgets and tasks on a toolbar.
• Legislation -
- The Data Protection Act 2018 – Keeps personal data private. Personal data must be processed,
relevant, accurate, not kept longer than needed, handled safely and for legitimate purposes.
- Computer Misuse Act 1990 – Illegal to access data without permission (hacking), for criminal use
(e.g. fraud) and to make changes to data without permission (e.g. writing a virus).
- Copyright Designs and Patents Act 1988 – Owning a creation (e.g. a game, book, music,
software). Exclusive legal rights. License given out for use. Illegal to make copies, sell, distribute
without permission. Creative commons means it can be used without permission but credit may
need to be given.
• Defragmentation -
- Defragmentation groups files/programs together and puts free space together, decreasing the time
the disk has to spend loading/saving. R/W speeds are improved. Makes it so they run contiguously.
Files and programs are stored in “blocks” and become fragmented when they’re removed and added
over time. Files are saved and deleted leaving gaps. When a file bigger than the gap is saved it is
separated/fragmented. SSDs do not need to be defragmented as electrical storage works different to
magnetic.
- Defragmentation improves efficiency as it takes less time to access the file as data is contiguous,
so does not need to move as far to reach the next piece of data (next memory location). It takes less
time to save new data as there’s larger free space together so it doesn’t need to split it.
• Utility software is used to keep a computer running with maximum efficiency. Many OS contain
built-in utility programs and can also be purchased as third-party software.
• Backups should be made (a copy of data). Network managers make regular backups with software
at scheduled times of the day, usually when the network is quiet. Made to high capacity secondary
storage or to the cloud. If data loss occurs it can be retrieved. Incremental backups take a copy of
any new files or those that have been edited.
8 mark question -
• Write as much as possible, attempting to include positives and negatives for each bullet point.
Incorporate own knowledge. Waffle, go into detail about points. Sentence starters (e.g. a negative
ethical issue is…).
• Examples of topics that could come up…
- Healthcare – Use of AI to diagnose illness, poorer nations cannot afford technology.
- Social Media – Great for keeping in touch, can be used for bullying/trolling.
- Environment – Networking removes need for travel, waste/pollution from manufacturing tech (e.g.
precious rare metals used in technology).
- Driverless cars – Can auto-navigate and do not get tired on long journeys, but could cause
accidents (especially if not ALL cars are driverless and connected).
- The ratings culture – Easy to find, share opinions. People can become obsessed with perceptions.
- Privacy issues – Do you own your data? Should government and law enforcement have complete
access? Should you allow the use of cookies?
- News – Lots of up to date news sources, which are real or fake?
- AI/robotics – Can do repetitive tasks well, will it replace humans?
Computer Science Notes -
- ‘Pseudocode’ for us just means to write in Python.
- Abstraction is the removal of unnecessary details and focusing on necessary detail to
reduce the complexity of a problem.
- Decomposition is breaking a program down into smaller sub-programs so it is easier
to solve.
- An algorithm is a set of instructions for a problem.
- Input is getting a value entered from a user ---> = input(“
- Process is doing something in a program ---> e.g. x = x + 2
- Output is printing something to the screen ---> print(“
- A variable is a location in memory that stores a value. Has a datatype. Has an
identifier. Can change whilst the program is running.
- A constant is a value that cannot be changed whilst the program is running. Rarely
used or seen.
- Assignment gives a value to a variable ---> e.g. password = [Link](0,5)
- Sequences: The ordering of instructions to ensure programs flow correctly.
- Selection: Use of IF, ELSE statements.
- Iteration: 2 types of iteration: Count controlled and condition controlled loops.
--> Count for when you know how many times you want to loop (for). ‘Range’ is the
amount of times you want to repeat it. The ‘i’ is a new variable created by the iteration.
EXAMPLE 1: for i in range(10): / print(i) – This code prints number 0-9.
EXAMPLE 2: count = int(input(“Loop amount?”)) / for i in range(count): / print(i) – Prints
a specified amount of numbers.
EXAMPLE 3: for i in range(1,11): / print(i) – Prints numbers 1-10.
EXAMPLE 4: name = input(“name”) / for letter in name: / print(letter) – This prints each
individual letter in a name.
EXAMPLE 5: If it says ‘for x = 1 to num’, it goes upto the amount of num and then ends
the loop.
EXAMPLE 6: for i in range(5): - Just repeats the following code 5 times.
--> For when you don’t know how many times you want to loop (while, do until).
- while ....: OR while True: /// ‘endwhile’ to end the code.
- You could also do ‘while NOT’.
Datatypes:
- String: Series of characters or numbers. Includes “ “ (blank space).
- Integer: A whole number.
- Float: A decimal number.
- Boolean: True or false.
- Character: A single character.
- Casting involves change a variable’s data type. For example, making an integer into a
string ---> new = str(old)
- Concatenation involves joining strings together ---> part 1 = abc // part2 = c //
print(part1 + str(part2))
- Boolean operators: AND, OR, NOT
- High levels languages such as python are close to English language. They have to be
translated into machine code to be understood by a computer. They are portable from
machine to machine.
- Low levels language (“machine code”) such as binary is specific to one machine. It
does not need to be translated as written for a specific computer.
- Translators turn high level code into low level code (machine code) to be understood
by a computer.
- A compiler translates all code in one go. It gives an error log at the end. It creates a
separate .exe file – this can only be ran so others cannot access source code. Doesn’t
need to be translated again when ran from .exe.
- An interpreter translates programs line by line and stops when an error is found. Great
for debugging.
- Three SQL query commands: SELECT, FROM, WHERE
- SQL is a database. A database holds records (rows). Records contain fields
(columns). SQL communicates with a database and can manipulate and retrieve data.
- SELECT is the name of the row, * is used to select all, can select multiple fields.
FROM is the name of the table. WHERE is a specific requirement such as ‘age < 10’.
- An array is a data structure storing multiple values in a list. They have elements with
positions. Indexing starts at zero.
--> Example: names = [“Josh”, “Ben”, “Olivia”, “Luke”]
--> To print the first position --> print(names[0])
--> ‘array colours[5]’ creates a 1D array with 5 elements (index 1 to 4).
- A 2D array contains groups of values linked to each other within one variable.
--> Example: P2S1Grades = [[“Maths”,”4”],[“Science”,”2”]]
--> To print: print(P2S1Grades[1][0]). The first is the position in the list. The second is
the indexing (inside of the position). So this would print “Science”.
Other ways to print:
- print(len(film)) - Length of a string. Spaces count as a character.
--> The following are known as ‘string slicing’.
- print(film[2:5]) - 2nd to 5th position – make sure you include 0 as first.
- print(film[:3]) - From start to that position.
- print(film[7:]) – From that position to the end.
- print(film[-1]) – Outputs the last character in a string.
- print([Link]()) OR print([Link]()) – Prints string fully in lowercase or uppercase.
- Two types of sub-programs: Functions and procedure.
- Sub programs are blocks of code that are reusable, small in size and easy to test.
- A function returns a value (‘return’) and a procedure does not.
- ‘def’ gives a chunk of code a variable, so you can repeat it multiple times without
re-typing the whole thing.
- Advantages:
--> You are able to reuse code without repeating it so it’s quicker to write.
--> You can test procedures or functions separately without having to test the whole
program, allowing for easily debugging.
--> They make programs shorter and easier to read and understand, making them
more maintainable.
--> The file size is smaller which uses less RAM so improves memory efficiency.
--> Example:
- def multiply(n1,n2): //// These are global variables – the parameters that you use.
- followed by code...
- return ... /// brings local variable back to global variable (local more efficient as uses
less RAM).
- You can then input the values that you want for the sub-program and do ‘multiply(n,y)’.
- Printed as... x = newprice(5,”Premium”) / print(x)
Example 1:
def multiply(n,y):
x = n * y
print(x)
return x
n = int(input("enter n"))
y = int(input("enter y"))
multiply(n,y)
Example 2:
def calculate(length,width):
area = length * width
return area
- Generating a random number:
import random
x = [Link](1,7)
print(x)
Truth tables: How many possible inputs are there for a logic gate with 2 inputs: 2^2 = 4
/// for 3 inputs: 2^3 = 8.
- A truth table determines all the possible inputs and their corresponding outputs.
- Validation is an automatic computer check to ensure data entered is sensible and
reasonable. It does not check accuracy of data.
Maintainability of a program – Means it is easily readable and understood by others:
- Sensible variable names – Naming of variables and sub programs identify what their
purpose is.
- Commenting – Useful to explain what a program does that may not be obvious.
- Indentation – Easier to see when it falls into selection, iteration, etc. and when the
program ends. Required for it to run.
- Use of sub programs
Searching Algorithms -
--> Binary Search
- The list needs to be in order (this can be alphabetical, numerical) – prerequisite.
- Take the middle value (if no middle, round up). Check if same as value you’re looking
for.
- If correct, stop. If larger than value you’re looking for, remove values to the right. If
smaller than value looking for, remove values to the left.
- Find a new middle point and repeat until the item is found.
- More memory efficient.
--> Linear Search
- Doesn’t need to be in order.
- Check the first value. If it is value looking for, stop.
- Else, move to next and check if value is correct.
- Repeat until checked all values or it is found.
- Slower than binary as binary halves (especially useful for longer lists, more memory
efficient) , whereas linear checks every value.
- Positives: Easier to code, doesn’t require it in order, could be quicker if near start of
data set.
Sorting Algorithms -
--> Bubble Sort
- Repeatedly steps through a list of data, comparing each pair of data it comes across
and swaps if the order is wrong. Position of focus moves one every time.
- Each movement through a full set of data is called a ‘pass’. If often needs multiple
passes.
--> Insertion Sort
- Steps through a list of data for each item it finds and compares itself with the previous
item(s) of the set.
- Works best with smaller data sets.
--> Merge Sort
- Data is split into individual items. Each pair (2) compared and sorted.
- Each pair of sorted are sorted into sets of 4. Continually comparing the left most items
and adding the smallest to a new list.
- Items compared and sorted into set of 8 in the same way. Continue this process.
To design programs defensively:
- Anticipate misuse and use authentication.
- Examples of misuse: Brute force attack. This can be rectified through ability to identify
when a user inputs the same data (spam) or nonsense data or the data is too long or
short.
- Authentication (checking of someone is who they claim to be): Username and
password, biometrics (fingerprint, face id), 2FA (2 factor authentication), CAPTCHA (test
for bots).
Input Validation: When data is entered into a program, validation checks to ensure it is
sensible and reasonable. It cannot check for mistakes as the user can lie.
- Type check – Checks if it is the correct data type.
- Range check – The data falls within a specified range (e.g. 1-10).
- Length check – The data isn’t too much or too short.
- Others: Format check (formatting such as date), presence check, lookup check (in a
table).
- Whitelists store all valid data inputs that a program should accept.
- Blacklists are invalid data that it should reject, for example /,?,* in file names.
Testing -
- Syntax error – An error in the grammar of the program that stops it from running -->
e.g. misspelling of ‘print’.
- Logical error – Program will run but won’t perform as expected --> e.g. looping
incorrect amount of times.
- Iterative testing is used to test your program as you develop it.
- Final or terminal testing is carried out after a program is written. It is a final check to
make sure a program works correctly.
- Testing is completed in a test plan that sets out data entered, type of test data,
expected outcome, result of test, action required.
Test data -
- Normal – Data that should be accepted, correct data type --> e.g. HENRY
- Boundary – Accepted but on edge of being accepted --> e.g. LI
- Invalid – Rejected but of the correct data type --> e.g. A
- Erroneous – Rejected by program and of wrong data type --> e.g 52566
Reading and Writing to a file -
- First create the text file. Use the function ‘open()’ so we can write to it. We always
need to open it before doing anything to it.
- Make sure to always use the same variable such as ‘newfile’ with every one of your
commands.
--> newfile = open(“The New [Link]”, “W”)
--> newfile = open(“[Link]”, “a”)
- Ensure you include .txt as this is the file format.
- ‘W’ starts writing to the file. After writing once, it will erase/restart if this code is
repeated. So we use ‘a’ instead to append it.
--> [Link](“Hello\n”).
--> [Link](film1)
--> [Link](“\n”)
- Put \n inside the speech marks at the end to continue writing on a new line. Don’t put
this for the last line added. Must be backslash - \.
- After we have written to the file we need to close it.
--> [Link]()
- To read a file and store the content of it in a variable:
newfile = open(“The New [Link]”, “r”)
namesinfile = new[Link]()
[Link]()
print(namesinfile)
- Or to just print:
print([Link]())
IDE (Integrated Development Environments):
- Writing large programs can be a complex tasks so to help the programmer write clear,
error-free, maintainable code, tools exist such as:
--> Editors, run-time environments, automatic line numbering, error trapping,
breakpoints, variable tracing, interpreters.
- Brands of IDE exist such as: IDLE in python, visual studio for C# and Visual Basic,
eclipse and Netbeans for Java, Javascript, HTML.
- Editors are software which allow programmers to write and edit code. They provide:
Automatic line numbering, auto-correct, auto-suggestion, auto-indent, colour coding.
They help to improve readability of code but don’t identify errors.
A Runtime environment (RTE) is special software that allows a program to run on a
computer, even if not designed to run on it.
- It creates a virtual machine in order to run a program. This is an emulation of a
computer system. This means a programmer can concentrate on program development
rather than understanding how different computer systems actually work. A common
RTE is the Java Runtime Environment (design on one platform, run on many).
- A runtime error occurs as the program is being executed, such as dividing by zero.
- It enables tools debugging tools such as tracing and breakpoints to work.
- Debugging tools help programmers to locate and fix errors.
- Breakpoints enable a program to be paused or stopped at predetermined points so
they can examine different parts of it. This tells them whether it’s working as expected.
- Variable tracing lets the programmer see the changing values of variables as the
program runs. This enables the programmer to check if it functions as expected.
- Some IDEs pinpoint exactly where a syntax error occurs or which line it is generated
at. This is known as error trapping.
Trace tables can be used to spot logic errors and test the accuracy of an algorithm.
OCR Reference Language -
- “switch” to open selection, “case” as use of IF/ELIF, “default” as use of else.
- Comment = //
- Converting to other data types: str(), int(), float(), real(), bool()
- For loop = for, to, next
- While loop: While, endwhile
- DO WHILE loop: do... until...
- ‘step 2’ prints even numbers.