Graphs Flashcards

1
Q

What is a ‘graph’?

A

A set of vertices and edges

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

What does it mean for two vertices to be (adjacent)?

A

Two vertices are adjacent if there exists an edge connecting them.

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

What is a ‘Weighted Graph’?

A

A graph in which a values is associates w/ each edge.

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

What is a ‘Directed Graph’?

A

A graph in which every edge has a direction associated with it.

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

What is a ‘Dependency Graph’?

A

A data structure formed by a directed graph that describes the dependency of an entity in the system on the other entities of the same system.

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

What are the two ways in which graphs are represented?

A
  1. Adjacency Matrix
  2. Adjacency List
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the runtime for determining if there is an edge between two vertices?

A
  1. Adjacency Matrix: Theta(1)
  2. Adjacency List: O(d)/O(V)
    where d is the degree of the vertex.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the runtime for determining all vertices adjacent to a given vertex?

A
  1. Adjacency Matrix: Theta(V)
  2. Adjacency List: O(d)/O(V)
    where d is the degree of the vertex.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the space requirements for each representation of a graph?

A
  1. Adjacency Matrix: Theta(V^2)
  2. Adjacency List: Theta(V+E)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

When should you use an Adjacency Matrix?

A
  1. Small Graphs
  2. Dense Graphs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

When should you use an Adjacency List?

A
  1. Large Graphs
  2. Sparse Graphs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is BFS used for?

A

BFS is used for finding the shortest path on an unweighted graph.

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

What type of data structure does a BFS algorithm use?

A

The BFS algorithm uses a queue.

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

What if the count of an index in BFS is not 0?

A

This means that there is an unvisited layer.

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

What is a DFS algorithm used for.

A

The most fundamental algorithm used to explore nodes & Edged of a graph.

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

What to BFS and DFS runtimes depend on?

A

They both depend on how the graph is represented.

17
Q

What are the runtimes for BFS?

A
  1. Adjacency Matrix: Theta (V^2)
  2. Adjacency List: Theta (V^2)
18
Q

What are the runtimes for DFS

A
  1. Adjacency Matrix: Theta (V+E)
  2. Adjacency List: Theta (V+E)
19
Q

Explain ‘Topological Sort’?

A

Topological sort takes a ‘directed’ graph and returns an array of the nodes where each node appears before all the nodes that it points to.

20
Q

What type of data structure does the Topological Sort algorithm use?

A

A min heap priority queue.

21
Q

Explain ‘Prim’s Algorithm’ and its runtime?

A

Prim’s Algorithm is used to construct a ‘minimum spanning tree’, which is the set of edges of the minimal cost that connects all edges.

Runtime: O(|E|lg|V|)

22
Q

Explain Dijkstra’s Algorithm and its runtime?

A

Dijkstra’s algorithm finds a single source shortest path across the graph.

Runtime: O(|E|lg|V|)

23
Q

Explain ‘Kruskal’s Algorithm’ and its runtime.

A

Kruskal’s algorithm sorts edges by weight and if two edges have the same weight, it puts the lower edge first.

24
Q

What algorithm does Kruskal’s Algorithm depend on?

A

Union-find

25
Q

Explain the ‘Union-find’ algorithm and its operations.

A

The union-find algorithm is used to detect cycles.

  1. makeSet(x): Creates single node trees
  2. union(x,y): Attaches the root of y’s subtree to the root of x’s subtree.
  3. find(x): Follows the pointer chain from x to the root