Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help figuring this one out. Thanks Linear? ?search Lab? ?12? ?-? ?Searching

ID: 3720889 • Letter: N

Question

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 ? ?wasn’t ? ?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 ? ?it’s alphabetically ? ?after. ? ?If ? ?the ? ?array ? ?wasn’t ? ?sorted, ? ?have ? ?it ? ?return ? ?-1.

Explanation / Answer


Hi. please find the answer above.. i have given comments so that it is very easy for you to understand the flow. In case of any doubts, please ask in comments. If the answer helps you, please upvote. Thanks!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote