Breadth first traversal with functions for xor gate, and gate(s) in progress