Lecture 3 - Topological Ordering Flashcards

1
Q

What is a DAG?

A

Directed Acyclic Graph

A directed graph with no cycles.

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

Where is topological ordering used?

A
  • project modelling (dependency modelling more specifically)
  • finding longest path or longest weighted path
  • can determine which activies are critical (i.e. on longest path)
  • scheduling and PERT networks
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

When does a graph have a topological ordering?

A

Only if the directed graph is a DAG, it is impossible to have a topological ordering if the graph has a cycle

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

What is a source?

A

A vertex of in-degree 0.

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

What is a sink?

A

A vertex of out-degree 0.

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

What is the basic fact about a DAG.

A

DAG has atleast one source and one sink.

  • otherwise a cycle could be built
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does a topological ordering imply?

A

that we label vertices 1 … n such that (u,v) < E implies label(u) < label(v)

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

What attributes do we need to add to each vertex in order to perform topological ordering?

A

A label and a count

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

What is a label?

A

The label , the lower the earlier in the order.

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

What is a count?

A

Initially it equals the in-degree of a vertex., but it is updated as the algorithm runs. It always equals the amont of incoming edges that are not labelled.

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

How does the algorithm work?

A
  • initiate the count of each vertex
  • add source to queue
    while there is element in the queue
    give label to element
    for each adjacent vertex decrease the count by 1, if it is 0 add it to queue
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

When is a vertex labelled?

A

When the number of incoming edges from unlabelled vertices is 0.

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

Predecessors of a vertex are labelled with…

A

a smaller number

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

What is the complexity of the topological ordering algorithm?

A
  • O(m+n) to find the in-degree, as we need to scan each adjacency list
  • mainloop is executed n times so O(n)
  • OVERALL IS O(M+N)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How can we determine if a digraph has a cycle?

A

Method 1:
if the source queue becomes empty before all vertices are labelled we have a cycle

Method 2:
(adaptation of dfs)
when at a vertex check if it connects to any vertex on the path that reached this vertex

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