computer science homework

profileJoshuaTT

Problem solving using recursion

 

There are two skeleton programs, flesh them out following the suggestions given.

 

Recursive algorithm for calculating xn: if n = 0, return 1.0 else return x * xn-1                                       (slow technique)

Alternate (faster) algorithm: if n = 0, return 1.0 else if n is odd return x * xn-1 else { y = xn/2;  return y * y;} (fast technique).

 

Run program with several input values and compare results from fast power, slow power, and Math.pow in this table:

Show all digits displayed by your program.

 

Base

Exponent

slow power

fast power

Math.pow

3.5

64

 

 

 

5

15

 

 

 

1.25

31

 

 

 

2

17

 

 

 

 

 

String matching

Finding needle in a haystack:

If needle is longer than the haystack then failure

else if needle matches the initial portion of haystack (of same size as the needle) then success

else {

         create a shorter haystack (haystack.substring(1))

         return result from recursive call on the shorter haystack

}

 

You are allowed to use only the following methods from the Java String class: .length(), .equals(), .substring().

You are not allowed to use any other method from the String class.

 

Fill results from power calculation in this page, copy paste source code and screen shots from the two finished programs in the following pages. 

 

Submit the Word document and zipped NetBeans project folders through Isidore assignments.

 

 

 

  • 10 years ago
  • 15
Answer(1)

Purchase the answer to view it

blurred-text
  • attachment
    joshua.zip
other Questions(10)