Back to course home
0% completed
Graph Valid Tree (medium)
Problem Statement
Given a number n
, which indicates the number of nodes numbered from 0
to n-1
, and a list of undirected edges for the graph, determine if the graph is a valid tree.
A graph qualifies as a valid tree if it meets the following criteria:
- It has no cycles.
- It is fully connected.
Examples
-
Example 1:
- Input: n = 5, edges = [[0,1],[0,2],[0,3],[1,4]]
-
Expected Output: true
- Justification: There are no cycles in the graph, and all nodes are connected, forming a valid tree.
-
Example 2:
.....
.....
.....
Like the course? Get enrolled and start learning!