1.4 - Data types, data structures and algorithms Flashcards

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

What is a data type?

A

It is the classification of data telling the computer how the computer will use the data.

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

What is an integer?

A

Any positive/negative whole number.

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

What is a real/float?

A

Any real world quantity expressed as a number (decimals).

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

What is boolean?

A

Used to represent one of two truth values (True/False)

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

What is a character?

A

Represents a single character, alphanumeric/symbol.

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

What is a string?

A

A collection of characters.

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

What is casting data types?

A

Changing data types

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

What is a primitive data type?

A

A basic data type.

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

What base in binary?

A

Base 2 = 01

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

What base is denary?

A

Base 10 0-9

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

What base is hexadecimal?

A

Base 16 0-9, A-F

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

What are the 5 positives of hexadecimal?

A
  • Values easier to remember/read than binary.
  • Quicker to write, less characters.
  • Less chance of eror when typing hex.
  • Defines colours, MAC addresses, in assembly languages/machine code.
  • Easy to convert to/from Binary.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you use sign + magnitude?

(Negative numbers in binary)

A

The most significant number represents whether the number is positive (= 0)/negative (=1).

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

How do you use two’s compliment?

(Negative numbers in binary)

A

The most significant number represents whether the number is positive (= 0)/negative (=1). Then all the numbers afterwards (until the last 1 (1 closest to the end)) are switched to the opposite value.

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

How do you convert from Denary to Binary?

A

Put in place value to add to make total of the number.
e.g. 99 = 01100011
128/64/32/16/8/4/2/1
0 1 1 0 0 0 1 1

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

How do you convert from Hexadecimal to Denary

A

Do the rule of place values. 256 16 1 time number based on plate.

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

How do you convert from Denary to Hexadecimal?

A

Divide number by 16 and add remainder.
e.g. 43/16 = 2 + 11 = 2B

(11 = remainder in the example)

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

How do you convert from Binary to Hexadecimal?

A

Divide binrary number into 2 (2 x 4 digits)= 0011 1100 (Use 8421 place values) and then add to make up the 2 hex digits.

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

What is a bit?

A

An individual digit in a binary value.

Used to represent ON + OFF voltage signals om a computer.

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

What is a byte

A
  • 8 Bits grouped together.
  • Can group 2 or more bytes together to hold larger values.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is a fixed bit?

A

extra zeros that pad the data at the front. So that the binary can be a full byte.

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

How big is a Kilobyte?

A

10^3 = 1,000 bytes

KB = Kilobyte

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

How big is a Megabyte?

A

10^6 = 1,000,000 Bytes

MB = Megabyte

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

How big is a Gigabyte?

A

10^9 = 1,000,000,000 Bytes

GB = Gigabyte

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

How big is a Terabyte?

A

10^12 = 1,000,000,000,000 Bytes

TB = Terabyte

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

How big is Kibibyte?

A

2^10 = 1,024 Bytes

KiB = Kibibyte

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

How big is a Mebibyte?

A

2^20 = 1,048,576

MiB = Mebibyte

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

How big is a Gibibyte?

A

2^30 = 1,073,741,824

GiB = Gibibyte

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

How big is a Tebibyte?

A

2^40 = 1,099,511,627,776

TiB = Tebibyte

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

What is ASCII?

A
  • American Standard Code for Information Interchange.
  • Established in 1963 to encode symbols found in the english Alphabet.
  • 7 bit = 2^7 = 128 possible binary codes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

How does ASCII work?

A
  • Every single character on the keyboard is represented by a binary value.
  • 1st 32 codes are control characters e.g. Backspace / Enter
  • 8th bit introduced later for extra characters. e.g. ©️
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

What is the purpose of Unicode?

A
  • Introduced to standardise the encoding of characters of all languages.
  • Either apply the variable length of 16 bits or 32 bits encoding.
  • 1st 128 characters same as ASCII, to improve the adoption of it.
  • Every single character in every single language, mathematic + scientific can be represented.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

What are the binary addition number rules?

A
  • 1+1 = 0 carry 1
  • 1 + 1 + 1= 1 carry 1
  • 0 + 0 = 0
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

What is an overflow error?

A

The result of an addition is too large for the number of bits the computer works with.

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

What determines the calculating range?

A

No. bits determines how many values can be represented in binary.

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

How much of the range of values can represent the binary values?

A
  • Positive = the full range.
  • Negative = half the range.
    Max for 8 bit = 127↓10 = 0111 1111
    Min for 8 bit = -128↓20 = 1000 0000
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

How do you do binary subtraction?

A

Turn the number you are subtracting into its negative form then add the two numbers together.

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

What are the 3 types of data?

A
  • Elementary
  • Composite
  • Abstract
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

What are some examples of an elementary data type?

A
  • e.g Char, Real, Integer, Boolean
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

What are Structured data types?

A
  • Built in = Strings, Arrays, Lists, Records.
  • Mainly made up of Elementary data types.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

What is an array?

A
  • An array is an ordered, finite set of elements of a single type
  • They are zero indexed (First element at index 0)
  • 1D array = linear e.g. [1]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

What is a 2D array?

A
  • 2 different indexes (Seperated by commas).
  • Like a table e.g [0, 1]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

What is a multidimensional array?

A
  • Can define w any no. of dimensions.
  • e.g. 3D = hold xyz coordinates, [x, y, z]
  • e.g. 4D can hold the sales of branches of a supermarket by country/store/department/year, sales[c, s, d, y] = 23450
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

What are 4 features of Tuples?

A
  • Ordered set of values.
  • May have elements of mixed types.
  • Immutable - elements cannot change.
  • ## Doesn’t use square brackets.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

What is a disadvantage of a tuple?

A

You can’t change it if there is a spelling error or add another element to a tuple.

46
Q

An example of a tuple

A

Player ID, Lastname, Firstname, Score1, Score2, Score3
Player 1 = (34296, “Jones”, “Jane”, 125, 150, 137)

47
Q

What are the 2 characteristics of a record?

A
  • Composed of a fixed number of fields of different data types (Resembles a spreadsheet)
  • Can be implemented as an object + treated like a tuple.
    (In writing files: each record is usually written as a single line).
48
Q

What is a static data type?

A

Cannot change size.
- Arrays in most languages don’t change size automatically.
- Some languages provide functions to resize, has to be programmed; not automatic.

49
Q

What is a dynamic data type?

A

Change size when required.
- Array lists/lists grow when items are added + shrink when items are removed.

50
Q

What is a abstract data type?

(ADT)

A
  • Logical description of how we view the data and possible operation.
  • Only concerned with what the data is representinig not how it is constructed.
  • e.g. a tree
51
Q

What principle does a queue follow?

A
  • The FIFO (first in, first out) principle
52
Q

What are the 4 stages of a queue?

A
  1. Add item to the rear of the queue.
  2. Remove the item from the front of the queue.
  3. Check if the queue is empty.
  4. Check if the queue is full.
53
Q

What are 2 features of a queue?

A
  • Can’t add to a full queue or take away from an empty queue.
  • When initialising a queue specify max no. it can hold, e.g. maxsize. May be necessary to have a variable size to hold the number of items currently in the queue.
54
Q

What are the 4 queue functions/methods?

A
  • enQueue(item) - add an item to the rear.
  • deQueue - remove and return an item from the front.
  • isEmpty - indicates if the queue is empty.
  • isFull - indicates if the queue is full.
55
Q

What principle does a stack follow?

A
  • The LIFO (last in first out) principle.
56
Q

What is a stack?

A

A data structure where new items added to the top of the stack and items are removed from the top of the stack.
- Order of insertion opposite to order of removal.
- e.g. [R,O,B,E,R,T] -> [T,R,E,B,O,R]

57
Q

What is the model of a stack?

A
  1. Add an item to the top.
  2. Remove an item from the top of the stack.
  3. Check if the stack is full.
  4. Check if the stack is empty.
58
Q

What are the 6 programming operations of a stack?

A
  • push(item) - adds item to the top of the stack.
  • pop() - removes + returns the item on top of the stack.
  • isFull() - Checks if the stack is full.
  • isEmpty() - Checks if the stack is empty.
  • peek() - returns the top item without removing it.
  • size() - returns the number of items in the stack.
59
Q

How are the 4 stages of a stack?

A
  1. Add an item to a stack.
  2. Remove an item from a stack.
  3. Check if the stack is empty.
  4. Find the number of items in the stack.
60
Q

What are the built in list operations of a stack?

A
  • len(stack) - finds the length (height) of the stack.
  • append(item) - add item to the top of the stack.
  • pop() - removes + returns the item on the top of the stack.
61
Q

What is a tree?

A

A connected, undirected graph with no cycles (i.e. there is a unique path from each node to any other node).

62
Q

What is a rooted tree?

A

One node is identified as the root so every node execpt the root has a unique parent. All branches start from 1 node.

63
Q

What is a node?

A

It holds a value or data, one of them becomes the root.

64
Q

What is an edge?

A

It is the connection between the nodes.

65
Q

What is a child?

A

It is a node with a parent node.

66
Q

What is a parent?

A

It has an edge to a child node.

67
Q

What is a leaf?

A

A node that doesn’t have a child node.

68
Q

What is a binary tree?

A

A rooted tree which each node has a maximum of 2 children.

69
Q

What are the 3 parts of a node?

(Binary tree)

A
  1. The data (Primitive or more complex object).
  2. Left pointer to a child.
  3. Right pointer to a child.
70
Q

How do you build a binary tree?

A
  • Nodes are added in the order given, with the first item at the root.
  • Starting at the root each time, if the next item is less than the root, it is added to the left of the root, otherwise to the right. Same rule applied at the root of each subtree.
  • e,g, 12, 7, 18, 22, 14, 10, 56, 3 , 2, 20, 8 (Work in order of list).
    12
    7 8
    3 10. 14 22
    2. 8. _. 20 56
71
Q

How else can you represent a tree?

A

In an array.
- Pointer -1 means that there is no subtree on that side.
- e.g. tree[0] 1, 24, 3
- 1 is the index number of the value of the left child.
- 24 is the data index 0 holds on the tree.
- 3 is the index number of the value of the right child.

72
Q

What are the 3 types of binary tree traversal?

A
  1. Pre-order.
  2. In-order.
  3. Post-order.
73
Q

What order is pre-order traversal?

A

Visit the root, then traverse th eleft sub tree, then the right sub tree.

74
Q

What order is in-order traversal?

A

Traverse the left sub-tree, visit the root, traverse the right sub-tree.

75
Q

What order is post-order traversal?

A

Traverse the left sub-tree, traverse the right sub-tree, then visit the root.

76
Q

What is a linked list?

A

A data structure which is the foundation for other structures to be built upon. e.g. stacks, queues, graphs + trees.

77
Q

What are 4 features of a linked list?

A
  • Contains nodes + pointers.
  • Start pointer identifies the first node.
  • Each node contains data and a pointer to the next node.
  • Can be stored anywhere in memory, pointers indicate the address of the next item.
78
Q

What is a circular linked list?

A

Where the last node points to the first node.

Combined with a double linked list to make a double circular linked list

79
Q

What is a double linked list?

A

Uses an extra pointer so nodes point to the previous and the next node.

Combined with a circular list to make a double circular linked list

80
Q

How can a linked list be implemented?

A

Through a static array. (Though requires the use of an index register; to determine where a specific index is in relation to a base address).

81
Q

What are the 2 benefits of implementing the linked list through objects?

A
  • Any available memory address can store the data. It doesn’t have to be adjacent (As each node points to the next).
  • It is a dynamic data structure (Memory footprint is not determined at the compile time + can change during the run time).
82
Q

What are the 6 applications of a linked list?

A
  • Operating systems managing a processor to store process blocks in a ready state.
  • Image viewers to switch between previous and next images.
  • Music players to store tracks in a playlist.
  • Web browswers to navigate back + forwards.
  • For hash table collision resolution as an overflow.
  • Maintaining a file allocation table of linked clusters on secondary storage.
83
Q

What 5 operations can be performed on a linked list?

A
  • Add: Adds a node to the linked list.
  • Delete: Removes a node from the linked list.
  • Next: Moves to the next item in the linked list.
  • Previous: Moves to the previous item in the doubly linked list.
  • Traverse: A linear search through the linked list.
84
Q

What is a graph?

A
  • It is a data structure consisting of nodes/vertices and edges/pointers.
  • ## Each vertex can have more than 2 edges + point to any vertex in the structure.
85
Q

What is a directed graph?

A

A graph where the edges point in one direction.

86
Q

What is a undirected graph?

A

A graph where the edges do not specify a direction.

87
Q

What is a weighted graph?

A

Each edge has a value which represents the relationship between the vertices. e.g. distance between them, time, bandwidth.

88
Q

What is cost?

(Graphs)

A

The edge value.

89
Q

How are graphs implemented?

A
  • Stored as objects or using dictionaries (adjacency lists).
  • ## Stored as an array (adjacency matrix; rows + colums represent the vertices + edges). 1 represents a edge between 2 vertices. 0 represents no edges between the vertices.
90
Q

What are the 4 applications of a graph?

A
  • Mapping road networks for navigation systems.
  • Storing social network data.
  • Resource allocation in operating systems.
  • Representing molecular structures in geometry.
91
Q

How do you traverse a graph?

A

The same way as a binary tree.

92
Q

What are the standard operations of a graph?

A
  • Adjacent: Returns whether there is an edge between 2 vertices.
  • Neighbours: Returns all the vertices between 2 vertices.
  • Add: Adds a new vertex to the graph.
  • Remove: Removes a vertex from the graph.
  • Add edge: Adds a new edge connecting 2 vertices.
  • Remove edge: Removes an edge connecting 2 vertices.
  • Get vertex value: Returns the data stored in a vertex.
  • Set vertex value: Sets the data for a vertex.
  • Get edge value: Returns the value of an edge between 2 vertices.
  • Set edge value: Sets the value of an edge between 2 vertices.
93
Q

What is a depth-first search?

(Graph search operations)

A

Starts at the root vertex, visits each vertex and explores each branch as far as possible before backtracking.

94
Q

What is a breadth-first search?

(Graph search operations)

A

Starts at the root node and visits each neighbouring node before moving to the vertices at the next depth.

95
Q

What are the 3 types of graph traversal?

A
  • Pre-order
  • In-order
  • Post-order
96
Q

What is the goal of a hash table?

A

Find an item in an unsorted/sorted list without needing to compare to other items in the data sets.

97
Q

What does a hashing function do?

A

It calculates the position of an item in a hash table.
Order = Initial data -> Converted value to fed to hash function -> Hash function -> Hash Table (holds address and data at the address).

98
Q

What is collision?

(Hash table)

A

When the algorithm returns the same value for more than one item. It happens because 2 data items cannot occupy the same position in the hash table

99
Q

What should you do to minimise the chances of a collision?

(Hash Table)

A

Make the hash table significantly larger than it needs to be to store the data items.

100
Q

What are the 4 ways to resolve a collision in a hash table?

A
  • Open addressing.
  • Linear Probing.
  • Using a 2D hash table.
  • Use an overflow table.
101
Q

What is open addresing?

(Hash Table)

A

Repeatedly checking the next availible space in the hashing table until an empty position is found and store the value there.

102
Q

What is linear probing?

A
  • Used to find the item later.
  • The hashing function delivers the start position from which a linear search can then be applied until the item is found.
103
Q

What are 2 disadvantages of linear probing?

A
  • Prevents other items from being stored in their position in the hash table.
  • Causes clustering.
104
Q

What is clustering?

(Hash Table)

A

Several values being filled around common collision values.

105
Q

What is rehashing?

A

Finding an alternative position for items in the hash table.

106
Q

What is the tradeoff between efficiency of the algroithm and the size of the hash table?

A

The larger the hash table the less collusions occuring. e.g. table size 10 has 2 collisions, table size 5 has 3 collisions so less efficient but smaller memory footprint.

107
Q

What is the benefit of using a 2D hash table?

A

Chaining can occur.

108
Q

What is chaining?

(Hash Table)

A

More than 1 item being placed in the same position.

109
Q

What is an overflow table?

A

A second table created for collisions - which can be searched sequentially.
Or use a linked list to manage the overflow.

110
Q

What are the 2 applications of a hash table?

A
  • File systems linking a file name to the path of the file.
  • Identifying the keywords in a programming language during complimation.
111
Q

What are the 3 operations performed on a hash table?

A
  • Add: Adds a new item to a hash table.
  • Delete: Removes an item from a hash table.
  • Retrieve: Retrieves an item from a hash table using its hash value.