Modeling an inequality problem to a graph Given $n$ variables : $a_1,a_2...,a_n$ and $m$ inequalities of the form $a_i&lt;a_j$, we want to know if there's a positioning that satisfies all the inequalities.


  a. We want to modelize the problem to a directed graph $G=(V,E)$. $V=?,E=?$


$V=\{a_i|i\in[n]\}$ $E=\{a_ia_j|a_i&lt;a_j\}$


  b. Complete the sentence: There exists a valid positioning iff...


$G=(V,E)$ doesn't contain directed cicles and parallel edges (i.e. to prevent $a_1&lt;a_2$ $a_2&lt;a_3\space$ $a_3&lt;a_1\space$ and $a_1&lt;a_2\space$ $a_2&lt;a_1$)


  c. How do we determine if there exists a valid positioning? What would be the complexity of such action?


I guess check for directed cycles (which i don't know how) and parallel edges?


  d. If there's a valid positioning, how do we find it?


By giving the vertex with maximum $d_{out}$ the lowest number and so on?

I'd appreciate help with c and d.
You’re on the right track with your response to $c$. There’s a bunch of algorithms that solve $c$ and $d$ simultaneously. If you’re familiar with depth-first search, you can use that to solve the problem.

Another approach is what’s called “topological sort.” The key idea here is that if a directed graph has no cycles, then you can put the vertices in a line such that there are only edges that go from start vertex to an end vertex such that the end vertex is to the right of the start vertex. This is actually really easy to write an algorithm to do, give it some thought and see if you can’t come up with a clever trick.

The best case time for solving this problem is $O(|V|+|E|)$, and off the top of my head I can think of four algorithms that achieve that timing.