Question: Need help figuring this one out. Thanks Linear? ?search Lab? ?12? ?-? ?Searching? ?Arrays 1. Please ? ?copy ? ?the ? ?following ? ?code ?

Need help figuring this one out. Thanks

Linear? ?search Lab? ?12? ?-? ?Searching? ?Arrays

1. Please ? ?copy ? ?the ? ?following ? ?code ? ?into ? ?your ? ?IDE ? ?and ? ?ensure ? ?it ? ?compiles.

public ? ?class ? ?Lab12 { public ? ?static ? ?void ? ?main(String[] ? ?args) {

String[] ? ?array ? ?= ? ?{john,ahmed,ghaith,tyler,elizabeth}; } }

2. Make ? ?a ? ?method ? ?to ? ?print ? ?a ? ?String ? ?array ? ?that ? ?accepts ? ?the ? ?array ? ?as ? ?a ? ?parameter.

3. Create ? ?a ? ?method ? ?which ? ?accepts ? ?a ? ?String ? ?array, ? ?and ? ?a ? ?string ? ?to ? ?search ? ?for ? ?as ? ?parameters, which ? ?returns ? ?the ? ?index ? ?of ? ?the ? ?first ? ?occurrence ? ?of ? ?the ? ?given ? ?string ? ?as ? ?an ? ?integer.

4. Create ? ?a ? ?boolean ? ?method ? ?which ? ?accepts ? ?a ? ?sorted ? ?string ? ?array ? ?in ? ?alphabetical ? ?order. ? ?The method ? ?either ? ?confirms ? ?that ? ?the ? ?array ? ?is ? ?sorted ? ?and ? ?returns ? ?true, ? ?or ? ?returns ? ?false ? ?if ? ?the array ? ?wasnt ? ?sorted.

5. Create ? ?a ? ?binarySearch ? ?method ? ?which ? ?accepts ? ?a ? ?sorted ? ?string ? ?array ? ?and ? ?a ? ?string ? ?to ? ?search for ? ?as ? ?parameters, ? ?confirms ? ?that ? ?the ? ?array ? ?is ? ?sorted, ? ?and ? ?returns ? ?the ? ?index ? ?of ? ?ANY occurrence ? ?of ? ?the ? ?given ? ?element ? ?as ? ?an ? ?integer. ? ?A ? ?binarySearch ? ?algorithm ? ?splits ? ?the ? ?search area ? ?of ? ?the ? ?array ? ?depending ? ?on? ?how ? ?the ? ?search ? ?string ? ?compares ? ?to ? ?the ? ?element ? ?in ? ?the middle ? ?(array[length/2].) ? ?You ? ?only ? ?need ? ?to ? ?search ? ?one ? ?half ? ?of ? ?the ? ?split ? ?array, ? ?the ? ?left ? ?half if ? ?the ? ?search ? ?string ? ?comes ? ?alphabetically ? ?before ? ?the ? ?middle ? ?element ? ?and ? ?vice ? ?versa ? ?if ? ?its alphabetically ? ?after. ? ?If ? ?the ? ?array ? ?wasnt ? ?sorted, ? ?have ? ?it ? ?return ? ?-1.

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!