Question: SUMMARY all in java plz Adjust the code we did in class to do a recursive binary search on a sorted array of Strings instead

  1. SUMMARY all in java plz

  1. Adjust the code we did in class to do a recursive binary search on a sorted array of Strings instead of integers.

  1. This lab will involve the following new features:
    1. Recursion
    2. Binary Search Algorithm

  1. DETAILS

  1. These instructions will be more bare than usual since the source code from class is being provided and I want you to think through all the changes you need to make.

  1. Set up your String array.
    1. Instead of having a "for" loop populating your array with random numbers, go ahead and make your array 10 in length and populate it in 10 lines of code that put a different string in each array slot, such as:

asWords[0] = "Frank";

...

  1. Change all references to the array and any references pulling values from the array to String type instead of int type.

  1. Adjustment to binary search method.
    1. Besides figuring out which things have to now become String type, you need to compare the string values a bit different than the integers by using the "equals" and "compareTo" methods.
      1. Example for equals check:
        1. Instead of...
          1. iTarget == ...
        2. It's this...
          1. sTarget.equals(...)
      2. Example for greater than check:
        1. Instead of...
          1. iTarget > ...
        2. It's this...
          1. sTarget.compareTo(...) > 0
            1. The reason you are seeing if the comparison is greater than 0 is because the "compareTo" method returns a number greater than 0 if sTarget is greater than the string that's passed in the parentheses. If it's equal, it returns 0 (but that won't happen because the equals comparison was in the first if statement). And if it's less than, it returns a number less than 0.

  1. You can remove, comment out, or update the traditional search method at the bottom of the code. It's up to you.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!