Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a binary search method called binarySearchAlgorithm(). The element to be searched for will be entered by the user. The binarySearchAlgorithm() method should accept the

Create a binary search method called binarySearchAlgorithm(). The element to be searched for will be entered by the user.

The binarySearchAlgorithm() method should accept the element being searched for as well as the array of elements as parameters. If the element is found, the binarySearchAlgorithm() method will return the index of where the element resides in the array. If the element is not found, the method will return a -1.

Use this main() method:

public static void main(String[] args) { int [] orderedArray = {8, 10, 12, 15, 19, 22, 28, 31, 34, 42, 47, 54, 60, 66, 72, 78, 80, 81, 94, 98, 100}; int element, index;

Scanner keyboard = new Scanner(System.in); System.out.print("Enter an element to find in the ordered array: "); element = keyboard.nextInt();

index = binarySearchAlgorithm(element, orderedArray);

if (index < 0) System.out.println(" Element " + element + " does not exist in this array"); else System.out.println(" Elemnt " + element + " resides at index " + index); }

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2022 Grenoble France September 19 23 2022 Proceedings Part 4 Lnai 13716

Authors: Massih-Reza Amini ,Stephane Canu ,Asja Fischer ,Tias Guns ,Petra Kralj Novak ,Grigorios Tsoumakas

1st Edition

3031264118, 978-3031264115

More Books

Students also viewed these Databases questions

Question

How does the character grow as a result?

Answered: 1 week ago

Question

Explain methods of metal extraction with examples.

Answered: 1 week ago