Develop a performance-testing client that takes an int value T from the command line and performs T trials of the following experiement: generate the connections in an N-by-N square grid, randomly oriented and in random order, then use UnionFind to determine connectivity as in our development client, looping until all sites are connected. For each N, print the value of N, the average number of connections processed, and the ratio of the running time to the previous. Use your program to validate the hypotheses in the text that the running times for quick-find and quick-union are quadratic and weighted quick-union is near-linear. Note : As N doubles, the number of sites in the grid increases by a factor of 4, so expect a doubling factor of 16 for quadratic and 4 for linear.
Develop a performance-testing client that takes
an int value T from the command line and performs T trials of the following experiement: generate the connections in an N-by-N
square grid, randomly oriented and in random order, then use UnionFind to determine
connectivity as in our development client, looping until all sites are connected. For each
N, print the value of N, the average number of connections processed, and the ratio of
the running time to the previous. Use your program to validate the hypotheses in the
text that the running times for quick-find and quick-union are quadratic and weighted
quick-union is near-linear. Note : As N doubles, the number of sites in the grid increases
by a factor of 4, so expect a doubling factor of 16 for quadratic and 4 for linear.
Step by step
Solved in 3 steps