DSA Flashcards

1
Q

Solution for traversing a dependency graph - like courses dependent on other courses, or a build sequence with dependencies

A

Topological Sort

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

How does Kahns Algorithm (for Topological sort) work ?

A

Find in_degrees of all nodes. Then repeatedly remove nodes that have no dependencies (in_degree = 0), reducing the in_degree of their neighbors and making them candidates if it comes down to 0.
The excercise is complete if all nodes are reduced to 0 in the end, which will not happen if there are cycles because all nodes in the cycle will retain in_degree of >=1

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