Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

14:44 1. Modify the BinarySearch program so that if the search key is in the array, it returns the largest index i for which a[i]

image text in transcribed
14:44 1. Modify the "BinarySearch" program so that if the search key is in the array, it returns the largest index i for which a[i] is equal to key, but otherwise, returns-i where i is the largest index such that ai is less than key. It should also be modified to deal with integer arrays rather than string arrays. Note: The program should take two command- line arguments, (1) an input file that contains a sorted integer array; and (2) an integer to search for in that array public class BinarySearch public static int search(String key, Stringl] a) t return search(key, a 0, a.length); public static int search(String key, Stringl] a, int lo, int hi) lSearch for key in a[lo, hi). if (hi lo) return-1; int mid lo+ (hi - lo)/2; int cmp-almid].compareTo(key); if (cmp > 0) return search(key, a, lo, mid) else if (cmp

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

Step: 3

blur-text-image

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

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago