4.2 - Graphs Flashcards

1
Q

What are graphs?

A

Graphs are an abstract data structure used to represent complex relationships between items within datasets. Graphs can be used to represent networks such as transport networks, IT networks and the Internet.

A graph consists of nodes (also known as vertices) which are joined by edges (sometimes called arcs). A weighted graph is one in which edges are assigned a value, representing a value such as time, distance or cost for example.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Unweighted, Undirected Graph vs Weighted, Directed Graph

A

Unweighted, Undirected Graph has no arrowheads or values on the edges (lines connecting the nodes)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can graphs be represented?

A

Adjacency Matrices and Adjacency Lists

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Explain adjacency matrices.

A

An adjacency matrix is a tabular representation of the graph. Each of the nodes in a graph is assigned both a row and a column in the table.

They always show diagonal symmetry.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In an unweighted graph, how are the matrices represented?

A

1 in the table represents that an EDGE EXISTS between two nodes.

0 indicates that there is NO CONNECTION.

Adjacency Matrices always have a diagonal line of 0s, represented when the row and column represent the same node.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In a weighted graph, how are the matrices represented?

A

Rather than using 1s and 0s, adjacency matrices contain the weight of a contain between two nodes.

If no connection exists, an arbitrarily large value is used (infinity symbol). This presents any shortest path algorithm from using any non existent edges.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Explain adjacency lists.

A

Instead of using a table to represent a graph, a list can be used.

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Adjacency Lists vs Adjacency Matrices

A

Adjacency Matrix:
ADVANTAGE - Time Efficient: Allows a specific edge to be queried very quickly, as it can be looked up by its row and column.
DISADVANTAGE - Memory Inefficient: Stores every possible edge between nodes, even those that don’t
exist. Almost half the matrix is repeated data.

Adjacency List:
ADVANTAGE - Memory Efficient: Only stores the edges that exist in the graph
DISADVANTAGE: Time Inefficient: Slow to query, as each item in a list must be searched sequentially until the desired edge is found.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly