Generating Random Unweighted Trees
- Since this is a tree, the test data generation plan is such that no cycle gets formed.
- The number of edges is one less than the number of vertices
- For each RUN we first print the number of vertices - NUM first in a new separate line and the next NUM-1 lines are of the form (a b) where a is the parent of b
Time Complexity : O(V + E)
Space Complexity : O(V)
Generating Random Weighted Trees
- Since this is a tree, the test data generation plan is such that no cycle gets formed.
- The number of edges is one less than the number of vertices
- For each RUN we first print the number of vertices - NUM first in a new separate line and the next NUM-1 lines are of the form (a b wt) where a is the parent of b and the edge has a weight of wt
Time Complexity : O(V + E)
Space Complexity : O(V)
If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above