Nisha Patel
Summary
Here we are using an adjacency list representation for an undirected graph in order to check for the presence of cycles, a key characteristic of trees.
We will initialize an ArrayList of ArrayLists. This will represent the adjacency list of each vertex of the graph.
Solution
Explanation
Initialize a counter ‘cnt’ to count the number of connected components in the graph.
The visited vertices are recorded in the visited array.
If the component (tree) is the only one connected, return true; if not, return false.
Suggested blogs:
>Find the number of pairs of elements whose sum is equal to K using C++
>How to check whether string is palindrome or not using C++
>How to determine the smallest possible size of a vertex cover using C++
>Build an Electron application from scratch
>Building Web API using ASP.NET (C#)
>Built Web API using ASP.NET (C#)