Exercise 5


In this exercise, you will explore an alternate way to use recursion in computing powers of integers.

First, start by reading the Supplement to Module 4 section that describes the use of BigInteger's. Nothing below will make sense until you read that first.

Next, download and examine BigPower.java, in which you will write all your code. You will see that the power() method computes powers in the standard way as described in the Module 4 supplement. You will also see calls to a method called power2(), which you are to write. This recursive method will use a slightly different approach to computing powers:

Write your code in power2() to perform the power computation recursively in the manner described above. Note: you won't need to understand any more of BigInteger's than is used in the examples shown in the Module 4 supplement. Indeed, you might try to get it working for regular int's before creating a version with BigInteger's.

Now, it's not clear that we've gained anything in this new approach. To see why it's useful, do the following:

Submission:

What else is due: