Let $G=(V,E)$ be a directed acyclic graph. I have to write an algorithm to assign integers to the vertices of $G$ such that if there is a directed edge from vertex $i$ to vertex $j$, then $i$ is less than $j$.
Could you give me some hints how to do that??
Is it maybe as followed??
L ← Set of integers S ← Set of all nodes with no incoming edges while S is non-empty do assign the lowest number i from L to first node n from S remove the node n from S remove the integer i from L for each node m with an edge e from n to m do remove edge e from the graph if m has no other incoming edges then insert m into S if graph has edges then return error (graph has at least one cycle) else return G