Fundamentals of Data Structures Flashcards
(36 cards)
Define ‘static data structure’.
A collection of data in memory that has a fixed storage size determined at compile-time.
Define ‘dynamic data structure’.
A collection of data in memory that has the flexibility to grow or shrink at run-time.
Explain two differences between static and dynamic data structures.
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.
Which type of data structure requires a pointer.
Dynamic data structures require memory to store a pointer to the next item which static data structures do not require.
What are the three types of queues?
Priority
Circular
Linear
What type of data structure is a stack
LIFO
Last item in is the first item out
What is an abstract data type?
A system described in terms of its behaviour, without regard to its implementation.
What type of data structure is a queue
FIFO
First item in is the first item out
How many pointers does a queue require?
Two pointers
One for the front of the queue, and another for the back.
How many pointers does a stack require?
One pointer
It points to the top of the stack.
What operations are implemented for a stack?
Push (add item)
Pop (remove item)
Peek (view item)
Describe the algorithm for insertion into a stack.
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.
Describe the algorithm for insertion into a queue.
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.
Describe the algorithm for deletion/reading from a queue.
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)
What are the components of a graph
Vertex
Edge
State two advantages of using an adjacency matrix.
Very quick and easy to work with
Adding new edges / checking for presence of edges is simple and quick using a 2D array.
State two disadvantages of using an adjacency matrix.
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.
What is the best way to store a sparse graph?
Adjacency list, they are very space efficient.
State the components of a tree.
Root node
Children nodes
Branches
Leaf nodes
What are the properties of a binary tree.
No more than two children per node.
Each node consists of data, a left pointer, and a right pointer.
What is an array?
Stores data of the same type in contiguous memory locations.
What is a hash table?
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.
What is a collision when working with hash tables?
Collisions happen when two or more keys point to the same array index.
What does a good hash function do?
Keep collisions to a minimum.