You have more than 2 weeks to do this homework. On the other hand, it is a big one, so do not leave everything to the last few days. At least get the programming part out of the way first, as this cannot be done under time pressure. This has the usual programming part and written part, to be submitted as usual.
B1=N1, B1<N1, B1>N1.Continue from there.
First note that we are interested in getting the
asymptotic performance of the respective algorithms. For this
purpose, assume our algorithm has polynomial time complexity
and we want to determine the exponent which
occurs in the complexity expression. Thus, for example, for
Karatsuba's algorithm, the complexity of multiplying two
n bit numbers is
Theta(n(lg 3))So the exponent is
lg 3 = 1.58...We want an experimental method to obtain this exponent. In practice, we expect to get an approximation to this exponent because of various system-related factors which are out of our control. This quibbling aside, what measurements can we perform to find out the exponent?
First we can express a polynomial running time T(n) (approximately) as follows:
T(n) = C * ne,for some constants C and e. We want to find e experimentally. Taking logarithms,
log T(n) = log C + e * (log n)Thus, the log - log plot of T against n is a straight line, whose slope is the value e we want. We can estimate this slope in many ways (a well known method is called "least squares method"). Also, you need to take the measurements several times to give a more accurate reading.
In this program, instead of calculating the slope using least square estimation described above, we simply take the first value as correct, and measure the slope with respect to that value. The slope is called dimension in the code.
In the following program
timing.java
we provide
code to process the arguments in a nice way. (You are welcome
to write this stuff too). You have to fill in code which
The approach is quite straightforward. We keep a variable called numBits, which, as should be clear from the name, stores bit lengths of the two BigIntegers we are multiplying at that point. We let this bit length vary from some minimum value to some maximum value, with some step length. For each bit length, we do a certain number of trials. Each trial consists of randomly picking two bigIntegers, and multiplying them together. We measure the time taken to do this multiplication.
All the relevant parameters can be set from the command line.
What are the other problems which might arise?