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
Q

Linked list pointers

A

A start pointer identifies the first element in a list, a nextfree pointer highlights the next free space, the last node has null

26
Q

Stack

A

A collection of elements that are retrieved on a last-in first-out basis

27
Q

Stack variables

A

Top and maxSize

Top starts at -1

28
Q

How to reverse elements?

A

Push them all onto a stack and then pop them off

29
Q

Stack isFull()

A
function isFull()
if (top + 1) == maxSize:
return True
else:
return False
end if
end function
30
Q

Stack isEmpty()

A
function isEmpty()
if top == -1:
return True
else:
return False
end if
end function
31
Q

Stack push()

A
procedure push(newItem)
if (top + 1) == maxSize
print (stack is full)
else:
top ++
stack[top] = newItem
end if
end procedure
32
Q

Stack pop

A
function pop()
if top == -1:
print (stack is empty)
item = null
else:
item = stack[top]
top --
end if
return item
end function
33
Q

Graph

A

A set of vertices connected by edges or arcs

34
Q

Adjacency Matrix of a weighted graph

A

Put the weight of the connecting edge and leave boxes blank instead of writing 0s

35
Q

Adjacency matrix advantages and disadvantages

A

+ convenient to work with, easy to add edges

- wastes a lot of memory space if nodes have few edges

36
Q

Adjacency list

A

A list of nodes pointing to their adjacent nodes

For weighted it has {node:weight}

37
Q

Tree

A

A connected, undirected graph with no cycles

38
Q

Root

A

The node at the top of the tree with no parents

39
Q

Child

A

A node below a parent node in a tree

40
Q

Parent

A

A node above one or more children

41
Q

Subtree

A

A part of a tree which itself is a tree

42
Q

Leaf

A

A node in a tree with no children

43
Q

Binary Tree

A

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
Q

Building a binary tree

A

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
Q

Pre-order searching

A

Visit the root then follow the left subtree then the right

46
Q

In-order searching

A

Follow the left subtree then visit the root then follow the right

47
Q

Post-order searching

A

Traverse the left subtree then the right then visit the root node

48
Q

Deleting a leaf node

A

Just remove the node

49
Q

Deleting a node with one child

A

The child replaces the deleted parent

50
Q

Deleting a node with two children

A

Repeatedly add 1 to the value of the node until you find the value of another node, which will replace the deleted node

51
Q

Binary tree uses

A

Mainly used for searching as you often have to rebuild the tree after deletion

52
Q

Breadth-first traversal

A

Traverses the root then the children of the root left to right then their children left to right

53
Q

Depth first traversal

A

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
Q

Record declaration

A
Name = record
DataType FieldName
DataType FieldName
…
End record
55
Q

Acessing a record

A

recordName.fieldName

56
Q

Adding a value to the end of a list

A

listName.append(value)

57
Q

Finding the first index of a value in a list

A

listName.index(value)

58
Q

List remove and return from a position

A

listName.pop(index)

59
Q

Removing the first instance of a value from a list

A

listName.remove(value)

60
Q

Initialising a tuple

A

tupleName = (“value1”, “value2”, …)

Accessed like an array

61
Q

Stack peek()

A

Returns the top element if the stack isn’t empty