Given a directed acyclic graph (DAG), is there an algorithm that runs in linear time that counts the in-degree of each vertex (and the source of that edge), given that we know a root node (a node that from it you can reach every other vertex)?
0
votes
What is your input? Adjacency lists? Are your nodes identified by integers 1 to n or 0 to n - 1? In that case yes, you just walk through all edges and increment a counter in an array.
- Niklas B.
Actually, my graph is the SCC graph of an original graph. The nodes are not identified by integers. They are represented as adjacency lists, and I have a topological ordering of the SCC graph
- TheNotMe
Define linear time - linear in number of edges or number of vertices, or both?
- Bernhard Barker
Both. $O(|V|+|E|)$ is my aim.
- TheNotMe
And I wish the downvoter would first state what is wrong with my question.
- TheNotMe