Given n nodes labeled from 0 to n - 1 and a list of undirected edges, check if these edges form a valid tree (connected, no cycles).
Input: n = 5, edges = [[0,1],[0,2],[0,3],[1,4]]
Output: true
Topics: graphs
Asked by: Google, LinkedIn
Time complexity: O(V alpha(V)). Space complexity: O(V).