0% found this document useful (0 votes)
12 views9 pages

OCR A-Level Computer Science Spec Notes - 1.4 Summarized

The document covers key concepts in data types, data structures, and algorithms relevant to A-Level Computer Science, including primitive data types, binary representation, and floating-point arithmetic. It also details various data structures such as arrays, linked lists, and trees, as well as Boolean algebra and its applications in logical expressions. The content is structured to provide foundational knowledge for understanding computer science principles and practices.

Uploaded by

ninja0990
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)
12 views9 pages

OCR A-Level Computer Science Spec Notes - 1.4 Summarized

The document covers key concepts in data types, data structures, and algorithms relevant to A-Level Computer Science, including primitive data types, binary representation, and floating-point arithmetic. It also details various data structures such as arrays, linked lists, and trees, as well as Boolean algebra and its applications in logical expressions. The content is structured to provide foundational knowledge for understanding computer science principles and practices.

Uploaded by

ninja0990
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/ 9

OCR A-Level Computer Science Spec Notes

1.4 Data types, data structures and algorithms


1.4.1 Data Types
(a) Primitive data types
Data types (All stored in the computer in Binary):
- Integer: Single whole number e.g (5,37,-102)
- String: A sequence of alphanumeric characters e.g (3A*s)
- Real: Numbers with decimal/fractional components e.g (3.14, 0.6)
- Character: Single digit/letter/symbol e.g (s,G,9,&)
- Boolean: Used to represent Binary logic (True/False, 0/1)

(b) Represent positive numbers in binary


- Binary is a base 2 number system whereas denary has a base 10
- To convert from Binary -> Denary (How I personally do it) I will convert 200 to denary:
● Create this nifty table (It looks btec but still) (apparently called the tabular method
according to Teach ICT) :
128 64 32 16 8 4 2 1

1 1 0 0 1 0 0 0
● Firstly we know 128 goes into denary so put a 1 under 128 in the table
● Then do 200-128 = 72. Now 64 goes into 72 once so put a 1 in that
● Now do 72-64 = 8. 32 & 16 don't go into 8 but 8 does do put a 1 in there
● Fill the rest of the boxes with 0
● Finito (Answer: 11001000)
● To summarize, keep subtracting and seeing whether the numbers in the top row
go into the subtracted value. It’s hard to explain just practice lmao.

(c) Sign and magnitude & two's complement for negative numbers
Sign & Magnitude:
- In denary, store a sign bit, a ‘+’ or ‘–’ as part of the number
- Simply use the most left-handed bit, to store these as a binary value, 0 for + and 1 for –

Corresponding Steps (example 127 & -127)


Sign Bit 64 32 16 8 4 2 1

0 (+) 1 1 1 1 1 1 1
= 127

Sign Bit 64 32 16 8 4 2 1

1 (-) 1 1 1 1 1 1 1
=-127
Two's Complement: An easy method for subtraction (Overpowered if use correctly):
1. Convert subtraction number into binary
2. Start from most right and keep all values the same until you reach the first ‘1’. Then after
that switch ‘1’s with ‘0’s and ‘0’s for ‘1’s’
3. Add the binary numbers and discard the overflow

Corresponding Steps (example Convert 75-35)


1. 35 in Binary = 00100011
2. 11011101 (-35)
3. Add 75 therefore (75+(-35)) = 01001011 + 11011101 = 0101000

(d) Addition and subtraction of binary numbers


Binary Addition (Check answer by doing in denary then converting)
- 0+0=0 / 1+0=10 (0 but carry 1 to next calc) / 1+1 = 11 (1 but carry 1 to next calc)
Binary Subtraction (Check answer by doing in denary then converting)
- 1-0=1 / 1-1=0 / 10- 1 = 1

(e) Represent positive numbers in hexadecimal


Hexadecimal uses a Base 16 Number System (4 bit system as 24=16)
- Same as denary upto 9 then letters are used where:
● 10=A/11=B/12=C/13=D/14=E/15=F

(f) Convert positive integers between binary, denary and hex


Denary-> Binary (E.g Convert 81 to Binary)
- Refer to (b) Represent positive numbers in binary
Binary -> Denary (E.g Convert 0101 1010 to Denary)
- Plug in Binary numbers into Nifty Table
128 64 32 16 8 4 2 1

0 1 0 1 1 0 1 0
- Just add the numbers which have a 1 below them (64+16+8+2 = 90)
Binary -> Hexadecimal (E.g Convert 0101 1010 to Hexadecimal)
- Split byte into 2 nibbles (0101 1010)
- Convert each nibble separately into Hexadecimal (0101 = 5 / 1010 = 10 = A)
- Combine the result together: 5D
Denary -> Hexadecimal
- Convert Denary into Binary
- Follow instructions for: Binary -> Hexadecimal
Hexadecimal -> Binary
- Split each Hex letter/number up
- Convert each letter/number into binary equivalent
- Join binary up again
Hexadecimal -> Denary
- Follow instructions for: Hexadecimal-> Binary
- Convert Binary into Denary
Alternate Way
- multiply each corresponding Hex digit with increasing powers of 16
3B = 3×161+11×160 = 48+11 = 5910

(g) Representation and normalisation of floating point numbers (Mantissa is normally 5 bits &
exponent is 3. Question will tell you if it changes)
Floating Point Numbers: A way of storing decimals in Binary
1. If a number is positive/negative, look at the first binary digit: 0 =positive, 1 = negative
2. Split into mantissa and exponent.
3. Use the exponent to float the binary point back into place (put decimal point after first
number)
4. Convert to denary.

Negative Values:
1. Split into mantissa and exponent.
2. Evaluate the exponent
3. Move the binary point one place to the left (If exponent is -1 for example)

The number of bits chosen for the mantissa & exponent affects the range and the accuracy of
the values that can be stored:
- If more bits are used for the mantissa = more accurate values.
- But the range is limited by the small exponent.
- If more bits are used for the exponent, = range of values stored is greater.
- But the accuracy is limited by the smaller mantissa.

(h) Floating point arithmetic, +ve, -ve, addition, subtraction


Addition of Floating Point Numbers (E.g 01011 001 + 01100 010)
1. Figure out what the exponents of the 2 bytes ( 001 = 1 & 010 =2)
2. Shift Mantissas according to exponents (010110 -> 01.011 & 01100 = 011.00)
3. Add digits together (01.011 + 11.00 = 100.011)

Subtraction of Floating Point Numbers


1. Figure out what the exponents of the 2 bytes ( 001 = 1 & 010 =2)
2. Shift Mantissas according to exponents (010110 -> 01.011 & 01100 = 011.00)
3. Add digits together (01.011 + 11.00 = 100.011)
(I) Bitwise manipulation and masks
Bitwise manipulation: The CPU is able to shift and mask binary to complete a range of
operations.
- Binary can be logically shifted left/right
- Shifting Left = *2 & Shifting Right = /2
- E.g Shifting 0001 (1) to the left = 0010 (2) & 1*2=2
Masking: Data used for bitwise operations. Using a mask (Byte/Nibble/bit etc) can be altered by
a bitwise manipulation.
- NOT performs a bitwise swap of values in a binary number (0 -> 1 & 1 -> 0)
- AND excludes bits by placing a 0 in the appropriate bit in the mask
● (0 AND 0 =0 / 0 AND 1 = 0 / 1 AND 1 = 1)
- OR resets bits by placing a 1 in the appropriate bit in the mask.
● (0 OR 0 =0 / 0 OR 1 = 1 / 1 OR 1 = 1)
- XOR checks if corresponding bits are the same.
● (0 XOR 0 =0 / 0 XOR 1 = 1 / 1 XOR 1 = 0)

(j) Character representation (ASCII and UNICODE)


Character Set
- Normally equates to the symbols on the keyboard that are represented by the computer
by unique binary numbers and may include control codes
- Number of bits used for one character is 1 byte
- number of characters tend to be a power of 2 and uses more bits for an extended set.
ASCII (American Standard Code for Information Interchange)
- ASCII is a 256 character set which is based on a 8-digit binary pattern (7 bits + parity bit)
- The limited character set makes it impossible to display other characters & symbols
outside the English alphabet
UNICODE
- UNICODE was originally a 16-bit coding system but now has over 65000
- Updated to remove the 16-bit restriction by using a series of code pages with each page
representing the chosen language symbols.
- Original ASCII representations are included with the same numeric values

1.4.2 Data Structures


(a) Arrays (3D), records, lists, tuples
Arrays
- Data structure which contains a set of data items of the same data type grouped
together under a single identifier
- Static data structure (Size can’t change)
- Each element can be accessed & addressed quickly by accessing the index/subscript
- Stored contiguously in memory
- Multi dimensional (1D (Spreadsheet), 2D (Table), 3D (Multiple Tables))
Records
- Data stores organised by attributes (fields) containing one item of data
Lists
- Abstract data type where the same item can occur twice
- Data stores organised by an index
Tuples
- Ordered set of values which are immutable (can’t be modified)
- Multiple data types stored as it’s similar to a list

(b) Linked lists, graphs, stack, queue, tree, binary search tree, hash table
Linked Lists
- Dynamic data structure
- Uses index values/pointers to sort lists in specific ways
- Can be organised into more than one category
- Needs to be traversed until desired element is found
- To add data: data added to the next available space & pointers adjusted
- To remove data: Pointer from previous item set to item that will be removed which
bypasses the removed item
- The contents may not be stored contiguously in memory.
Graphs
- Set of vertices/nodes connected by edges/arcs
- Can be represented by an adjacency matrix
- Edges can be:
● directional or bi-directional
● directed or undirected
● weighted or unweighted
- Searched by breadth/depth first traversal
Stack
- LIFO (Last In First Out)
- 2 pointers (Top/bottom) Top Pointer = Stack Pointer
- Data is added (PUSH) and removed (POP) from the top of the stack
- Stack overflow: When data is trying to go into stack but stack is full
Queue
- FIFO (First In First Out)
- 2 pointers (Start/End) Start Pointer = Queue Pointer
- Data is added (enqueue) from end & data removed (dequeue) from the top of queue
Tree
- Are dynamic branching data structures.
- They consist of nodes that have sub nodes (children).
- The first node at the start of the tree (root node)
- The lines that join the nodes are called (branches)
Binary search tree
- Each node has a maximum of 2 children from a left branch and a right branch.
- To add data to the tree, it is placed at the end of the list in the first available space and
added to the tree following the rules:
● If a child node is less than a parent node, it goes to the left of the parent.
● If a child node is greater than a parent node, it goes to the right of the parent.
Hash table
- Enable access to data that is not stored in a structured manner.
- Hash functions generate an address in a table for the data that can be recalculated to
locate that data.

1.4.3 Boolean Algebra


(a) Defining a problem using Boolean logic
Boolean Logic
- NOT (Negation) Symbol: ¬ (e.g if A=0 -> ¬A =1 / A=1 -> ¬A = 0)
- AND (Conjunction) Symbol: ^ (e.g if A=1 & B=1 -> A^B =1 Otherwise A^B = 0 )
- OR (Disjunction) Symbol: v (e.g if A=1 / B=1 -> AvB =1 Otherwise AvB = 0 )
- XOR (Exclusive Disjunction) Symbol: v (e.g if A=1 / B=1 (Not other)-> AvB =1 Otherwise AvB
=0)
- NAND (Conjunction) Symbol: ¬(A ∧ B) (e.g if A=1/0 & B=1/0 -> AvB = 0/1 Otherwise AvB =
1)
- NOR (Disjunction) Symbol: ¬(A V B) (e.g if A=1/0 & B=1/0 -> AvB = 1/0 Otherwise AvB = 0 )

(b) Manipulating Boolean expressions (Karnaugh maps)


Karnaugh maps
- Are a visual method for simplifying logical expressions.
- They show all the outputs on a grid of all possible outcomes (Truth Table)
- The method is to create blocks of 1s as large as possible so that the 1s are covered by as
few blocks as possible and no 0s are included.
- The blocks can wrap around the diagram if necessary, in both directions, from side to
side or from top to bottom.

The rules for using Karnaugh maps:


- No 0s (zeros) allowed & diagonal blocks
- Larger groups the better
- Every 1 must be within a block
- Overlapping blocks allowed
- Wrap around blocks allowed
- Aim for smallest possible groups Karnaugh Map

(c) Simplifying statements in Boolean algebra using rules


Equivalence / Iff (if and only if)

Symbol (AND):
- ≡ e.g. (A ∧ B) ≡ ¬(¬A V ¬B) ------> (A AND B ≡ NOT (NOT A OR NOT B))

Alternative notations (XOR):


- e.g. (A ⊻ B) ≡ (A ∧ ¬B) V (¬A ∧ B) ------> (A XOR B ≡ (A AND NOT B) OR (NOT A AND B))

Boolean algebra
There are rules, similar to arithmetic (Statistics if you take A-level Maths), for manipulating
Boolean expressions:
Boolean Rule Boolean Expression Description

De Morgan’s ● ¬(A V B) ≡ ¬A ∧ ¬B ● A NOR B ≡ NOT A AND NOT B


laws ● ¬(A ∧ B) ≡ ¬A V ¬B ● A NAND B ≡ NOT A OR NOT B

Distribution ● A ∧ (B V C) ≡ (A ∧ B) V (A ● A AND (B OR C) ≡ (A AND B) OR (A AND


∧ C) C)
● A V (B ∧ C) ≡ (A V B) ∧ (A ● A OR (B AND C) ≡ (A OR B) AND (A OR C)
V C)

Association ● (A ∧ B) ∧ C ≡ A ∧ (B ∧ ● (A AND B) AND C ≡ A AND (B AND C)


C) ● (A OR B) OR C ≡ A OR(B OR C)
● (A V B) V C ≡ A V (B V C)

Commutation ● A∧B≡B∧A ● A AND B ≡ B AND A


● AVB≡BVA ● A OR B ≡ B OR A

Double ● ¬(¬ A) ≡ A ● NOT(NOT A) ≡ A


Negation

Simplification AND AND


Expressions ● A∧A≡A ● A AND A ≡ A
(1 = True ● A∧0≡0 ● A AND 0 ≡ 0
0 = False) ● A∧1≡A ● A AND 1 ≡ A
● A ∧ ¬A ≡ 0 ● A AND NOT A ≡ 0

OR OR
● AVA≡A ● A OR A ≡ A
● AV0≡A ● A OR 0 ≡ A
● AV1≡1 ● A OR 1 ≡ 1
● A V ¬A ≡ 1 ● A AND NOT A ≡ 1

Absorption ● A V (A ∧ B) ≡ A ● A OR (A AND B) ≡ A
● A ∧ (A V B) ≡ A ● A AND (A OR B) ≡ A
(d) Logic gate diagrams and truth tables
Logic Gates: Building block of a digital circuit used to implement Boolean functions
Truth Table: Mathematical table used with logic gates to list out all possible scenarios of the
corresponding logic gate(s)

Logic Gates Examples:


Type of Boolean Diagram Truth Table
GATE Expression
AND A∧B

OR AVB

NOT ¬A

NAND ¬(A ∧ B)
A B ¬(A ∧ B)

F F T

F T T

T F T

T T F

NOR ¬(A V B)

A B ¬(A V B)

F F T

F T F

T F F

T T F

XOR A⊻B

(e) D type flip flops, half and full adders


D type flip flops
- Store the state of a data bit in RAM
- D = Delay
- 2 Inputs: data(D) & clock
- 2 Outputs: the delayed data (Q) and the inverse
of the delayed data (¬Q)
Half Adders
- Half adders logic circuit with 2 inputs & outputs
- The sum (S) is an XOR gate (A XOR B)
- The carry (C) is an AND gate (A AND B)

Full adders
- Combination of half adders to make a full adder
- The sum (S) is an XOR gate
- The carry (C) is an AND gate
- A B and Cin are added together = The result is given in the sum (S) N And a carry bit in
Cout
Series of full adders combined together allows computers to add binary numbers.

You might also like