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