1.4.2 Data Structures Flashcards
Array
A static data structure used for storing a finite, ordered set of data of the same data type within a single identifier. They are contiguous.
How to find a given position within a 2D/3D array
Use the reverse to the method used to find a set of coordinates.
EG: 3D [z,y,x]
How can a 2D array be visualized as?
Table/spreadsheet
How can a 3D array be visualised as?
Multi-page spreadsheet / multiple 2d arrays
Record
A data structure that stores data in elements called fields, organised based on attributes.
What is a List?
- A dynamic data structure that can store multiple values of different data types.
- They are mutable, meaning values can be changed or replaced.
- List values are stored non-contiguously.
Tuple
A data structure for storing an immutable, ordered set of data, which can be of different data types, within a single identifier.
Linked list
- A dynamic data structure consisting of an ordered sequence of nodes.
- Each node has a data field and pointer field.
- Each pointer points to the next node in the sequence.
- They are non-contiguous.
Name the pointers used by linked lists.
Start Pointer
Free Pointer
What is the procedure for adding an item to a linked list.
Add the new value to the end of the linked list, and update the free pointer.
Update the node that currently has a null pointer to point to the new item.
Update the pointer of the new item to have a null pointer.
What is the procedure for removing an item from a linked list.
The pointer in the previous item changes to the pointer held by the item that is to be removed, effectively bypassing the removed item.
Disadvantages of linked list
- Removing nodes from a linked list does not truly remove it. This wastes memory.
- Storing pointers also means more memory is required compared to an array.
- As items in linked lists are stored in a sequence, they can only be traversed in this order. This means they cannot be directly accessed, as is possible in an array.
Graph
A dynamic data structure. It is a collection of data nodes (known as vertices), connected by edges.
Describe the three categories of graph.
Directed: Edges can only be traversed in one direction
Undirected: Edges can be traversed in both directions
Weighted: A cost is attached to each edge.
What are the two ways of traversing a graph?
Breadth-first (using queue)
Depth-first (using stack)
Stack
A LIFO data structure, meaning items are added to the top and removed from the top.
They have a pointer which points to the top of the stack, where the next piece of data can be added.
Name some operations you can perform with a stack.
Push
Pop
isFull
isEmpty
peek
size
Queue
A FIFO data structure, meaning items are added to the end of the queue and removed from the front.
It uses a front and back pointer to show the item that can be removed and the item that can be added.
Name some operations you can perform with a queue
enQueue
deQueue
isEmpty
isFull
What is the difference between circular and linear queues?
Once the queue’s rear pointer is equal to the queue’s max size, it loops back to the front of the array and stores values there (provided it is empty).
Pros/Cons of circular queue
Uses space in an array more effectively.
Harder to implement.
Why are linear queues ineffective compared to circular queues.?
Linear queues implemented using an array can become ineffective over time as dequeued elements leave unused spaces in the array, while circular queues are more efficient as they wrap around and reuse the array space as elements are dequeued.
Tree
- A dynamic data structure that branches.
- It has a root node at the top, and other nodes arranged in levels beneath it.
- Each node in a tree can have zero or more child nodes, which are connected to it by edges/branches.
Edge/Branch
Connects two nodes togetherq