1.4.2 Data Structures Flashcards

(29 cards)

1
Q

Define mutable and immutable

A

Mutable means that a variable’s value can be changed without creating an entirely new variable. Immutable values cannot be changed.

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

Define static and dynamic

A

A static data structure has a fixed length. A dynamic data structure’s length is not fixed.

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

Define linear and non-linear

A

In a linear data structure elements are stored contiguously. They may be stored non-contiguously in a non-linear structure.

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

Define zero-indexed

A

The first element in the data-structure is considered to be at position zero.

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

Describe an Array

A

A mutable static data structure
An array is a data structure that contains a fixed number of values of one data type. The data is mutable and stored linearly. Each value is identified by a single index and it can be iterated by index.

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

How do you identify the position of an element in 2D and 3D arrays?

A

Generally, when searching in a 2D array, you go down the rows, then across the columns. In 3D arrays, you go to the array number, then down, then along.

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

Describe a record

A

A record is a data structure consisting of a fixed number of variables, called fields. Every field has an identifier and a data type. Each field in a record can have a different data type.

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

Describe a list

A

Lists are dynamic data structures, consisting of ordered items where an item can occur more than once. They are non-contiguous and can hold multiple data types. Like arrays, it identifies values by an index.

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

Describe a tuple

A

An ordered, immutable set of values. Values can be of differing data types.

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

Describe a linked list

A

An ordered, linear dynamic data structure in which data can be stored non-contiguously and each element is called a node.

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

Describe how pointers work in a linked list

A

Each node contains the data relating to the element and the pointer to the next node.
You must start from the first position indicated by the startpointer, then read the next pointer value and follow this pointer value to access the next data item, and so on…

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

Describe graphs

A

Graphs are non-linear data structures made up of nodes. They are an abstract structure that represents complex, non-linear relationships.

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

Define each term related to graphs

A

Nodes: The elements in a graph
Edges: The connections between nodes
Neighbours: When two nodes are connected by an edge
Degree: The number of other nodes that a node is connected to
A loop: An edge that connects a node to itself
A path: A sequence of nodes that are connected by edges
A cycle: A closed path, i.e. a path that starts and ends at the same node (and no node is visited more than once)

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

Describe the difference between directed and undirected graphs

A

In a directed graph the edges can only be traversed in one direction. In an undirected graph the edges can be traversed in both directions.

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

Describe a stack

A

A stack is an abstract data type that holds an ordered, linear sequence of items. It is a Last In, First Out (LIFO) structure. You need to maintain a pointer at the top of a stack. They may be static or dynamic.

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

Define overflow and underflow in relation to stacks

A

Overflow - attempting to push onto a stack that is full
Underflow - attempting to pop from a stack that is empty

17
Q

State the main stack operations and their uses

A

push(data) = adds an element to the top of the stack
pop() = removes an element from the top of the stack
peek() = returns a copy of the element on the top of the stack without removing it
is_empty() = checks whether a stack is empty
is_full() = checks whether a stack is at maximum capacity when stored in a static (fixed-size) structure

18
Q

Describe a queue

A

A queue is an abstract data type that holds an ordered, linear sequence of items. It is a First in, First Out (FIFO) structure. You need to maintain a pointer at both the front and back of the stack.
They may be static or dynamic.
New elements are added to the back or rear of the queue. When an element is removed, the remaining elements do not move up to take the empty space.

19
Q

State the main queue operations and their uses

A

enqueue(data) = adds an element to the queue
dequeue() = returns an element from the front of the queue
is_empty() = checks whether the queue is empty
is_full() = checks whether the queue is at maximum capacity
(if the size of the queue is constrained)

20
Q

Describe a tree

A

A tree is an abstract data structure used to represent non-linear data. It is a connected, undirected graph consisting of nodes and edges. There are no cycles in trees so only one path between any 2 nodes.

21
Q

Define each term related to trees

A

Root = The first node, at the top. It does not have any incoming nodes.
Child = A node with incoming edges
Parent = A node with outgoing edges
Subtree = Subsection of a tree consisting of a parent and all the children of a parent
Leaf = A node with no children

22
Q

Describe a binary search tree

A

A binary tree is a type of tree in which each node has a​ maximum of two children.
Nodes are added in the order given, with the first item at the root. If the next item is less than the root, it is added to the left of the root, otherwise to the right. Apply the same rule at the root of each sub-tree.
​These are used to represent information for binary searches​.

23
Q

Describe a hash table

A

A hash table is an array that uses the hash function.
It is a data structure which will find any record in the dataset almost instantly, no matter how large the dataset is.
It enables access to data that is not stored in a structured manner.

24
Q

State the hash function and its use

A

The hash function is Address = key mod TableSize.

A hash function takes an input (key) and computes a numerical index within the bounds of a hash table. Large data sets can be organised so each record is assigned a unique address.

25
Define collisions in hash tables
When a key creates a hash value that references a position that is already occupied.
26
Describe linear probing/open addressing
This places the data in the next free position in a hash table if a collision occurs. This is done through probing (incrementing) either sequentially or by a skip factor (interval) until an empty position is found. (It's best to have the table size as a prime number to avoid looping if a skip factor is used)
27
State the advantages and disadvantages of linear probing
**Advantages** = This technique is simple and, because it probes adjacent slots, it often benefits from CPU caching, which can make it fast in practice when the table isn’t too full. **Disadvantage** = Linear probing suffers from a problem called primary clustering. This means that as keys collide and probe linearly, long sequences of occupied slots tend to build up. When a new key hashes into this cluster, it has to probe further down the sequence, potentially making the cluster even longer. This significantly slows down insertions and searches as the table gets fuller.
28
Describe chaining/closed addressing
Chaining is used to avoid collisions, by storing multiple elements in the same slot using a linked list. E.g. [10 → 24 → 31 → 17 → 45 → 3]
29
What are the benefits of using the hash function/a hash table?
-It distributes keys uniformly -It's fast to compute -It minimises collisions