Graph theory Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is a graph?

A

A set of vertices or nodes connected by edges or arcs which can have weights and directions.

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

What is a tree?

A

A connected, undirected graph with no cycles

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

What is an adjacency matrix?

A

A square matrix used to represent a graph.

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

Why are adjacency matrices sometimes not suitable?

A

In a very large or sparse graph, many of the values in the matrix will be 0. In this case you would use an adjacency list. Adjacency lists are also appropriate when edges are rarely changed.

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

What is a simple graph?

A

An unweighted, undirected graph containing no graph loops or multiple edges

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

What is meant by the valency of a node?

A

The number of other nodes it’s connected to

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

How is an adjacency list created?

A

A list of the nodes is created, and each node in the list links to a dictionary containing all the nodes connected to the aforementioned node. If the graph was not weighted, there would be no need for dictionaries and each node could just point to a list of adjacent nodes (there is no weight to store).

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

What are the 2 ways of traversing a graph?

A

Depth first: child nodes are visited before sibling nodes. This type of uses a stack.
Breadth first: sibling nodes are visited before child nodes. This type uses a queue.

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

What is the difference between a stack and a queue?

A

In a stack, items are added and removed from the same end of the stack. In a queue, items are removed from the front and added to the back

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

What are the operations of a stack?

A

pop, push and peek

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

What are the operations of a queue?

A

Enqueue and dequeue

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

Describe the depth-first search algorithm

A

Mark the starting node of the graph as visited and push it onto the stack
While the stack is not empty
Peek at top node on the stack
If there is an unvisited child of that node
Mark the child as visited and push the child node onto the stack
Else
Pop the top node off the stack

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

Describe the breadth-first search algorithm

A

Mark the starting node of the graph as visited and enqueue it into the queue
While the queue is not empty
Dequeue the next node from the queue to become the current node
While there is an unvisited child of the current node
Mark the child as visited and enqueue the child node into the queue

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

Breadth-first uses

A

Shortest path for an unweighted graph

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

Depth-first uses

A

Navigating a maze

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