We have n items entering and leaving a queue, they could enter and leave at any time. The information we have is that for each pair (a, b), we know either
1) a leaves the queue before b enters or vice versa;
2) at some point, a and b are in the queue at the same time. or
3) no information at all.
Suppose we are given a list of pairwise information for all (n choose 2) pairs, find a O(n2) algorithm to determine if there is any inconsistency in the information.
For example, a leaves before b enters (for simplicity, write it as a>b), b>c, and c=a is inconsistent, since there is no possible timeline of a, b, c to enter and leave the queue that makes all three statements true.
I thought about making this a graph transversal problem, each item as a vertex, pairwise relation as an edge, if a>b or b<a then it's a directed edge, if a=b then it's an undirected edge, then this problem may be reduced to some sort of cycle detection in a mixed graph (with directed or undirected edges), where algorithms such as DFS or BFS can be applied. However, it's not just any kind of cycle leads to inconsistency, obviously if all edges in the cycle are directed, then it's inconsistent for sure, as > or < is transitive. However, if all edges in a cycle are undirected, there is no inconsistency. Or if some are directed or some are undirected, could be either inconsistent or consistent. For example, a>b, b>c, and c=a is inconsistent, while a=b, b=c and c>a is consistent.
Any input and idea will be greatly appreciated!