Implement DFS generation algorithm