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
Where is the BIOS chip located?
masya89 [10]

Answer:

on the motherboard inside the computer

6 0
3 years ago
Read 2 more answers
What is the device used for the calculations of payment and balancing the accounts record s​
Greeley [361]
A calculator or bank? Maybe an atm
6 0
1 year ago
Read 2 more answers
If you use the Justified option for a paragraph, the lines of text will __________.
saul85 [17]
The answer should be option A "<span>all be of equal length and line up at both margins." The justified option on Microsoft Word lines up the words at both margins, mainly used for types of writings and helped make the writing more neater or organized.

Hope this helps!</span>
5 0
2 years ago
If you ship bakudeku. I swear. <br> *RANTS*
Bad White [126]

cries in bakudeku shipper

3 0
3 years ago
Chris is working with other employees on a worksheet. The other employees have made comments, but they are not visible.
Vedmedyk [2.9K]
I believe the answer is A.
5 0
3 years ago
Other questions:
  • A brick weighs 26 N. Measured underwater, it weighs 11 N.
    10·1 answer
  • Universal Containers has implemented a strict software architecture for their custom Apex code. One of the requirements is that
    14·1 answer
  • With a _____ network connection, the computers and other devices on the network are physically connected via cabling to the netw
    13·1 answer
  • Why is it important to be a good digital citizen??
    11·1 answer
  • What are three reasons teens might start drinking alcohol??
    7·2 answers
  • A corporation needs an operating system that allows the various teams in its office to network and collaborate on projects. Whic
    10·1 answer
  • Give 4 examples of mnemonic codes, and what do they do?
    15·1 answer
  • You are configuring NIC teaming on a server with two network adapters. You chose Switch Independent Mode. You now must choose be
    15·1 answer
  • How to use access?<br> like working in access and bringing tables and stuff
    5·1 answer
  • What is the output of the following JavaScript code?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!