Data Structures Flashcards
What is a primitive data type?
A data type that can’t be broken down further.
What is an abstract data type?
A conceptual model of how data is to be organised and the operations we might perform on the data.
What is a data structure?
Implementation of ADTs. Can combine multiple data under a single identifier.
What are the key ADTs?
- Stacks
- Queues
- Graphs
- Trees
- Hash Tables
What are arrays?
Static data structures that stored data of the same type arranged as a contiguous block in memory with a fixed length
How does indexing work in arrays?
The index acts as an offset to the data from the start off the structure in memory. For this reason the dimensions and data type of the array must be known.
What is a multidimensional array?
An n-dimensional array is a set of elements with the same data type that are indexed by a tuple of n integers, where a tuple is an ordered list of elements.
What are the uses of arrays?
- Can store multiple homogenous values
- Can represent vectors
- Can store tabular data in a matrix
- 2D arrays are common in machine learning applications that consist of large related data sets
What are the advantages of static data structures?
- Do not require pointers so take up less space
- Can randomly access any element in constant time because data is stored continuously in memory
- Faster than dynamic data structures
What are the disadvantages of static data structures?
- Cannot grow to accommodate more data being declared
- Cannot shrink to free up memory
- Inefficient if more space is allocated than required
- Can lead to errors if not enough space is allocated
On what kind of basis is date retrieved from a stack?
Last-In-First-Out
On what kind of basis is data retrieved from a queue?
First-In-First-Out
What are the key operations of a stack?
- Push
- Pop
- Peek
- Test for empty stack
- Test for full stack
What are the key operations of a queue?
- Add and item
- Remove an item
- Test for an empty queue
- Test for a full queue
What is a stack overflow?
An attempt is made to push more data onto the stack that it can store
What is a stack underflow?
Occurs when a pop is attempted on an empty stack.
What are stacks comprised of?
- A sequence of items
- A stack pointer
What are queues comprised of?
- Sequence of items
- Rear pointer
- Front pointer
What are the uses of stacks?
- Reversing sequences of items
- Maintaining “undo” lists in applications
- Maintaining a web-browser history
- Storing processor state (register values) when handling an interrupt
What are the uses of queues?
- Maintaining a queue of print jobs
- Managing an input buffer
- Handling multiple file downloads
- Maintaining a playlist of media
Test if a stack is empty?
- Check if the stack pointer is equal to -1
Test if a stack is full?
- Compare the stack pointer to the maximum size of the array (-1)
Push an item onto a stack?
- Check if the state is full if not…
- Increment the stack pointer by 1
- Assign the pushed item to the element within item indexed by the stack pointer
Peeking a stack?
- Check if the stack is empty, if not…
- Return the item at the stack pointer
Popping a stack?
- Check if the stack is empty, if not…
- Decrement the stack pointer
- Return the item at the stack pointer + 1
What is a linear queue?
A simple static and array based implementation of a queue
What are the advantages and disadvantages of linear queues?
+Simple to program
-Can lead to wasted capacity as memory is never used up
-Process of shuffling data to solve this issue is inefficient
What is a circular queue?
A static array based implementation of a queue with “wrapping” front and rear pointers