1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
vitfil [10]
3 years ago
9

Suppose we are performing a binary search on a sorted array called numbers initialized as follows: // index 0 1 2 3 4 5 6 7 8 9

10 11 12 13 14 int[] numbers = {-5, -1, 0, 3, 9, 14, 19, 24, 33, 41, 56, 62, 70, 88, 99}; int index = binarySearch(numbers, 18); Write the indexes of the elements that would be examined by the binary search (the mid values in our algorithm's code).
Computers and Technology
1 answer:
konstantin123 [22]3 years ago
6 0

Answer:

The indexes of the elements that would be examined by the binary search are

7 11 9

numbers[7] = 39

numbers[11] = 57

numbers[9] = 42

The values that would be returned from the search are    

39 57 42

Explanation:

The complexity of searching a value in an array using binary search is O (log n). It follows divide and conquer principle. First we have to sort the elements in the array. Here in our case the array is already sorted.

   target = (search for the value) =42

numbers[] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14    

min max

here assign min= 0 (minimum index)

max= 14 (maximum index)    

Instead of searching for the target in a sequential manner we are searching by examining the middle term in the array by using the following formula. middle = ( min + max )/2

step 1) middle = (0 + 14)/2 = 7 numbers[middle]=numbers[7] = 39

compare target value with numbers[middle]

i.e target = 42 > 39 , the target value is greater than the numbers[middle]. so we have to move to upper part of the array.

Then min= middle+1 = 7+1 = 8

max= (unchanged) 14

 

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14    

min max

step 2) middle = (8+ 14)/2 = 11 numbers[middle]=numbers[11] = 57

compare target value with numbers[middle]

i.e target =  42 < 57 ,the target value is lesser than the numbers[middle] .

Then min= (unchanged) 8

max= middle -1 =11-1 =10

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14    

min max

step 3) middle = (8+10)/2 = 9   numbers[middle]=numbers[9] = 42

i.e target =  42 = 42

Here stop the process. In this way we found our target using binary search.

You might be interested in
Which education level has the highest return on investment (ROI)?
Keith_Richards [23]
The correct option is B.
Having a bachelor degree from a college gives the highest returns on investments. People who go to college usually secure high paying jobs compare to their counterparts who have less education.
The type of college one attends also matter, for instance in USA, the college in the first position, which gives the highest return on investment is Massachusetts Institute of Technology  [MIT].
5 0
3 years ago
Read 2 more answers
What is this on G00gel Documents , how do I fix it?
mylen [45]

Answer:

Sorry but it donest show the picture

Explanation:

7 0
2 years ago
What is the computer box called?
BaLLatris [955]
It is called the desktop or case.
7 0
3 years ago
Read 2 more answers
ก
Harrizon [31]

Answer:

Rubies are used in electronics.

 

Please select the best answer from the choices provided

T

Explanation:

6 0
3 years ago
Read 2 more answers
Clunker Motors Inc. is recalling all vehicles from model years 1995-1998 and 2004-2006.Given a variable modelYear write a statem
Dominik [7]

Answer:

Following are the statement is given below

recalled = (modelYear >= 2001) && (modelYear <= 2006);                         // holding the value true if condition is true.

Explanation:

Following are the description of above statement                                                                                              

  • Declared a variable recalled of Boolean type .
  • The variable modelYear examine the above condition .
  • The variable recalled holds true if modelYear is greater then or equal 2001 and modelYear is less then or equal to 2006 otherwise if following condition is false then this variable holds False .
5 0
3 years ago
Other questions:
  • Explain how can you protect your computer from malware
    15·2 answers
  • Which of the following information security technology is used for avoiding browser-based hacking?
    11·2 answers
  • Que cambiaría personalmente en esos momentos de cuarentena​
    7·1 answer
  • A girl scout troop with 10 girl scouts and 2 leaders goes on a hike. When the path narrows, they must walk in single file with a
    12·1 answer
  • no one can succeed in his or her career without relying on others for help or opportunities. It’s best, though,
    13·1 answer
  • Ethics is a way of behaving so that you are
    7·2 answers
  • How to make a water bottle rocket??
    6·1 answer
  • Premise: Tracy has a file that contains a list of actors and the movies in which they acted. She wants to know the top 3 ranked
    8·1 answer
  • BADM-Provide a reflection of at least 500 words (or 2 pages double spaced) of how the knowledge, skills, or theories of this cou
    7·1 answer
  • When you are typing data that is in a series, such as days of the week or months of the year, you can use this tool to complete
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!