bottom to up cost O(nlogn) time, while DFS/BFS cost only O(V+E)