What is a graph?
An abstract data structure used to represent complex relationships between items within datasets.
What can graphs represent?
They can be used to represent networks such as transport networks, IT networks and the Internet.
What is a node?
A fundamental unit in a graph which contains data and pointers to other nodes.
What is an edge?
A connection between two nodes in a graph.
What is a weighted graph?
A graph where the edges are assigned a value. E.g. a map of towns and the distance between them.
What is a directed graph?
A graph where the edges have a direction. The edges cannot be bi-directional.
What are the two ways in which a graph can be represented?
By using adjacency matrices or adjacency lists.
Explain an adjacency matrix for an undirected graph.
A one is used to show that an edge exists between two nodes and a zero indicates that there is no connection.
Adjacency matrices have a characteristic diagonal line of 0s where the row and column represent the same node.
They also display diagonal symmetry.
Explain an adjacency list for an undirected graph.
For each node in the graph, a list of adjacent nodes is created. This means that an adjacency list only records existing connections in a graph, unlike an adjacency matrix which stores even those edges that don’t exist.
What is the space consideration for a matrix?
Stores every possible edge, even those that don’t exist. Requires more memory (O(n^2)). If undirected, half the matrix is repeated data.
What is the space consideration for a list?
Only stores edges that exist.
Requires less memory.
What is the time consideration for a matrix?
Specific edges can be accessed instantly (O(1)) by looking up its row and column.
What is the time consideration of a list?
Slow to access specific edges as each item in a list must be searched sequentially (O(n)).
When do you use a matrix?
Use when graphs have a large number of edges, or when edges need to be frequently changes/checked.
When do you use a list?
Use when there are few edges or when edges are not frequently changed/checked.