Graphs Flashcards

(15 cards)

1
Q

What is a graph?

A

An abstract data structure used to represent complex relationships between items within datasets.

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

What can graphs represent?

A

They can be used to represent networks such as transport networks, IT networks and the Internet.

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

What is a node?

A

A fundamental unit in a graph which contains data and pointers to other nodes.

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

What is an edge?

A

A connection between two nodes in a graph.

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

What is a weighted graph?

A

A graph where the edges are assigned a value. E.g. a map of towns and the distance between them.

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

What is a directed graph?

A

A graph where the edges have a direction. The edges cannot be bi-directional.

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

What are the two ways in which a graph can be represented?

A

By using adjacency matrices or adjacency lists.

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

Explain an adjacency matrix for an undirected graph.

A

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.

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

Explain an adjacency list for an undirected graph.

A

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
10
Q

What is the space consideration for a matrix?

A

Stores every possible edge, even those that don’t exist. Requires more memory (O(n^2)). If undirected, half the matrix is repeated data.

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

What is the space consideration for a list?

A

Only stores edges that exist.
Requires less memory.

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

What is the time consideration for a matrix?

A

Specific edges can be accessed instantly (O(1)) by looking up its row and column.

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

What is the time consideration of a list?

A

Slow to access specific edges as each item in a list must be searched sequentially (O(n)).

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

When do you use a matrix?

A

Use when graphs have a large number of edges, or when edges need to be frequently changes/checked.

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

When do you use a list?

A

Use when there are few edges or when edges are not frequently changed/checked.

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