Data types, data structures and algorithms Flashcards
What is a string?
A collection of characters
1 nybble=
1 nybble = 4 bits
The least significant bit of a binary number is the one furthest to the…
right
BINARY ADDITION
0+0+0=
0+0+1=
1+1+0=
1+1+1=
0+0+0=0
0+0+1=1
1+1+0= 10 (0 carry 1)
1+1+1= 11 (1 carry 1)
Explain sign magnitude
A way of representing negative numbers in binary
Ignore most sig bit and convert remaining bits to decimal then change the sign
e.g 10101101 =173
1 10101101 = -173 (1 for negative)
0 10101101 = +173 (0 for positive)
Explain two’s compliment
Its a way of representing negative numbers in binary
This is done by making the most significant bit negative
eg 7 = 00000111
In two’s complement
-7=-128+64+32+16+8+1
=11111001
What is an easy way of converting a number to two’s complement?
Flip the bits in the positive version and adding one
eg 7 = 00000111
In two’s complement
=11111000 then add one
=11111001
Number bases
Decimal = base 10
Binary = base 2
Hexadecimal = base 16
HEX conversion values
0-9 = 0-9
A-F = 10-15
Convert hex 4E7F into decimal
16^3 : 4 (4X4096)
16^2 : E (14X256)
16^1 : 7 (7X16)
16^0 : F (15X1)
(4X4096) + (14X256) + (7X16) + (1X15)= 20095
Convert hex B2 into decimal
16x11 =B
1X2= 2
(16X11) + (1X2) 178
OR
B=11 2=2
11=1011 2=0010
COMBINE: 10110010
10110010=178
Can be split into 2 parts mantissa and exponent
What is this?
Floating point binary numbers
Why does floating point binary need to be normalised?
To make sure they are as precise as possible in a given number of bits
(meaning making use of as much mantissa as possible)
To normalise number make sure it starts with:
01 for positive num
10 for negative num
What is meant by a character set?
A published collection of characters and corresponding codes which can be used by computers for respresenting text
2 examples of character sets are ASCII and Unicode
Give examples of character sets
ASCII and Unicode
ASCII
Example of a character set
-Uses 7 bits (2^7= 128 characters)
-Capital A-Z=65-90
-Lower a-z= 97-122
-Also has codes to represent other symbols and numbers
-Can only represent characters in English language
UNICODE
-Uses a varying number of bits
-Better than ASCII as it can represent more characters meaning that it can be used for more different languages rather than just English
-Can represent letters, numbers, symbols, emojis….
What is an array?
An ordered, finite set of elements of a single type
-Taken to be zero-indexed (first index 0) unless stated in question
Linear array = 1D
What is a record made up of?
Row in a file made up of fields
-eg used in databases
Lists can contain elements of more than one data type
TRUE OR FALSE
TRUE
(Unlike arrays)
What is a list?
A data structure consisting of a number of ordered elements where each element can occur more than once
(ordered because the elements retain the sequence in which they were added until you change them)
A difference between lists and arrays is that the values in a list are stored non-contiguously.
What does this mean?
Non contiguous = The values don’t have to be stored in consecutive memory locations. Each element of a list can be in different places in memory.
(rather than arrays as they have to be next to eachother in memory)
Give ways to process graphs
-Adjacency matrix
-Adjacency list
Give advantages of using adjacency matrices
-Ea
Give advantages of using adjacency lists
-Better to work with for large, sparse graphs
What is meant by sparse graph?
A graph in which the number of edges is relatively small compared to the number of POSSIBLE edges among the vertices.
(small edge to vertex ratio)
LESS EDGES