Implement alternation depth algorithm.