I have a connected graph, $G$. For a subset of the edges of that graph, $E$, I would like to know:
- Do these edges cut the graph, resulting in two subgraphs $A$ and $B$ such that each edge in $E$ has one endpoint in each subgraph?
- If so, how many nodes are in $A$ and $B$?
- Also, given any vertex of the original graph, does it reside in $A$ or $B$.
I have an algorithm to answer these questions.
- Start by assigning an arbitrary node to $A$.
- Then look at the neighbours of this node:
- If they are connected via an edge in $E$, assign the neighbour to $B$;
- If not, assign it to $A$.
- For all the newly assigned nodes, repeat step 2. If any of their neighbours are already assigned, check there are no contradictions.
This continues until either all nodes are assigned, or a contradiction is found. The former implies that $E$ is indeed a cut, and returns $A$ and $B$. The latter implies that $E$ is not a cut.
The complexity of this algorithm is $O(|G|)$. For large $|G| >> |E|$, this seems like it may be much more inefficient that necessary. Is there a faster method?