DFS and BFS use heap instead of stack