Fundamentals of Data Structures Flashcards

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

Define ‘static data structure’.

A

A collection of data in memory that has a fixed storage size determined at compile-time.

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

Define ‘dynamic data structure’.

A

A collection of data in memory that has the flexibility to grow or shrink at run-time.

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

Explain two differences between static and dynamic data structures.

A

Static data structures may waste memory if the number of data items stored is less than the allocated storage space. However, dynamic data structures only take up the amount of storage space required for the actual data.

Static data structures store data in contiguous memory locations, dynamic data structures do not.

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

Which type of data structure requires a pointer.

A

Dynamic data structures require memory to store a pointer to the next item which static data structures do not require.

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

What are the three types of queues?

A

Priority
Circular
Linear

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

What type of data structure is a stack

A

LIFO
Last item in is the first item out

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

What is an abstract data type?

A

A system described in terms of its behaviour, without regard to its implementation.

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

What type of data structure is a queue

A

FIFO
First item in is the first item out

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

How many pointers does a queue require?

A

Two pointers
One for the front of the queue, and another for the back.

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

How many pointers does a stack require?

A

One pointer
It points to the top of the stack.

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

What operations are implemented for a stack?

A

Push (add item)
Pop (remove item)
Peek (view item)

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

Describe the algorithm for insertion into a stack.

A

Check if stack is full.
If the stack is full report an error and stop.
Increment stack pointer.
Insert new data item into location pointed to by stack pointer and stop.

Do the opposite for deletion (empty, decrement). To peek, copy data item from location pointed to by stack pointer.

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

Describe the algorithm for insertion into a queue.

A

Check if queue is full.
If the queue is full report an error and stop.
Increment back pointer.
Insert new data item into location pointed to by back pointer and stop.

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

Describe the algorithm for deletion/reading from a queue.

A

Check if queue is empty.
If the queue is empty report an error and stop.
Copy data item from location pointed to by front pointer. (reading only)
Increment front pointer and stop. (deletion only)

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

What are the components of a graph

A

Vertex
Edge

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

State two advantages of using an adjacency matrix.

A

Very quick and easy to work with
Adding new edges / checking for presence of edges is simple and quick using a 2D array.

17
Q

State two disadvantages of using an adjacency matrix.

A

If the graph is sparse (lots of nodes but very few edges), it results in lots of wasted memory.

Implementing it as a 2D array can make it difficult to add / delete nodes.

18
Q

What is the best way to store a sparse graph?

A

Adjacency list, they are very space efficient.

19
Q

State the components of a tree.

A

Root node
Children nodes
Branches
Leaf nodes

20
Q

What are the properties of a binary tree.

A

No more than two children per node.
Each node consists of data, a left pointer, and a right pointer.

21
Q

What is an array?

A

Stores data of the same type in contiguous memory locations.

22
Q

What is a hash table?

A

A data structure that maps keys to values using a hash function.
It is used to insert, look up, and remove key-value pairs quickly.

23
Q

What is a collision when working with hash tables?

A

Collisions happen when two or more keys point to the same array index.

24
Q

What does a good hash function do?

A

Keep collisions to a minimum.

25
Q

How are collisions handled in a hash table? Describe two methods

A

Open addressing, look for the next available empty space in the table. This may cause clustering.

Separate chaining, a linked list of objects that hash to each slot in the hash table is present. Two keys are included in the linked list if they hash to the same slot. This is good for handling several collisions.

26
Q

Describe the algorithm for adding a value to a hash table.

A

Feed in key to hash function.
Go directly to array index.
If location is empty insert the value.
Otherwise, follow linked list in sequence until free space is found.
Insert value.

27
Q

Describe the implementation of a dictionary.

A

Stores groups of objects using key value pairs. Each key has a single value associated with it, which is returned when the key is supplied.

28
Q

State a use of dictionaries

A

Dictionary encoding

29
Q

How can a vector with three components, drawn from the set of real numbers be represented?

A

3-vector over R
R^3

where R is the symbol for set of real numbers.

30
Q

How can a vector be represented?

A

As a list
As a 1D array
As a dictionary (which can be considered to be representing it as a function)
Graphically (as an arrow)
Using set notation

31
Q

a = (5, 13) b = (29, 5)

a + b = ?

A

(34, 18)

32
Q

multiplying a = (5, 13) by 2 will give the vector…

A

(10, 26)

33
Q

what is the expression for the convex combination of vectors?

A

(a * u) + (b * v)
OR
au + bv

a is alpha, and b is beta
a + b = 1
a and b are greater than or equal to zero
u and v are vectors

34
Q

a = (2, -1) b = (-7, -4)

What is the dot product of a and b?

A

a.b = (2 * -7) + (-1 * -4) = -14 + 4 = -10

a.b = -10

35
Q

What is the purpose of finding the dot product of two vectors?

A

Can be used to find the angle between them.

36
Q

What is the formula for finding the angle between two vectors?

A

cos(theta) = a.b / |a|.|b|