Depth first search both recursively and non-recursively works.