Fundamentals of Data Structures Flashcards
What is a data structure?
Any method used to stored data in an organised and accessible format.
What is an abstract data type?
A conceptual model of how data can be stored and the operations that can be carried out on it.
What is a list/array?
A set of related data items stored under one identifier.
What are static data structures?
When the size and amount of memory put aside for it doesn’t change.
What are dynamic data structures?
When the size and amount of memory used to store it can vary as the program runs.
What are the advantages of static data structures?
Fast access, as memory locations are fixed
Easy to implement and use
What are the advantages of dynamic data structures?
Can optimize storage as size can change
Adaptable.
What are the disadvantages of static data structures?
Will take up memory even if it doesn’t need to. (Inefficient)
Limited adaptability.
What are the disadvantages of dynamic data structures?
More complex to implement
Slower access, as memory locations aren’t fixed.
How do dynamic data structures work?
It uses a heap, which is a pool of unused memory. It can take more memory off the heap if needed and put blocks of unused memory back onto the heap.
What is a stack?
A Last In First Out structure, meaning the last item to be added is the first to be removed.
What is pushing in terms of a stack?
Adding a new item of data to the stack.
What is popping in terms of a stack?
Taking an item off the top of the stack.
What is peeking in terms of a stack?
Used to identify the item at the top of the stack.
What is a stack overflow error?
If an item is added and the stack has run out of memory.
What is a stack underflow error?
If the stack is empty and you try to pop an item.
What is a stack frame?
Uses stacks to stored information about a running program. (Removes its from the stack when it completes).
What does a stack frame contain?
Function arguments (parameters/data)
Return address
Saved frame pointer
What is a call stack?
A stack that keeps track of all active stack fames in a program.
When are stack frames used?
If an interrupt occurs the program details are stored in a stack frame until the interrupt has been dealt with and then the program can carry on from where it left off.
What is recursion?
The process of a subroutine calling itself.
What is a queue?
A first-in-first-out structure.
What are uses of queues?
Sending data to the CPU
Print queues.
What does enqueue do?
Adds an item to the rear of a queue.
What does dequeue do?
Removes and returns the item from the front of the queue.
What is a linear queue?
A queue organised as a line of data sequentially, where if the rear pointer is at the last position the queue is full.
What are the disadvantages of linear queues?
Can only add or remove a certain number of items.
Once elements are dequeued the empty slots are wasted ( inefficient).
Underflow and overflow errors.
What are the advantages of linear queues?
Easy to implement
Predictable behaviour
What is a circular queue?
A queue implemented as a circle, where the front and rear pointers can wrap around from the end to the start.
What are the disadvantages of circular queues?
Complex implementation
Additional isEmpty and isFull logic
Harder to debug
What are the advantages of circular queues?
Efficient memory utilization, as empty spaces are reused.
Efficiently allocates memory
Consistent performance