Graphs Flashcards

1
Q

What is a graph?

A

It’s an abstraction to represent connectivity between objects Formally an undirected graph G it a collection of vertices V and edges E between pairs of them.

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

What is a loop in a graph? What is a simple graph?

A

It’s a path which connects a vertex to itself. A simple graph is a graph with no loops.

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

Describe ways to represent graphs in computer and compare their performance

A
  1. Edge list 2. Adjacency matrix 3. Adjacency list
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Let’s say we have a graph G and a vertice s. How to find all vertices v in G such that there is a path from s to v?

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

What is an idea of DFS? Runtime?

A

O(|E|) + O(|V|)

Each vertex is marked as visited exactly once - O(1) work per vertex

Each vertex checks each neighbour and total number of neighbours in O(|E|)

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

What is a connected component in an undirected graph?

A

It’s a set of vertices of a G, such that v is reachable from w if and only if they are in a same connected component.

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

How to find connected components in an undirected graph?

A

Use the modification of DFS with markers for connected components

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

What is a DAG?

A

A directed acyclic graph is a directed graph G without cycles.

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

What directed graphs can be linearly ordered?

A

Any DAG can be linearly ordered. A graph with a cycle can not be.

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

What are strongly connected components in a DAG?

A

The vertices v and w in a DAG G are connected if you can reach v from w and w from v. A DAG can be partitioned into strongly connected components where two vertices are connected iff they are in the same cmponents

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

What is a metagraph? What properties it has?

A

It’s a graph describing connectivity between strongly connected coponents. A metagraph is a always a DAG.

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

What are sources/sinks?

A

A source is a vertex with no incoming edges, and a sink is a vertex with no outgoing edges.

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

How to do a topological sort of a DAG?

A
  1. DFS(G)
  2. sort vertices by reverse post-order
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to compute strongly connected components of a DAG?

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

What is the idea behind computig strongly connected components?

A

Idea: If v is in a sink SCC, explore(v) nds vertices reachable from v. This is exactly the SCC of v.

The vertex with the largest postorder number is in a source component!

Find sink components of G by running DFS on G R

Don’t need to rerun DFS on G R . Largest remaining post number comes from sink component.

Runtime O(|V | + |E|)

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

What are main ideas of Dijkstra’s algorithm?

A