1.4.2 Data Structures Flashcards

(69 cards)

1
Q

Array?

A

A data structure that holds several elements of the same data type

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

How and why are arrays used in computer hardware?

A

Contents of arrays are stored contiguously on the RAM
Each position is directly accessible
Values are mutable

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

Mutable?

A

Can be changed while the program is running

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

2D arrays?

A

Can be visualized as a table
Navigate down the rows then across the columns

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

3D arrays?

A

Can be visualized as a multipage spreadsheet / multiple 2D arrays

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

Pros of using arrays?

A

Arrays can be declared via a single identifier

Arrays can be processed efficiently, using iteration techniques

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

Record?

A

A data structure that consists of a fixed number of variables, called fields.

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

List?

A

An abstract data structure that describes a linear collection of data items in an order.

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

What are the 4 list operations?

A

Create
Add
Delete
Traverse

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

How do you implement lists using static arrays?

A

Create an array where the max number of elements in the list is fixed.

Populate the array sequentially, using a linear search to find gaps

An index pointer is used to point to the next occupied element in the list

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

Cons of static list implementation?

A

If items are constantly added/removed there will be gaps

Gaps are found using linear search, which’s slow and inefficient, especially with larger lists.

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

What does it mean for a list to be dynamic?

A

The size of the list can change at any time

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

How do you implement a list dynamically?

A

Using a linked list

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

What is a linked list?

A

A dynamic data structure that acts like a chain, consisting of a sequence of nodes, where each node contains data and a pointer to the next node in the sequence

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

Node?

A

An element in a linked list that stores:

Data relating to the element
A pointer to the next node

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

The head pointer?

A

Indicates the first element in the linked list

This has a null value when the list is empty

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

Tail pointer?

A

Indicates the last element in the linked list

Always points to a null value- marking end of list

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

Tuple?

A

An immutable, ordered sequence of elements

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

Use of tuples?

A

To group together a set of disparate items, that are to be passed into a method.

Results from SQL queries are received as tuples

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

Stack?

A

An abstract LIFO data structure that holds an ordered, linear sequence of items

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

Main stack operations?

A

push(data) = adds element to the top of the stack

pop() = removes element from the top of the stack

peek() = returns a copy of the element on the top of the stack

is_empty() = checks if stack is empty

is_full() = checks if stack is full, if it’s in a static structure

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

Queue?

A

First in first out data structure that holds an ordered linear sequence of items

Meaning items are added to the end and removed from the front

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

What’s a pointer?

A

An object that stores a memory address

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

Queue overflow?

A

Enqueuing to a full queue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
queue underflow?
dequeuing from an empty queue
26
Main queue operations?
enqueue(data) = adds element to the back of the queue dequeue() = removes element from the front of the queue peek() = returns a copy of the element at the front of the queue without removing it from the queue is_empty() = checks if queue is empty is_full() = checks if queue is full
27
Static queues?
Queues with a fixed size and contents that cannot change at run time
28
Types of static queues?
Linear queue Circular queue
29
Linear queues?
Consists of an array Items are added to the next available space starting from the front of the queue, where the rear pointer begins and then the rear pointer moves to the next index As items are removed from the front, the front pointer moves to the next item
30
Circular queues?
Freed spaces from dequeued items are reused- efficient memory usage The last index connects to the first forming a circle When an item is enqueued the REAR pointer moves to its position When an item is dequeued the FRONT pointer moves to the position of the next item at the front
31
Dynamic Queues?
Queues that can automatically resize their memory allocation based on the number of elements they hold The queue has no fixed size
32
Type of dynamic queue?
Priority queue
33
Priority queue?
Each item has a priority associated with it The queue has no fixed size
34
Hash table?
An associative array, which's used with a hash function
35
Hash function?
Maps the hash key to an index in the hash table- taking in data and releasing an output
36
Collision / synonym?
When 2 inputs produce the same hashed value These are impossible to avoid ,but a good hashing algorithm should have a low probability of collisions occurring
37
Linear probing?
A collision resolution, where the data that has caused a collision is typically placed in the next available index/ location Probing can either occur sequentially or via use of an interval, until and empty bucket is found
38
Retrieving data after probing?
Hash the key to generate the index value Examine the indexed position to see if the key matches that of the data you're looking for If there's no match, check each location that follows at the appropriate interval, until a match or an empty bucket is found If you reach an empty bucket, without finding a matching key, then the data is not in the table
39
Cons of linear probing?
Reduces the efficiency of using a hash table for searching
40
Pros of linear probing?
Resolves collisions generated by hashing algorithms
41
Graph?
A set of nodes that are connected by edges / pointers.
42
Graph characteristics?
Directed- edges can only be traversed in one direction Undirected- edges can be traversed bidirectionally Weighted- A value is attached to each edge (if no edge exists, the infinity symbol becomes its value in an adjacency matrix / list) Unweighted- Each edge has a value of 1, if no edge exists its value becomes 0 in an adjacency matrix / list
43
Adjacency matrix?
A 2d array that records the relationship between each node and all other nodes in the graph
44
Adjacency list?
Records the existence of an edge between a node and each of its neighbours.
45
Dictionary?
An associative array that stores a collection of unique keys, each with a corresponding value Stores the node to be visited and the weight of the connecting edge as key-value pairs (for graphs)
46
Breadth-first search?
Method of graph traversal Systematically visits all neighbours of a given node before moving on to tho neighbours of the next node Goes from left to right
47
Depth- first search?
Use an edge based system, traversing the left most path first Uses a stack to push each visited node on, and then pop them when there are no connected nodes left to visit
48
Tree?
Connect, undirected forms of graphs, containing a root node and connecting nodes in parent-child relationships
49
Tree height?
The number of edges that connect the root node to the FURTHEST leaf node
50
Features of trees?
Branches = edges Root node = top node Leaves = endpoints / nodes with zero children One parent can have multiple children
51
Uses of trees?
Managing folder structures
52
Uses of binary trees?
Used to store routing tables Used to speed up searching for data Can represent algebraic expressions simply
53
Binary trees?
A rooted tree where every node has a maximum of 2 child nodes And the tree is ordered based on whether a node is greater than or less than the parent
54
Recursion?
When a function calls on itself to execute a task
55
Pre-order traversal
Visit the root-traverse the left subtree-traverse the right (Start bottom left, touch the left of the node) Repeat every time a new node is traversed
56
In-order traversal?
Traverse the left subtree-Visit the root node- traverse the right subtree (Start bottom left, touch the bottom of the node) Repeat every time a new node is traversed
57
Post-order traversal?
Traverse the left subtree-traverse the right- visit the root node (Start bottom left, touch the right of the node) Repeat every time a new node is traversed
58
Adding to a binary tree?
If tree is empty, new value becomes the root If value is less than the current node, move to left child If value is greater than the current node, move to the right child Repeat until a vacant spot is reached to insert the new value Make sure the tree maintains its structure
59
How to remove a leaf node from a binary tree?
directly delete it
60
How to remove a node with only one child from a binary tree?
copy the value of the child in place of the parent node and delete the empty node
61
How to remove a node with two children from a binary tree?
replace the node with its minimum child
62
Recursion?
A programming technique where a function calls itself to execute a task Using self reference to breakdown complicated problems until it reaches the base case
63
Base case?
The condition of a recursive method that returns a value without any further recursive calls
64
Stopping base?
A condition that must be reachable after a finite number of times
65
Recursive algorithm features?
the function must call itself It has a base case It has a stopping base
66
How to develop a stopping condition?
Consider the problem being solved Identify the easiest scenario where the function can provide a direct result- define this as the base case
67
Pros of recursion vs iteration
Can be expressed in a more concise way Simple- don’t have to focus on maintainability
68
Cons of recursion vs iteration
Worse performance- repeat method calls are memory intensive, causing slower execution More difficult to track the program state during debugging Limited application
69
Why is a proper base case needed?
To avoid stack overflow errors- which cause program crashes Without a stopping condition, the function will call itself indefinitely- which will use up excessive memory The program may malfunction