Consider a directed graph with AND nodes and OR nodes. The AND nodes are activated only when all the in edges into it are activated. The OR nodes are activated if at least one of the in edges into it is activated. Assuming that vertices with no in edges into them are activated initially, how to design an efficient algorithm to decide if all nodes can be activated? I have thought of some naive algorithm but it takes $O(n^{3})$ time. I believe $n^{3}$ cannot be an efficient algorithm and there's some method that I am missing. Tagging domains where the problem might have a solution.
2026-03-26 17:30:46.1774546246
On
Activating "AND" Nodes and "OR" nodes
88 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
2
There are 2 best solutions below
0
On
A idea would be to iterate over all edges, and from each edge see if a connected node is a AND or a OR node. Put at begin every node to true (activated) . If this node is a OR node, dont do nothing. If a edge is a activated node, we no need to do anything. If our edge is a not activated node, see if each of 2 nodes are OR nodes. If one of them is a AND node, and considering we have a not activated edge, we can assign this node to false (not activated) and exit inmediately, because we can return a value indicating that not all nodes are activated. Time of this algorythm is O(E). Daniel
A little modification to a dfs will work in time $\mathcal O(n^3)$. This dfs wil pass through each vertex at most $n$ times, so at most $n^2$ call to the function dfs are made, and each one takes at most $n$ iterations.
Here is the c++11 code: