1.4 Data types, data structures and algorithms Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What are the different types of data? (5)

A

-integer
-boolean
-real/floating point
-character
-string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is an integer data type?

A

whole numbers (includes 0 and -ve numbers)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a boolean data type?

A

values which are restricted to true and false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a real/floating point data type?

A

+ and -ve numbers which can also be fractional/decimal numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a character data type?

A

a single symbol used by the computer
-include the letters A to Z, the numbers 0 to 9 and hundreds of symbols like % and £

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a string data type?

A

a collection of characters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How are integers stored on computers? How does this work?

A

-stored using binary
-computers count in base 2
-0 is just to show an ‘empty space’ whereas the 1 shows the number which the integer will consist of [0= false, 1=true]

128 64 32 16 8 4 2 1
-the row above shows the place value of each digit of the number (remember computers count in base 2 e.g. 2^2, 2^3)

-if the binary code beneath consists of 1 then the integer will be made up of the place value above the 1
e.g.
128 64 32 16 8 4 2 1
0 1 0 0 1 1 0 1

64+ 8 +4 +1 = 77

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Explain how we can convert the binary code into denary

A

128 64 32 16 8 4 2 1
0 1 0 0 1 1 0 1

-the row below is the binary code which can be converted into an integer by adding the numbers which have a value of 1

-in this case we add 64, 8, 4 and 1 as they have a place holder value of 1 which gives a number of 77

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Explain how we can convert denary into binary code

A

-first step: find the largest power of two which is smaller than the number you’re converting, then write up the place values in power of 2 up to this power
e.g. , if we were converting the decimal 47 into binary, we would write out place values up to 32

32 16 8 4 2 1

-then, place a 1 or a 0 in each position so that the total adds up to 47 starting with the most significant bit (32)
-if we write a 1, then we subtract the place value from
our value and use the result for the next stage e.g. 47-32= 15
-as 16 is larger than 15 a 0 will be used as an empty space/false number so we move on to the next numbers and continue the steps until we reach the final bit and the number is complete

32 16 8 4 2 1
1 0 1 1 1 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the four rules when adding binary code?

A
  1. when adding 0 + 0 it always gives a 0
  2. when adding a 0 + 1 it always gives a 1
  3. when adding 1 + 1 you carry the one to the next addition and instead place a zero
  4. when adding a 1 +1 + 1 you carry the one to the next addition and instead place a 1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do we add binary code together?

A

-line up digits
-start from right hand side (least significant bit)
-add values from each column whilst following the rules
-if the value has an overflow error (having an extra digit at the end), write out the code with the extra digit noting the error
-convert value into denary to check if calculation is correct

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the two methods which can represent negative numbers in binary?

A

-sign and magnitude
-two’s complement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Explain how sign and magnitude works

A

-equivalent of adding a + or - sign in front of a number
-binary can only use 0s and 1s, so instead we represent the signs using 0 as positive and 1 as negative.

e.g. [010101101] = 173
[110101101] = -173

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How can we convert from sign and magnitude into denary and vice versa?

A

-same as converting normally from binary to denary and vice versa
-only difference is adding the sign at the end of the largest significant bit for binary and adding a +/- to a denary number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Explain how two’s complement works

A

-works by making the most significant bit negative e.g., the most significant bit, usually 128, represents -128
-add place values as normal
e.g.,
-128 64 32 16 8 4 2 1
1 1 1 1 1 0 0 1
so: -128 + 64 + 32 +16 + 8 +1= -7

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How can we add binary numbers using two’s complement?

A

-flip the first number (all 0s turn to 1 and vice versa)
-add as a normal binary

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is hexadecimal?

A

makes use of the characters A-F to represent numbers 10-15

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Show the conversions between denary and hexadecimal

A

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <—-DENARY
0 1 2 3 4 5 6 7 8 9 A B C D E F <—-HEXADECIMAL

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How do we convert hexadecimal into binary and vice versa?

A

B2
-split into two characters –> B 2
-convert both into denary –> 11 2
-convert denary into binary
-combine both binary sections into one

-for vice versa, split the binary into sections of 4 bits and do the opposite

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How do we convert hexadecimal into denary and vice versa?

A

-first convert hexadecimal into binary
-convert binary into denary

-do opposite for vice versa

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

How can floating point numbers be shown in binary?

A

-can be split into two parts: mantissa and exponent
e.g., 6.63 x 10^-11
mantissa is 6.63 and exponent is -11

-the last bit next to the most significant bit shows the sign (remember 0 is positive and 1 is negative sign)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How does the mantissa and exponent work in binary?

A

-the mantissa is always taken to have the binary point (same as a decimal point)
[as the mantissa is considered a binary point the binary number e.g. 1100100111 becomes 1.100100111]

-the exponent is used to show the shift of how many places the decimal point moves and in which direction

-mantissa comes first then the exponent (which will also have the smaller bytes)

e.g. 6.63 x 10^-11
mantissa is 6.63 and the exponent is -11
so the decimal point will be shifted 11 times from the decimal point to give us 0.0000000000663

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

How do we convert the a floating point number into denary?

A

-convert exponent into denary using the normal method
-as the mantissa is considered a binary point the binary number e.g. 1100100111 becomes 1.100100111
-move the binary point the required number of places that the exponent gives (e.g. moving the binary point 5 places to the right of the mantissa)

-this mantissa can then be converted to the denary version
[REMEMBER for the place values in decimal, the computer counts in base 2s so it goes on as 2^-1, 2^-2 etc)

[REMEMBER WITH TWO’S COMPLEMENT IF THE INIRIAL BIT IS A NEGATIVE THE MOST SIGNIFICANT PLACE VALUE IS A NEGATIVE]
e.g.
32 16 8 4 2 1 . 0.5 0.25 0.125 0.0625
1 1 0 0 1 0 . 0 1 1 1

32 + 16 + 2 + 0.25 + 0.125 + 0.0625 = 50.4375

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Give the decimal place values for binary. Explain how we get these numbers

A

0.5
0.25
0.125
0.0625

[REMEMBER for the place values in decimal, the computer counts in base 2s so it goes on as 2^-1, 2^-2 etc)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What does it mean if we normalise floating point numbers? What is shown to present a floating point number as normalised?

A

-making them precise as possible in a given number of bits
-to normalise a binary number, adjust it so that it starts 01 for a positive number or 10 for a negative number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

How can we normalise a floating point number?

A

-check if it is a positive or negative number
-split the number into its mantissa and exponent
-adjust the mantissa so it starts in 01 (for +) or 10 (for -)

-to adjust the mantissa to create a normalised number, move bits to the required number to the left and add zeros to the end of the mantissa

-then adjust the exponent so you still remain with the same number (as we move the bits to the left the mantissa becomes larger so we need to reduce the exponent by the number of bits moved)

e.g. if we move the bits two places to the left we subtract the exponent by two and replace it with what has been left
—–> 5 - 2 = 3 so the new exponent would be three

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

How do we add floating point numbers?

A

-the exponents need to be the same
-add mantissa’s together
-normalise answer if needed

if the exponents are not the same, they need to be modified to match
-to do this, we shift the bits of the mantissa to the right to the needed number of places until the exponent is modified to match the other (same as when we normalise)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

How can we subtract floating point numbers?

A

-make exponents the same
-the number which will be subtracted from the first needs to be flipped (converted to two’s complement)
-add both numbers together
-normalise answer if needed

if the exponents are not the same, they need to be modified to match
-to do this, we shift the bits of the mantissa to the right to the needed number of places until the exponent is modified to match the other (same as when we normalise)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What is a logical shift?

A

involves moving all of the bits in a binary number a specified number of places to the right or to the left

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

What happens to the number if a logical shift occurs?

A

multiplication (or division if shifting right) by two to the
power of the number of places shifted

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

What are the different masks that can be applied to binary calculations?

A

AND
OR
XOR

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

What does the AND mask do to a binary calculation?

A

all values must be true (1= true, 0 = false)

e.g.
if a calculation involves 1 and 0 the result would be 0
if a calculation involves 1 and 1 the result would be 1

if there is a false then the answer would be false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

What does the OR mask do to a binary calculation?

A

only one value needs to be true (1= true, 0 = false)

e.g.
if a calculation involves 1 and 0 the result would be 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

What does the XOR mask to do a binary calculation?

A

works the same as OR where the result is true if the calculation consists of 1 (1= true, 0 = false)

both values cannot be the same: the value must consist of 1 and 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

What is a character set?

A

a published collection of codes and corresponding characters which can be used by computers for representing text

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

What are two types of character sets?

A

ASCII
Unicode

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

Describe the ASCII character set

A

-stands for American Standard Code for Information Interchange
-7 bits to represent 2^7 = 128 different characters
-capital letters A-Z are represented by codes 65-90 while the lower case letters a-z correspond to codes 97-122

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

What is one issue that arose from using ASCII? What was used to fix this?

A

-became a disadvantage when computers needed to represent other languages with different characters
-Unicode was introduced to solve this

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

Describe the Unicode character set

A

-uses a varying number of bits allowing for over 1 million different characters
-has enough capacity to represent a wealth of different languages, symbols and emoji

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

What is an array? Describe its characteristics

A

-a data structure
-an ordered, finite set of elements of a single data type
-usually zero indexed unless told otherwise

can be 1D, 2D, 3D

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

What can a 1 dimensional array be called? Give an example

A

a linear array

e.g.
oneDimensionalArray = [1, 23, 12, 14, 16, 29, 12] //creates a
1D array

print(oneDimensionalArray[3])
» 14

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

Describe a 2 dimensional array. Give an example

A

-can be visualised as a table or spreadsheet
-when searching through a 2D array, you first go down the rows and then across the columns to find a given position

e.g.
twoDimensionalArray = [[123, 28, 90, 38, 88, 23, 47],[1, 23, 12,
14, 16, 29, 12]]

print(twoDimensionalArray)
» [[23, 28, 90, 38, 88, 23, 47],
[ 1, 23, 12, 14, 16, 29, 12]]

print(twoDimensionalArray[1,3]) // Goes down and then across
» 14

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

Describe a 3 dimensional array. Give an example

A

-can be visualised as a multi-page spreadsheet and can be
-in a 3D array requires the following syntax to be used: threeDimensionalArray[z,y,x], where z is the array number, y is the row number and x is the column number

e.g.
threeDimensionalArray = [[[12,8],[9,6,19]],[[241,89,4,1],[19,2]]]
print(threeDimensionalArray[0,1,2])
» 19

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

What is a record?

A

-a data structure
-commonly referred to as a row in a file
-made up of fields

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

What is a list?

A

-a data structure consisting of a number of ordered items where the items can occur more than once
-list values are stored non-contiguously (means they
do not have to be stored next to each other in memory)
-can also contain elements of more than one data type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q

What are the different operations used for lists? (9)

A

isEmpty()
append(value)
remove (value)
search(value)
length()
index(value)
insert(position, value)
pop()
pop(position)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
47
Q

What are the two differences between an array and a list?

A

-lists store data non-contiguously whereas arrays store data in order
-lists can store more than 1 data type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

What does the isEmpty() command do for a list? Give an example

A

checks if the list is empty

List.isEmpty()
» False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
49
Q

What does the append(value) command do for a list? Give an example

A

adds a new value to the end of the list

List.append(15)
»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
50
Q

What does the remove(value) command do for a list? Give an example

A

removes the value the first time it appears in the list

List.remove(23)
»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
51
Q

What does the search(value) command do for a list? Give an example

A

searches for a value in the list

List.search(38)
» False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
52
Q

What does the length() command do for a list? Give an example

A

returns the length of the list

List.length()
» 7

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
53
Q

What does the index(value) command do for a list? Give an example

A

returns the position of the item

List.index(23)
» 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
54
Q

What does the insert(position, value) command do for a list? Give an example

A

inserts a value at a given position

List.insert(4,25)
»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
55
Q

What does the pop() command do for a list? Give an example

A

returns and removes the last value in the list

List.pop()
»12

56
Q

What does the pop(position) command do for a list? Give an example

A

returns and removes the value in the list at the given position

list.pop(3)

57
Q

What is a tuple?

A

-a data structure
-an ordered set of values of any type is called a tuple
-a tuple is immutable (cannot be changed)
-uses normal brackets instead of square

58
Q

How can a tuple be accessed? Give an example

A

-accessed in the same way as an array

tupleExample = (“Value1”, 2, “Value3”)

print(tupleExample[0])
» Value1

59
Q

What are two differences between a tuple and an array?

A

-elements cannot be added or removed once it has been created (will result in a syntax error)
-initialised using regular brackets instead of square brackets

60
Q

What is a linked list?

A

a dynamic data structure used to hold an ordered sequence which are not stored in contiguous locations

61
Q

What is each item in a linked list called?

A

nodes

62
Q

What does each node in a linked list contain?

A

contains a field data and an address field called link/pointer

63
Q

What is a data field in a linked list?

A

a field that stores the actual data

64
Q

What is the pointer field in a linked list?

A

a field that contains the address of the next node in the list

65
Q

How does a linked list work? Give an example

A

Index Data Pointer
0 ‘Linked’ 2
1 ‘Example’ 0
2 ‘List’ -
3

Start = 1 NextFree=3

to start, the algorithm will provide a start pointer (1) as well as the next free space (3)

-start with 1, to get ‘example’ as the first data item
-the pointer is showing to go to index 0 which outputs the values at each node
-this then gives a pointer to index 2 which gives the next value
-this doesn’t have another pointer as there is no other value occupying the next available space

by following the algorithm we end up with ‘example’ , ‘linked’ , ‘list’

66
Q

What is one advantage of using a linked list? How does this work? Give an example

A

values can easily be added or removed by editing pointers

adding:
done by adding the value at the end of the linked list and updating the pointer

e.g.
index data pointer
3 ‘OCR’
4

Start = 1 NextFree=4

removing:
rearrange the pointers so that the value wanting to e removed wont be called upon and therefore not in use

e.g.

index data pointer
0 ‘Linked’ 2
1 ‘Example’ 2
2 ‘List’ -

this will leave out ‘linked’ and instead give ‘example’ , ‘list’

-if needed, update other pointers so the algorithm works properly without any mix up of values

67
Q

What is one disadvantage when trying to remove a value from a linked list?

A

the value isn’t fully removed, only ignored which wastes memory

68
Q

What are two differences between a linked list and an array?

A

-storing pointers means more memory is required
compared to an array

-as items in linked lists are stored in a sequence, they can only be transported in this order so an item cannot be directly accessed, as is possible in an array

69
Q

What is a graph?

A

-a data structure
-a set of vertices/nodes connected by edges/arcs

70
Q

What are the three categories of graphs? Describe them

A

directed graph: the edges can only be traversed in one direction

undirected graph: the edges can be traversed in both directions

weighted graph: a cost is attached to each edge

71
Q

How can computers process graphs?

A

by using an adjacency matrix or an adjacency list

72
Q

What are positives of an adjacency matrix and an adjacency list?

A

adjacency matrix:
-convenient to work with due to quicker access times
-easy to add nodes

adjacency list:
-more space efficient for large, sparse networks

73
Q

What is a stack? How does it work?

A

-a last in first out (LIFO) data structure
-items can only be added to or removed from the top of the stack

74
Q

Give two examples of where stacks may be used?

A

-back button in a web page
-undo button

75
Q

How are stacks implemented?

A

implemented using a pointer which points to the top of the stack, where the next piece of data will be inserted

76
Q

What are the two data structures stacks can be used as? Which is preferred and why?

A

-implemented as either a static structure or a dynamic structure

-when maximum size is required, static stacks are preferred, as they are easier to implement and make more efficient use of memory

77
Q

What are the 6 types of stack operations?

A

isEmpty()
push(value)
peek()
pop()
size()
isFull()

78
Q

What does the isEmpty() command do for a stack? Give an example

A

-checks if the stack is empty
-works by checking the value of the top pointer

Stack.isEmpty()
» True

79
Q

What does the push(value) command do for a stack? Give an example

A

-adds a new value to the end of the list
-needs to check that the stack is not full before pushing to the stack

Stack.append(“Nadia”)
»
Stack.append(“Elijah”)
»

80
Q

What does the peek() command do for a stack? Give an example

A

-returns the top value from the stack
-first checks the stack is not empty by looking at value of top pointer

Stack.peek()
» “Elijah”

81
Q

What does the pop() command do for a stack? Give an example

A

-removes and returns the top value of the stack
-first checks the stack is not empty by looking at value of top pointer

Stack.pop()
» “Elijah”

82
Q

What does the size() command do for a stack? Give an example

A

returns the size of the stack

Stack.size()
» 2

83
Q

What does the isFull() command do for a stack? Give an example

A

-checks if the stack if full and returns a Boolean value
-works by comparing stack size to the top pointer

Stack.isFull()
» False

84
Q

What is a queue? How does it work?

A

-a first in first out (FIFO) data structure
-items are added to the end of the queue and are removed from the front of the queue

85
Q

Give three examples of where queues may be used in

A

-printers
-keyboards
-simulators

86
Q

What is a linear queue? How does it work?

A

-a data structure consisting of an array
-items are added into the next available space in the queue, starting from the front
-items are removed from the front of the queue

87
Q

How are pointers used in a queue?

A

-make use of two pointers
-one pointing to the front of the queue
-one pointing to the back of the queue, where the next item can be added

88
Q

Why can a linear queue be ineffective to use? How can we fix this?

A

-as the queue removes items, there are addresses in the array which cannot be used again
-this makes a linear queue an ineffective implementation

-use a circular queue to fix this

89
Q

What is a circular queue? How does it work to fix the issue with a linear queue?

A

-a queue which operates in a similar way to a linear queue in that it is a FIFO structure

-coded in a way that once the queue’s rear pointer is equal to the maximum size of the queue, it can loop back to the front of the array and store values here, provided that it is empty
-therefore, circular queues can use space in an array more effectively

90
Q

What are the four different stack commands?

A

enQueue(value)
deQueue()
isEmpty()
isFull()

91
Q

What does the enQueue(value) command do? Give an example

A

-adds a new item to the end of the queue
-increments the back pointer

Queue.enQueue(“Nadia”)
»
Queue.enQueue(“Elijah”)
»

92
Q

What does the deQueue() command do? Give an example

A

-removes the item from the front of the queue
-increments the front pointer

Queue.deQueue()
»

93
Q

What does the isEmpty() command do for a queue? Give an example

A

checks if the queue if empty by comparing the front and back pointer

Queue.isEmpty()
» False

94
Q

What does the isFull() command do for a queue? Give an example

A

checks if the queue is full by comparing the back pointer and queue size

Queue.isFull()
» False

95
Q

What is a tree?

A

-a data structure
-has a root node and child node which are connected by branches
-is a connected form of a graph

96
Q

What is a node (for a tree data structure)?

A

an item in the tree

97
Q

What is an edge (for a tree data structure)?

A

connects two nodes together and is also known as a branch, or arc

98
Q

What is a root (for a tree data structure)?

A

a single node which does not have any incoming nodes

99
Q

What is a child (for a tree data structure)?

A

a node with incoming edges

100
Q

What is a parent (for a tree data structure)?

A

a node with outgoing edges

101
Q

What is a subtree?

A

subsection of a tree consisting of a parent and all the children of a parent

102
Q

What is a leaf (for a tree data structure)?

A

a node with no children

103
Q

What is a binary tree? What are they used for?

A

-a type of tree where each node has a maximum of two children
-used to search for values quickly such as representing information for binary searches

104
Q

What are the three ways we can traverse through a binary tree?

A

-pre-order
-in-order
-post-order

105
Q

How does pre-order traversing work?

A

-follows the order: root node, left subtree, then right subtree
-nodes are traversed in the order in which you pass them on the
left, beginning at the left-hand side of the root node

106
Q

How does in-order traversing work?

A

-follows the order: left subtree, root node, right subtree
-nodes are traversed in the order in which you pass under them,
beginning at the first node from the left which does not have two child nodes

107
Q

How does post-order (depth first) traversing work?

A
  • follows the order: left subtree, right subtree, root node
    -nodes are traversed in the order in which you pass them on the
    right
108
Q

What is a hash table?

A

-an array which is coupled with a hash function

109
Q

How does a hash table work?

A

-the hash function takes in data (a key) and releases an output (the hash)
-the role of the hash function is to map the key to an index in the hash table

110
Q

What is a collision (hashing)? How can we solve this issue?

A

-two keys producing the same hashed value
-if this occurs, the item is typically placed in the next available location

111
Q

What properties does a good hashing algorithm have?

A

-has a low chance of collision
-must be fast

112
Q

How can problems in boolean equations be solved?

A

by using boolean logic

113
Q

What are the only two solutions a boolean equation can equate to?

A

true or false

114
Q

What are the four operations which can be used for boolean equation?

A

-conjunction (AND)
-disjunction (OR)
-negation (NOT)
-exclusive disjunction (XOR)

115
Q

What is the symbol for conjunction? What can it also be called?

A

also known as AND

116
Q

What is the symbol for disjunction? What can it also be called?

A

v
also known as OR

117
Q

What is the symbol for negation? What can it also be called?

A

¬
also known as NOT

118
Q

What is the symbol for exclusive disjunction? What can it also be called?

A


also known as XOR

119
Q

Draw a diagram showing all the logic gates for the four operations

A

https://spinningnumbers.org/i/logic11.svg

120
Q

What is a truth table? How are the inputs and outputs represented?

A

-a table showing every possible arrangements of inputs to a logic gate and the corresponding output

-inputs are usually labelled A, B, C etc
-1 represents True, 0 represents False

121
Q

How are boolean equations made? Give an example and explain how to solve it

A

made by combining boolean operators
-e.g. ¬(A ^ (B v C))

-first do the equation in the first bracket—> B v C
-work out the next bracket—> A ^ (B v C)
-then apply the negation to the answer

-this could be carried out using truth tables

122
Q

How can we simplify boolean expressions?

A

by using karnaugh maps

123
Q

How do karnaugh maps work?

A

-they create tables filled corresponding to the expression’s truth table
-can be used for a truth table with two, three or four variables
-use the bits for each column and row and apply the operation

124
Q

How can we simplify an expression using a karnaugh map? Show an example

A

-first write your truth table as a Karnaugh map
-then highlight all of the 1s in the map with a rectangle
-the larger the rectangle you can highlight at once the better
-only groups of 1s with edges equal to a power of 2 (1, 2 or 4 in a row) can be highlighted, wraparound is included
-remove variables which change within these rectangles from the expression
-keep variables which do not change, but negate to become True if required

https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcROPkC5L7D_3lwHMAcnkYks-WVR7mfrPeMbWA&usqp=CAU

125
Q

What are the four laws to simplify boolean algebra?

A

-De Morgan’s Laws
-distribution
-association
-commutation
-double negation

126
Q

How does De Morgan’s Law work and when is it used? Give an example

A

-involve breaking UP negation (NOT) and changing the operator between two literals
-used when negation (NOT) applies to the whole of the operator between the two literals

-the AND symbol would also be replaced by the OR symbol and vice versa

e.g. ¬(A ^ B) == ¬A v ¬B
¬(A v B)== ¬A ^ ¬B

127
Q

How does distribution work and when is it used? Give an example

A

-applies when conjunction (AND) is used with another operator that contains disjunction (OR) and vice versa
-can also be used with the same operator

e.g. A ^ (B v C) == (A ^ B) v (A ^ C)
A v (B ^ C) == (A v B) ^ (A v C)

128
Q

How does association work? Give an example

A

-involves the addition or removing of brackets and reordering of literals in a boolean expression

e.g. (A ^ B) ^ C == A ^ B ^ C
(A v B) v C == A v B v C

129
Q

How does commutation work? Give an example

A

-shows that the order of literals around an operation do not matter

e.g. A v B == B v A
A ^ B == B ^ A

130
Q

How does double negation work? Give an example

A

-if negation on a literal is used twice, they cancel out and remain the same truth value

e.g. ¬¬A == A

131
Q

What are three types of logic circuits?

A

-D-type flip flops
-half adders
-full adders

132
Q

Describe what a D-type flip flop is

A

-a type of logic circuit which can store the value of one bit
-has two inputs, a control signal and a clock input (a regular pulse generated by the CPU to coordinate the computers’ components)

133
Q

How does a D-type flip flop circuit work? Draw a diagram

A

-clock pulse rises and falls
-edges can be classified rising or falling
-the output of a D-type flip flop can only change at a rising edge, the start of a clock tick

-uses four NAND gates
-updates the value of Q to the value of D whenever the clock (CLK) rises
-the value of Q is the stored value
e.g.
https://media.geeksforgeeks.org/wp-content/cdn-uploads/gq/2017/01/D-logic-diag.png

134
Q

Describe what an adder is

A

-a logic circuit which adds together the number of inputs which are true and outputs the number in binary

135
Q

How does a half adder work? Draw a diagram

A

-has two inputs, A and B
-has two outputs, Sum and Carry
-formed from two logic gates: AND and XOR

-when both A and B are False, both outputs are False
-when one of A or B is True, Sum (S) is True
-when both inputs are True, Carry (C) is True

e.g.
https://media.geeksforgeeks.org/wp-content/uploads/20201009113450/outputonlinepngtools3.png
https://www.techopedia.com/wp-content/uploads/2023/03/9097e01b7bfd4e8dbf671dcfa129beae.png

136
Q

How does a full adder work? Draw a diagram

A

-similar to a half adder, but has an additional input
-allows carry in to be represented
-formed from two XOR gates, two AND gates and an OR gate
can be chained together to form a ripple adder with many inputs

e.g.
https://www.watelectronics.com/wp-content/uploads/Full-Adder-Truth-Table.jpg
https://circuits-diy.com/wp-content/uploads/2021/08/full-adder-circuit.png