1/48
Characteristics of an array
Same data type
Numerical index
Traditionally fixed in size
Duplicates
Characteristics of a list
Dynamic size
Zero-based index
Mixed data types
Duplicates
Characteristics of a tuple
Fixed size - a new tuple must be made for new data
Mixed data types
Duplicates
Characteristics of a record
Groups related data items
Fields have meaningful names
Different data types
Represents an individual object
What are static data structures?
Collections of data that are fixed in size
What are dynamic data structures?
Collections of data that can grow/shrink in size
Unused memory is re-allocated as required
Adv/Disadv of static data structures
Adv: No issue when items are removed.
Disadv: Inefficient since memory may be left unused
Adv/Disadv of dynamic data structures
Adv: Memory is only used when it is needed
Disadv: Risk of overflow/underflow, deemed harder to program
Definition of mutable
The structure and data can be changed at runtime (after its creation)
Overflow and underflow definition
Overflow: When an item is pushed onto a full structure
Underflow: When an item is removed from an empty structure
Stack definition
A data structure with items popped on and off with a LIFO structure
Queue definition
A data structure with items enqueued and dequeued with a FIFO structure
How can we implement a stack with an array?
The stack is initialised as an empty array, with variables for the pointer and max capacity saved.
As an item is pushed, the pointer increments by 1
As an item is popped, the pointer decrements by 1
If an item is peeked at, the top item is returned
Underflow and overflow is checked for before pushing/popping to prevent error
How can we implement a queue with an array?
The stack is initialised as an empty array, with variables for the head pointer, tail pointer and max capacity saved.
As an item is enqueued, the tail pointer increments by 1
As an item is dequeued, the head pointer increments by 1
If an item is peeked at, the top item is returned
Underflow and overflow is checked for before pushing/popping to prevent error
What are the problems caused by implementing a queue via an array?
Both the pointers travel in the same direction, which can cause the queue to quickly run out of space.
Solution: Circular Queue — cycling the tail pointer to the front if it reaches the end.
Uses of stacks
Depth-first searches
Evaluating maths expressions (e.g. RPN or Shunting Yard)
Uses of queues
Breadth-first searches
Process scheduling (e.g. RR uses a circular queue)
How can you traverse through a stack/queue?
Repeatedly pop/dequeue items and output their value
What is Reverse Polish Notation? How can we convert it to infix notation with a stack?
Formatting a mathematical expression with the operators after the operands.
Push digits onto the stack until an operator is reached
Push the operator onto the stack and conduct the operation with the two previous digits
Repeat till you have one number remaining
What is the Shunting Yard Algorithm?
An algorithm used to convert infix notation to RPN.
If the value is a digit, push onto the output stack
If an operator, push onto the operator stack.
However if this has less precedence than the operator below it, push all operators below onto the output stack
Furthermore, if the operator is a closed bracket, pop the entire operator stack onto the output stack (without brackets)
Once the end of the expression is reached, pop the entire operator stack and push onto the output stack.
Graph definition
A structure with nodes and edges
Adjacency matrix definition
A matrix storing adjacency between nodes, where the columns represent nodes in the data structure. Typically implemented as dictionaries.
Cost definition
A value given to an edge which represents its relationship with the vertices
Implementation of an adjacency matrix in weighted graphs
A: {B:8, C:2, D:10}
Implementation of an adjacency matrix in unweighted graphs
A: {B, C, D}
What are the different types of traversals on a graph?
Inorder: Reads left, root, right
Preorder: Reads root, left, right
Postorder: Reads left, right, root
Way to remember: pre, in, or post references the roots position in the reading
Tree definition
A type of graph that is undirected, connected, and acyclic.
This means that there is always a findable path
Binary tree definition
A tree with 0-2 edges per node, with each connecting to a different child node.
How do we present binary trees as arrays?

How do we present binary trees as objects?

Dictionary definition and its characteristics
A general-purpose abstract data structure used for storing objects
Characteristics:
Has a set of keys
Each key holds a value
When the key is supplied, the value is returned

Uses of dictionaries
Storing/Retrieving data
Implementing other data structures
Containing categorised data
Mapping data
Operations on a dictionary
Creation
Adding key-value pair
Removing key-value pair
Appending key-value pair
Returning T/F if a key exists
Returning a value from a given key
Returning length of the dictionary
What is a hash table?
A data structure that stores key-value pairs. Used to immediately find an item in an (un)sorted list with no need for comparisons
Typically large to account for collisions between values
This can cause clustering around common collision points
What is a hashing function?
A function that calculates an items position.
3 solutions for collisions
Open addressing
Chaining
Overflow table
What is open addressing?
Collision values repeatedly check the next space until it is empty.
What is linear probing?
The process of using linear search to find key-value pairs.
What is chaining?
Using a 2D hash table, which lets multiple items be stored in the same position.
How are items removed/added?
Calculate its hash value, and find its corresponding position.
Either add it, or check if its the value we’re looking for.
If so, retrieve and delete it.
Else, search via linear probing.
Vector definition
A series of numbers used to represent spatial information
How can we represent vectors?

What is vector addition?
Combining vectors to make a resultant vector.
What is scalar vector multiplication?
Multiplying vectors by scalar values to create new vectors.
What is the convex combination of 2 vectors? How is it represented?
The area between two vectors on a graph. Represented by αu + βv where:
u and v are vectors
α + β = 1
α and β are bigger than/greater to 0
How is convex combination used?
To calculate fields of view in a game.
(Any value supplied as u and v give a vector on the hypotenuse between the two vectors)
What is the dot/scalar product?
Multiplying each matching component of the vector together, then adding the results.
How can we use the dot/scalar product?
To find the angle between two vectors, where |n| is the magnitude.
