Project #94988 - java homework

Write recursive programs for Problems I, II, III, and IV.

Problem  I.    We define the Shaw strings as follows:

      1. abb is a Shaw string.

      2. bca is a Shaw string.

      3. If S is a Shaw string, so is SaS.

      4. If U and V are Shaw strings, so is UbV.

Here a, b, c are constants and S,U,V are variables. In these rules,
the same letter represents the same string. So, if S = abb,
rule 3 tells us that abbaabb is a Shaw string.
In rule 4, U and V represent Shaw strings, but they may be different.

Write the method

public static boolean isShaw(String in)
     that returns true if in is a Shaw string and false otherwise.

Problem II.  Write the  method

public static  double getLargest(double [] a, int low, int high)

   that returns the largest number in the array slice a[low:high].

If low > high, it throws an IllegalArgumentException. Otherwise, it checks if
the slice has 1 item. If so, it returns that value. 

If the slice has 2 or more items, it divides the slice into 2 equal subslices, 
computes the largestvalues of the 2 subslices and returns the largest of the 2 values.

Problem III. We define the Raju numbers as

         Raju(0) = 1
         Raju(1) =1
         Raju(n) = Raju(n-1) + Raju(n-2) + 3 if n >= 2

 Write the method 

public static long Raju(int n)

that returns the n-th Raju number. If n < 0, the method throws an IllegalArgumentException.      

Problem IV. Write the method

public static int binarySearch(double[] arr, int low, int high,
      double inq)

that search the array slice arr[low:high] for an occurrence
of inq. If inq occurs in arr, return an index i such that
arr[i] == inq. Otherwise, return -1.

Assume that arr is sorted in increasing order. Write a recursive version of this method.


Subject Computer
Due By (Pacific Time) 11/20/2015 12:00 am
Report DMCA

Chat Now!

out of 1971 reviews

Chat Now!

out of 766 reviews

Chat Now!

out of 1164 reviews

Chat Now!

out of 721 reviews

Chat Now!

out of 1600 reviews

Chat Now!

out of 770 reviews

Chat Now!

out of 766 reviews

Chat Now!

out of 680 reviews
All Rights Reserved. Copyright by - Copyright Policy