Developed a testbed for examining the empirical efficiency of GCD algorithms. (And others as well)
Implemented several GCD algorithms.
Experienced collecting and interpreting data related to the empirical performance of algorithms.
Please modify my example program
Implement a non recursive Euclid's GCD algorithm.
Implement the Binary GCD algorithm
gcd(0, v) = v, because everything divides zero, and v is the largest number that divides v. Similarly, gcd(u, 0) = u. gcd(0, 0) is not typically defined, but it is convenient to set gcd(0, 0) = 0.
If u and v are both even, then gcd(u, v) = 2*gcd(u/2, v/2), because 2 is a common divisor. Don't test for even with divide or mod, us a logical and. Don't divide either, shift right one.
If u is even and v is odd, then gcd(u, v) = gcd(u/2, v), because 2 is not a common divisor. Similarly, if u is odd and v is even, then gcd(u, v) = gcd(u, v/2).
If u and v are both odd, and u >= v, then gcd(u, v) = gcd((u - v)/2, v). If both are odd and u < v, then gcd(u, v) = gcd((v - u)/2, u). These are combinations of one step of the simple Euclidean algorithm, which uses subtraction at each step, and an application of step 3 above. The division by 2 results in an integer because the difference of two odd numbers is even.
Repeat steps 2-4 until u = v, or (one more step) until u = 0. In either case, the GCD is 2kv, where k is the number of common factors of 2 found in step 2.
Suggest a hybrid of the Sieve and the Consecutive routines.
Add a second test driver which will execute a given routine a given number of times, generating new random input each time. The driver should return the average run time for the routine.
Use the driver described above to test each algorithm at least 10 times for different random values with 6 bits, 14 bits, 22 bits and 30 bits. (Do not test the School routine with this driver, but do test your two new routines)
Use the data that you collected, along with your favorite graphing software (ie excel or oocalc) to draw a graph comparing the speeds of the different implementations. You may need to present the data in different graphs to provide meaningful data.
For each test size
for the number of tests at each size
generate a random input
For each Algorithm
Run the test and record the time spent
calculate the average of each test (total time/runs)
as the data point for that algorithm at that size
So each data point on the graph will be an average of at least ten runs with different input of the same size
Since you are asked to test at 6, 14, 22 and 30 bits, you will run each routine 10* 4 times
This will produce 4 datapoints per routine.
Write a summary describing what you have discovered in your empirical investigation of GCD algorithms. This should address issues similar to :
What are the empirical performances of each routine?
Is there any point where one routine should be preferred?
Is there any strange behavior worth further investigation?
Are there any routines which should be discarded? Why?
Are there any improvements which could be made to improve the performance of the routines?
You should submit your code via email to danbennett360@gmail.com on the due date. Submit your report in class.