1.4.2 Data Structures Flashcards

1
Q

Arrays

A

An ordered, finite set of elements of a single type

You can make an array of tuples

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

Index of arrays

A

0-based
Find a value with arrayname[index]
arrayname[row,column] for 2d

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

Multi-dimensional arrays

A

You can have any number of dimensions

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

Tuples

A

An ordered set of values, can have elements of mixed type and it is immutable (elements cannot change)

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

Records

A

Composed of a fixed number of fields of different data types

Access a value with the name of the record

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

Dynamic data structure

A

They can change size when required

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

Static data structure

A

They cannot change size

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

Abstract Data Type

A

A logical description of how we view the data and possible operations

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

Where does the rear of the queue start at?

A

-1

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

isFull() pseudocode

A
function isFull()
if size == maxSize:
return True
else:
return False
end if
end function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

isEmpty() pseudocode

A
function isEmpty()
if size == 0;
return True:
else: 
return False
end if
end function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

enQueue() pseudocode

A
function enQueue()
if size < maxSize:
rear ++
rear = rear MOD maxSize
Q[rear] = item
size ++
else:
print (queue is full)
end if
end function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

deQueue() pseudocode

A
function deQueue()
if size  == 0:
item = null
print (queue is empty)
else:
item = Q[front]
front = (front + 1) MOD maxSize
size --
end if
return item
end function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Priority Queue

A

Items are ordered in a queue first based on their priority and then based on FIFO, items move backward to allow a higher priority item to join.

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

Hash Table

A

A data structure where keys are mapped to index values, used where faster searching is needed e.g. police records

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

Collisions/synonyms and how to deal with them

A

When an algorithm generates the same address for different primary keys
Methods include putting the value in the next free location or incrementing how far you skip by

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

Searching in a hash table

A

Apply the hash function to the key and first check that position, if not increment by 1 and check each
If the original position is empty or you cycle back the value isn’t in the table

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

Mid-square hashing algorithm

A

Square the number, extract some portion of the resulting digits (likely the middle), then mod by the size of the table

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

Folding hashing algorithm

A

Divide the item into equal sized pieces (excluding maybe the last piece, sum them and carry out the mod with the size of the table

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

Hashing alphanumeric data

A

Take the ASCII of each character, sum them and mod with the size

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

Hash table deletion

A

When a value is deleted, a placeholder is used to represent that a value has not been deleted.

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

Lists

A

A dynamic data type containing a number of ordered items that can be repeated. The elements are stored non-contiguously on the heap and can be of different types

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

Linked list

A

A dynamic abstract data structure which is implemented as an array and pointers

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

What is a node composed of linked list?

A

The data and a pointer to the next node

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Linked list pointers
A start pointer identifies the first element in a list, a nextfree pointer highlights the next free space, the last node has null
26
Stack
A collection of elements that are retrieved on a last-in first-out basis
27
Stack variables
Top and maxSize | Top starts at -1
28
How to reverse elements?
Push them all onto a stack and then pop them off
29
Stack isFull()
``` function isFull() if (top + 1) == maxSize: return True else: return False end if end function ```
30
Stack isEmpty()
``` function isEmpty() if top == -1: return True else: return False end if end function ```
31
Stack push()
``` procedure push(newItem) if (top + 1) == maxSize print (stack is full) else: top ++ stack[top] = newItem end if end procedure ```
32
Stack pop
``` function pop() if top == -1: print (stack is empty) item = null else: item = stack[top] top -- end if return item end function ```
33
Graph
A set of vertices connected by edges or arcs
34
Adjacency Matrix of a weighted graph
Put the weight of the connecting edge and leave boxes blank instead of writing 0s
35
Adjacency matrix advantages and disadvantages
+ convenient to work with, easy to add edges | - wastes a lot of memory space if nodes have few edges
36
Adjacency list
A list of nodes pointing to their adjacent nodes | For weighted it has {node:weight}
37
Tree
A connected, undirected graph with no cycles
38
Root
The node at the top of the tree with no parents
39
Child
A node below a parent node in a tree
40
Parent
A node above one or more children
41
Subtree
A part of a tree which itself is a tree
42
Leaf
A node in a tree with no children
43
Binary Tree
A rooted tree in which each node has a maximum of two children, each node has a left and a right pointer (-1 if there is no child on that side)
44
Building a binary tree
Start from the root each time and trace to the left if the value is smaller than the current node and to the right if it is larger
45
Pre-order searching
Visit the root then follow the left subtree then the right
46
In-order searching
Follow the left subtree then visit the root then follow the right
47
Post-order searching
Traverse the left subtree then the right then visit the root node
48
Deleting a leaf node
Just remove the node
49
Deleting a node with one child
The child replaces the deleted parent
50
Deleting a node with two children
Repeatedly add 1 to the value of the node until you find the value of another node, which will replace the deleted node
51
Binary tree uses
Mainly used for searching as you often have to rebuild the tree after deletion
52
Breadth-first traversal
Traverses the root then the children of the root left to right then their children left to right
53
Depth first traversal
Starts at the bottom left and at each leaf it will move up to the latest decision point and go right where it hasn’t been done before
54
Record declaration
``` Name = record DataType FieldName DataType FieldName … End record ```
55
Acessing a record
recordName.fieldName
56
Adding a value to the end of a list
listName.append(value)
57
Finding the first index of a value in a list
listName.index(value)
58
List remove and return from a position
listName.pop(index)
59
Removing the first instance of a value from a list
listName.remove(value)
60
Initialising a tuple
tupleName = (“value1”, “value2”, …) | Accessed like an array
61
Stack peek()
Returns the top element if the stack isn’t empty