Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/*****Modify the recursive implementation of binary search from the code below, so that the search method workd on any array of type Comparable[].*******/ Test The

/*****Modify the recursive implementation of binary search from the code below, so that the search method workd on any array of type Comparable[].*******/

Test The implentation with arrays of different types to see if it works.

- Be sure you search for items in all parts of the array and for items not in the array

- use an array of strings as one of your options

- print your arrays before searching so it's easy to see if the item is there.

- you decide how you want to input your data -- hardcore it, read it from the keyboard, read it from a file

public class BinarySearch { public static int search(int[] a, int first, int last, int key) { int result = 0; if(first>last) result = -1; else { int mid = (first + last)/2; if(key == a[mid]) result = mid; else if(key < a[mid]) result = search(a, first, mid -1, key); else if(key > a[mid]) result = search(a, mid + 1, last, key); } return result; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions

Question

apply communication design concepts into creative projects.

Answered: 1 week ago

Question

=+derived from the assignment will balance the costs?

Answered: 1 week ago

Question

=+6 Who is the peer of the IA ?

Answered: 1 week ago