The problem
Consider a set of $N$ vertices $V=\{v_1,v_2,...,v_N\}$. We define a random directed acyclic graph by the set of edges $E$ as follows: for every $i<j$, $e_{ij}:=(v_i\rightarrow v_j) \in E$ with probability $p$, independent of other edges.
We are looking for an algorithm to determine the "maximal" or "upstream" vertices; that is, output the set $$V_{\max}=\{v_i\mid \forall j, e_{ij} \notin E\}$$
Assume that the indexing (used in problem statement for convenience) is not accessible to the algorithm (i.e., given $v_i$ and $v_j$, there is no direct way to know whether $i<j$ or $j<i$ without looking at the edges).
We consider two possible conditions:
- the set of all edges is fed as an input to the algorithm; looping over all edges is a $O(|E|)$ operation, testing a if a given edge exist is $O(1)$
- the set of all edges is not known; an oracle can tell us whether a given edge exists in $O(1)$ (we want to minimize the number of such queries) but looping over all edges is $O(N^2)$ (requires to query every possible edge).
The graphs in question are called "stochastic ordered graphs" or "Barak-Erdös graphs" in the literature (after the authors of the 1984 paper On the maximal number of strongly independent vertices in a random acyclic directed graph.). I searched Google-Scholar a bit, but I found mostly math papers interested in percolation theory / longest path problems etc. rather than the maximal subsets, and nothing in the way of construction algorithms (although this is not my field at all, and I might have missed obvious stuff).
Already known
A previous question (Finding maximal elements of a partially ordered set) roughly approximates condition 2 (edges are not necessarily a preorder because of a lack of transitivity, but adding edges to make the graph transitive does not change $V_{\max}$). The following findings are applicable:
- a simple algorithm in $O(N^2)$ exists to solve both conditions
- there are graphs where no algorithm can do better than this: for instance, for $p=0$ (the graph has no edge) in condition 2, all $O(N^2)$ possible edges must be queried (to differentiate this case from the one where a single, unqueried edge exists).
- there are cases where a quicker runtime is possible: for instance, for $p=1$ (every possible edge exists), any (sane) algorithm is linear in either condition (every edge query will eliminate one vertex from consideration, leaving only $v_1$ after $O(N)$ operations).
The interesting case is $0<p<1$, and the question is whether there is any reasonable expectation to find an algorithm that is sub-quadratic on average.
Obviously, if $|V_{\max}|=O(N^2)$, then any algorithm must be in $O(N^2)$ runtime (since it must at least output $V_{\max}$). However, this never happens for $p>0$. The abstract of the 1984 Barak-Erdös paper states (I cannot access the full text) that the cardinal of the largest strongly independent subset grows as $O(\sqrt{\log N})$. Therefore, the cardinal $V_{\max}$ grows at most at $O(\sqrt{\log N})$, though possibly less, and I could not outright refute the existence of a subquadratic algorithm. ($V_{\max}$ is not necessarily the largest strongly independent subset. For instance, consider the graph with vertices $1,2,3$ and edges $1\rightarrow 2, 1\rightarrow 3$; then $V_{\max}=\{1\}$ has cardinal 1 but $\{2,3\}$ is a strongly independent subset with cardinal 2.)
Some speculation
Given that $|E|\approx p\frac{N^2}{2}=O(N^2)$, it seems to me that conditions 1 and 2 are equivalent: any looping over the edges will immediately incur a quadratic cost, therefore any sub-quadratic algorithm needs to not look at a majority of the edges.
The worst-cases exhibited by hand are usually "sparse" graphs (few edges, many vertices in $V_{\max}$), and the best case are "full" (many edges, few vertices in $V_{\max}$) graphs, so I guess there is a better chance to find such an algorithm for high $p$. The Barak-Erdös result gives me some hope the typical case for any $p>0$ resembles more the "full" case than the "sparse" case.