0% found this document useful (0 votes)
9 views176 pages

OCR GCSE Revision cards v2.1 Unit 2

The document outlines key concepts in computational thinking, algorithms, and programming techniques relevant to OCR GCSE Computer Science. It covers topics such as abstraction, decomposition, various search and sorting algorithms, programming constructs, and data handling techniques. Additionally, it discusses the importance of validation, input sanitization, and robust programming practices.

Uploaded by

schwarkjayden08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views176 pages

OCR GCSE Revision cards v2.1 Unit 2

The document outlines key concepts in computational thinking, algorithms, and programming techniques relevant to OCR GCSE Computer Science. It covers topics such as abstraction, decomposition, various search and sorting algorithms, programming constructs, and data handling techniques. Additionally, it discusses the importance of validation, input sanitization, and robust programming practices.

Uploaded by

schwarkjayden08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 176

Craig’n’Dave

OCR GCSE Computer Science


Terminology
Unit 2
© CraignDave Ltd
Computational thinking, algorithms and
programming
(02)
80 marks
1 hour and 30 minutes
Written paper
(no calculators allowed)
2.1 ALGORITHMS

Abstraction
2.1 ALGORITHMS

Including only the necessary details and leaving


out the unnecessary details when problem
solving.
2.1 ALGORITHMS

Decomposition
2.1 ALGORITHMS

Breaking a problem down into smaller sub-


problems, making the overall problem easier to
solve.
2.1 ALGORITHMS

Advantages of decomposition
2.1 ALGORITHMS

Making problems easier to solve.


Different people can work on different parts of
a problem, reducing development time.
Program components developed in one
program can be reused in other programs.
2.1 ALGORITHMS

Algorithmic thinking
2.1 ALGORITHMS

A way of getting to a solution


by identifying the steps needed.
2.1 ALGORITHMS

Binary search
2.1 ALGORITHMS

Identify the mid point in an ordered list.


Check if the item is the one to be found.
If it is then output and stop.
If it is less than the mid point, discard right list.
If it is more than the mid point, discard left list.
Repeat until item is found or no items left.
2.1 ALGORITHMS

Linear search
2.1 ALGORITHMS

Start at the first item of an unordered list.


Check if the item is the one to be found.
If it is then output and stop.
If not, select the next item in the list.
Repeat until item is found or no items left.
2.1 ALGORITHMS

Bubble sort
2.1 ALGORITHMS

Compare items 1 and 2 in a list.


Swap them if they are in the wrong order.
Compare items 2 and 3 in the list.
Swap them if they are in the wrong order.
Compare items 3 and 4 in the list…
Repeat until all the items in a list are checked.
Repeat until no more swaps are made.
2.1 ALGORITHMS

Merge sort
2.1 ALGORITHMS

Repeatedly split the list in half until each list


contains only a single item.
Combine two adjacent lists together by
comparing each item in the lists in turn,
inserting each item into the correct order in
the new list.
Repeat until one list is created.
2.1 ALGORITHMS

Insertion sort
2.1 ALGORITHMS

Take each item in a list in turn.


Insert the item into the correct position in a
new list or in the sorted portion
of an existing list.
Move the other items already in the new list as
necessary to make room for the new item.
2.1 ALGORITHMS

Pseudocode
2.1 ALGORITHMS

A language independent description of the


steps of an algorithm.
Intended for humans to design algorithms
before coding them.
2.1 ALGORITHMS

Flow diagram
2.1 ALGORITHMS

A method of designing algorithms before


coding using symbols.
2.1 ALGORITHMS
2.1 ALGORITHMS

Terminal flow diagram symbol.


Start of an algorithm.
End of an algorithm.
Start of a sub-routine.
2.1 ALGORITHMS
2.1 ALGORITHMS

Process flow diagram symbol.


Used to show changing variables.
Example use: counter = 5
2.1 ALGORITHMS
2.1 ALGORITHMS

Decision flow diagram symbol.


Used to show a program branch.
Yes and No arrows are used from this symbol.
Example use: IF counter = 5
2.1 ALGORITHMS
2.1 ALGORITHMS

Sub-routine call flow diagram symbol.


Used to show a call to a procedure or function
in another flow diagram.
2.1 ALGORITHMS
2.1 ALGORITHMS

Program flow symbol.


Used to show control passing between
connected shapes in a flow diagram.
2.1 ALGORITHMS
2.1 ALGORITHMS

Input/output flow diagram symbol.


Indicates an input from the user.
Indicates an output to the user.
2.2 PROGRAMMING TECHNIQUES

Variable
2.2 PROGRAMMING TECHNIQUES

A name for a memory location.


Temporarily holds a value that can change whilst the
program is running.
Variables have a data type:
Integer: whole number, Real: number with a fractional part.
Boolean: true or false, String: alphanumeric text.
2.2 PROGRAMMING TECHNIQUES

Constant
2.2 PROGRAMMING TECHNIQUES

A value that cannot change whilst the program


is running and is set when the program is
designed.
2.2 PROGRAMMING TECHNIQUES

Operator
2.2 PROGRAMMING TECHNIQUES

Plus: +
Minus: -
Multiply: *
Divide: /
E.g. score = score + 5
2.2 PROGRAMMING TECHNIQUES

Assignment
2.2 PROGRAMMING TECHNIQUES

Giving a variable or constant a value.


E.g. counter = 0
2.2 PROGRAMMING TECHNIQUES

The 3 basic programming constructs


2.2 PROGRAMMING TECHNIQUES

Sequence: executing one instruction after


another, one by one.
Selection: a program branch depending on a
condition (IF).
Iteration: repeating code in a loop.
Controlled either with a counter (FOR) or a
condition (WHILE).
2.2 PROGRAMMING TECHNIQUES

String manipulation commands


2.2 PROGRAMMING TECHNIQUES

LENGTH: to return the number of characters.


LEFT: to return the characters of the left.
RIGHT: to return the characters to the right.
SUBSTRING: to return part of a string.
E.g. “Hello”.substring(2,3) = “ell”
UPPER/LOWER: to convert upper/lowercase.
ASC/CHR: to convert number/character ASCII.
2.2 PROGRAMMING TECHNIQUES

File handling
2.2 PROGRAMMING TECHNIQUES

Remember to open the file for read/write/


append.E.g. file = OPENREAD(“data.txt”)
Use a while loop to read in all the data until
end of file is reached. E.g. WHILE NOT file.EOF
Remember to close the file. E.g. file.CLOSE
2.2 PROGRAMMING TECHNIQUES

Record
2.2 PROGRAMMING TECHNIQUES

A collection of related data items for one


entity.
E.g. Surname, Forename and Date of birth.
2.2 PROGRAMMING TECHNIQUES

SQL
2.2 PROGRAMMING TECHNIQUES

A language to return, define and manipulate


records in a database:
SELECT (which fields, * is a wildcard)
FROM (which tables)
WHERE (criteria) LIKE (% is a wildcard)
E.g. SELECT surname, forename FROM customers
WHERE surname LIKE ‘Jon%’ AND forename = ‘Sam’;
2.2 PROGRAMMING TECHNIQUES

Array
2.2 PROGRAMMING TECHNIQUES

A data structure for storing records in RAM.


One dimension Two dimension

index name score

0 Craig index 0 1 2

1 Dave 0 Craig 16 24
1 Dave 36 22

name(1) = “Dave” score(1,1) = 36


2.2 PROGRAMMING TECHNIQUES

Function
2.2 PROGRAMMING TECHNIQUES

A small piece of code.


May take parameters.
Returns a value.
Used to create a reusable component.
2.2 PROGRAMMING TECHNIQUES

Procedure
2.2 PROGRAMMING TECHNIQUES

A routine within a larger program.


Takes variables.
Used to produce structured code.
Does not return a value.
Easier to read and debug structured programs.
Can port code to other programs easily.
2.2 PROGRAMMING TECHNIQUES

Casting
2.2 PROGRAMMING TECHNIQUES

Converting a variable from one data type to


another.
E.g. variable entered as a string, but needs to
be an integer for calculation.
age = INPUT(“Enter your age: “)
age = INT(age)
2.2 PROGRAMMING TECHNIQUES

Boolean operator
2.2 PROGRAMMING TECHNIQUES

AND, OR, NOT


Used in conditions.
E.g. IF choice < “1” OR choice > “3”
2.3 PRODUCING ROBUST PROGRAMS

Validation
2.3 PRODUCING ROBUST PROGRAMS

Checking data input by the user meets specific


criteria/rules before processing.
Range check. E.g. between 1 and 31.
Type check. E.g. number not symbol.
Presence check. E.g. data has been input.
Format check. E.g. postcode is LLN(N) NLL.
2.3 PRODUCING ROBUST PROGRAMS

Input sanitisation
2.3 PRODUCING ROBUST PROGRAMS

Removing unwanted characters before


processing inputs.
E.g. additional spaces at the end of a string.
2.3 PRODUCING ROBUST PROGRAMS

Planning for contingencies


when writing programs
2.3 PRODUCING ROBUST PROGRAMS

Making sure the program does not crash if:


Division by zero.
File does not exist.
End of file reached.
Invalid data in file.
Out of disk space.
2.3 PRODUCING ROBUST PROGRAMS

Preventing input misuse


2.3 PRODUCING ROBUST PROGRAMS

Whitelists are all the valid data inputs a


program should accept. E.g. A, B, C in a menu.
Blacklists are invalid data inputs a program
should reject. E.g. /?* in filenames.
2.3 PRODUCING ROBUST PROGRAMS

Authentication
2.3 PRODUCING ROBUST PROGRAMS

Verifying a user identity before they can use a


program with username and password.
Strong passwords over a certain length with
symbols and mixed case are advised.
2.3 PRODUCING ROBUST PROGRAMS

Maintainability of programs
2.3 PRODUCING ROBUST PROGRAMS

Using descriptive variable names.


Comments explain sections of code.
Indenting makes it easy to see where
structures begin and end.
Conditions and iterations should be indented.
Code inside procedures/functions should be indented.
2.3 PRODUCING ROBUST PROGRAMS

Purpose of testing
2.3 PRODUCING ROBUST PROGRAMS

To check a program:
Meets the requirements.
Does not contain logic errors (bugs).
Has acceptable performance/usability.
Prevents unauthorised access.
2.3 PRODUCING ROBUST PROGRAMS

Iterative testing
2.3 PRODUCING ROBUST PROGRAMS

Each module of a program is tested


as it is developed.
2.3 PRODUCING ROBUST PROGRAMS

Final or Terminal testing


2.3 PRODUCING ROBUST PROGRAMS

Testing when the program is complete.


Testing that all the modules of a program work
together as expected.
Checking the program meets the expectations
of the user with real data.
2.3 PRODUCING ROBUST PROGRAMS

Syntax error
2.3 PRODUCING ROBUST PROGRAMS

Rules of the language have been broken.


The program will not run.
Examples include:
Variables not being declared before use.
Using assignments incorrectly. E.g. 2 + 2 = x
Keywords misspelt. E.g. PRNT(“Hello”)
2.3 PRODUCING ROBUST PROGRAMS

Logic error
2.3 PRODUCING ROBUST PROGRAMS

The program runs but


does not give the expected output.
2.4 COMPUTATIONAL LOGIC

Why data is represented in binary


2.4 COMPUTATIONAL LOGIC

Easy to store two states with electrical


components. E.g.
Charge or no charge (RAM).
Polarity of magnets (Hard disk).
Pit or land (CD-R/DVD-R).
2.4 COMPUTATIONAL LOGIC
2.4 COMPUTATIONAL LOGIC

AND gate
Ʌ symbol
0Ʌ0=0
0Ʌ1=0
1Ʌ0=0
1Ʌ1=1
2.4 COMPUTATIONAL LOGIC
2.4 COMPUTATIONAL LOGIC

OR gate
V symbol
0V0=0
0V1=1
1V0=1
1V1=1
2.4 COMPUTATIONAL LOGIC
2.4 COMPUTATIONAL LOGIC

NOT gate
¬ symbol
¬0 = 1
¬1 = 0
2.4 COMPUTATIONAL LOGIC

Truth Table

A
B D
C
2.4 COMPUTATIONAL LOGIC

A B C D
0 0 0 0

0 0 1 1

0 1 0 0

0 1 1 1

1 0 0 0

1 0 1 1

1 1 0 1

1 1 1 1
2.4 COMPUTATIONAL LOGIC

Truth Table

A
B D
C
2.4 COMPUTATIONAL LOGIC

A B C D
0 0 0 0

0 0 1 0

0 1 0 0

0 1 1 1

1 0 0 0

1 0 1 1

1 1 0 0

1 1 1 1
2.4 COMPUTATIONAL LOGIC

Truth Table

A C
D
B
2.4 COMPUTATIONAL LOGIC

A B C D
0 0 0 1

0 1 1 0

1 0 1 0

1 1 1 0
2.4 COMPUTATIONAL LOGIC

Exponentiation
2.4 COMPUTATIONAL LOGIC

^ symbol
To the power of. E.g. 2^3 = 8
2.4 COMPUTATIONAL LOGIC

MOD
2.4 COMPUTATIONAL LOGIC

Modulus
Returns the remainder from a division.
E.g. 6 mod 2 = 0
E.g. 7 mod 2 = 1
E.g. 11 mod 3 = 2
2.4 COMPUTATIONAL LOGIC

DIV
2.4 COMPUTATIONAL LOGIC

Integer division
Returns a whole number only from a division
without rounding.
E.g. 7 DIV 2 = 3
E.g. 10 DIV 4 = 2
2.5 TRANSLATORS AND FACILITIES OF LANGUAGES

High level language


2.5 TRANSLATORS AND FACILITIES OF LANGUAGES

Source code is aimed at humans.


Structure and syntax similar to English.
Must be translated to machine code.
Translates to many different machine types.
Large number of instructions.
2.5 TRANSLATORS AND FACILITIES OF LANGUAGES

Low level language


2.5 TRANSLATORS AND FACILITIES OF LANGUAGES

Written in assembly language.


Much harder to write than high level source
code because of reduced set of instructions.
Computers assemble to machine code.
Translates to one type of machine.
Used for speed critical and embedded systems.
2.5 TRANSLATORS AND FACILITIES OF LANGUAGES

Translator
2.5 TRANSLATORS AND FACILITIES OF LANGUAGES

Translates source code written in a


high level language into machine code.
Translates assembly code written in a
low level language into machine code.
Examples include compiler, interpreter &
assembler.
2.5 TRANSLATORS AND FACILITIES OF LANGUAGES

Assembler
2.5 TRANSLATORS AND FACILITIES OF LANGUAGES

Converts low level code into machine code.


Each mnemonic instruction is converted into a
binary instruction.
E.g. STA 12 becomes 0011 1100
(store the value in accumulator to
memory address 12)
2.5 TRANSLATORS AND FACILITIES OF LANGUAGES

Compiler
2.5 TRANSLATORS AND FACILITIES OF LANGUAGES

Converts source code to machine code for


high level languages.
+ Compiled code executes faster.
+ Compiled code is optimised.
- Code is recompiled after every change.
- Errors in the code can be harder to spot as
the code will not run at all.
2.5 TRANSLATORS AND FACILITIES OF LANGUAGES

Interpreter
2.5 TRANSLATORS AND FACILITIES OF LANGUAGES

Interprets high level code line by line into


machine code.
+ Easier to debug code.
+ Code will run on any machine with an
interpreter. E.g. Java virtual machine.
- Interpreted code executes more slowly.
- Code is not optimised.
2.5 TRANSLATORS AND FACILITIES OF LANGUAGES

IDE
2.5 TRANSLATORS AND FACILITIES OF LANGUAGES

Integrated development environment.


Features include:
Code editors to enable program code to be entered.
Error diagnostics for debugging.
Run-time environment to test and run the program.
Translator to convert high level code to machine code.
2.5 TRANSLATORS AND FACILITIES OF LANGUAGES

IDE code editing features and debugging tools


2.5 TRANSLATORS AND FACILITIES OF LANGUAGES

Help with keywords and colouring code.


Automatic indentation.
Highlight syntax errors in the code.
Syntax error messages.
Breakpoints to stop code at a certain point.
Variable lists and value tracing.
Stepping onto next line of code.
2.6 DATA REPRESENTATION

Bit
2.6 DATA REPRESENTATION

Binary digit.
0 or 1
2.6 DATA REPRESENTATION

Nibble
2.6 DATA REPRESENTATION

4 bits
Half a byte.
2.6 DATA REPRESENTATION

Byte
2.6 DATA REPRESENTATION

8 bits
Can represent one character using ASCII.
2.6 DATA REPRESENTATION

Kilobyte
KB
2.6 DATA REPRESENTATION

1024 bytes
Can be approximated to 1000 bytes.
Remember kilo means thousand.
2.6 DATA REPRESENTATION

Megabyte
MB
2.6 DATA REPRESENTATION

1024 kilobytes
Can be approximated to 1,000,000 bytes.
Remember mega means million.
2.6 DATA REPRESENTATION

Gigabyte
GB
2.6 DATA REPRESENTATION

1024 megabytes
Can be approximated to 1,000,000,000 bytes.
Remember giga means billion.
2.6 DATA REPRESENTATION

Terabyte
TB
2.6 DATA REPRESENTATION

1024 gigabytes
Can be approximated to 1,000,000,000,000
bytes.
Remember tera is a million, million.
2.6 DATA REPRESENTATION

Petabyte
PB
2.6 DATA REPRESENTATION

1024 terabytes
Can be approximated to
1,000,000,000,000,000 bytes.
Remember peta is a thousand million, million.
2.6 DATA REPRESENTATION

Convert denary numbers 0 - 255


into 8 bit numbers
Convert 8 bit numbers
into 0 - 255 denary numbers
2.6 DATA REPRESENTATION

Use a number line:

128 64 32 16 8 4 2 1

0 0 1 1 0 1 1 0 = 54

1 0 0 0 1 1 1 0 = 142

1 1 1 1 1 1 1 1 = 255
2.6 DATA REPRESENTATION

Add two 8 bit numbers


2.6 DATA REPRESENTATION

Use a number line and show carries:

128 64 32 16 8 4 2 1

0 0 1 1 0 1 1 0 54

1 0 0 0 1 1 1 0 142 +

1 1 0 0 0 1 0 0 = 196
1 1 1 1 1
2.6 DATA REPRESENTATION

Arithmetic overflow
2.6 DATA REPRESENTATION

When there are insufficient bits to store the


result from addition due to a final carry bit.
128 64 32 16 8 4 2 1

0 0 1 1 0 1 1 0 54

1 1 0 0 1 1 1 0 206 +

1 0 0 0 0 1 0 0 = err
1 1 1 1 1 1 1
2.6 DATA REPRESENTATION

Binary shift
2.6 DATA REPRESENTATION

Left shift multiplies by 2.


Right shift divides by 2.

128 64 32 16 8 4 2 1

0 0 1 1 0 1 1 0 = 54

0 1 1 0 1 1 0 0 left

0 0 0 1 1 0 1 1 right
2.6 DATA REPRESENTATION

Convert denary number 0 - 255 into


hexadecimal
2.6 DATA REPRESENTATION

Write the number in binary.


Split into two nibbles.
Convert each nibble into hexadecimal.
0-9, A=10, B=11, C=12, D=13, E=14, F=15
128 64 32 16
8 4 2 1
8 4 2 1

1 1 0 1 0 1 1 0 = 214
D 6
2.6 DATA REPRESENTATION

Convert 2 digit hexadecimal into denary


2.6 DATA REPRESENTATION

Change each hexadecimal digit into a nibble.


0-9, A=10, B=11, C=12, D=13, E=14, F=15

Convert 8 bits of binary to denary.

E A

8 4 2 1 8 4 2 1

1 1 1 0 1 0 1 0 = 234
2.6 DATA REPRESENTATION

Check digit
2.6 DATA REPRESENTATION

A calculation on data to create a number


included with the data for error checking.
E.g. check digit = sum of digits DIV 3:
12345 (data) 15/3 = 5 (check digit)
= 123455.
When the number is input the check digit is
recalculated to check it matches.
Therefore valid data entry can be assumed.
2.6 DATA REPRESENTATION

Character set
2.6 DATA REPRESENTATION

A defined list of characters recognised by the


computer hardware and software.
Each character is represented by a number.
Two common character sets are ASCII and
Unicode.
E.g. Letter A is number 65 or 01000001.
2.6 DATA REPRESENTATION

Relationship between the number of bits and


the number of characters in a set
2.6 DATA REPRESENTATION

The number of characters is equal to 2 to the


power of the number of bits.
7 bits = 27 = 128 characters (ASCII).
8 bits = 28 = 256 characters (extended ASCII).
32 bits = 232 = 4 billion characters (UNICODE).
2.6 DATA REPRESENTATION

How bitmap pictures are stored


2.6 DATA REPRESENTATION

Each colour has a unique binary value.


Every pixel is stored with the binary number.
The more colours the 11 11 11 11 11
more bits are required 11 01 01 01 11
per pixel. 11 01 10 01 11
11 01 01 01 11
Used for photographs.
11 11 11 11 11
2.6 DATA REPRESENTATION

Metadata
2.6 DATA REPRESENTATION

Additional data stored with an image


Examples include:
Width and height of image.
Number of bits per pixel (colour depth).
Colour palette.
2.6 DATA REPRESENTATION

Effect of colour depth and resolution on the


size of an image file
2.6 DATA REPRESENTATION

The greater the resolution the greater the file


size. The greater the colour depth the greater
the file size. Multiply all the factors together.
E.g.
32x32 at 2 bit colour = 2,048 bits.
64x64 at 2 bit colour = 8,192 bits.
64x64 at 8 bit colour = 32,768 bits.
2.6 DATA REPRESENTATION

How sound is sampled and stored


in digital form
2.6 DATA REPRESENTATION

At each sample point the analogue value (black dot) is


stored as the closest bit depth value (black line)
using an analogue to digital converter.
40
30
Bit depth

20
10
0
1 2 3 4 5 6
Sample rate
2.6 DATA REPRESENTATION

Sound sample size


2.6 DATA REPRESENTATION

The total number of bits in a sound.


Bit rate multiplied by the sampling frequency.
2.6 DATA REPRESENTATION

Sampling frequency
2.6 DATA REPRESENTATION

Number of samples stored per second.


2.6 DATA REPRESENTATION

Bit depth / Bit rate


2.6 DATA REPRESENTATION

The number of bits used to store each sample.


The higher the number the better the quality.
The higher the number the larger the file size.
CD quality is 24 bits per sample.
2.6 DATA REPRESENTATION

The need for compression


2.6 DATA REPRESENTATION

To reduce the number of bits in a file.


Making data transfer of the file quicker.
Making the storage capacity of the file lower.
2.6 DATA REPRESENTATION

Lossy compression
2.6 DATA REPRESENTATION

Greatly reduces file size.


Some of the data is lost.
Reducing the quality of the sound/image.
Cannot be used on text or software files.
E.g. JPEG, video files, mp3 sound files.
2.6 DATA REPRESENTATION

Lossless compression
2.6 DATA REPRESENTATION

Partial reduction in file size.


None of the data is lost, it is encoded in a
different way.
Can be turned back into original format.
Can be used on images, text and programs.
E.g. PNG, zip files.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy