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
What is the purpose of "display:table"?
igor_vitrenko [27]

Answer:

Modern browsers use CSS to style all their markup.

How would they render a <table> element if CSS had nothing that could express the appearance of one?

(That, and you might have non-tabular data that you want to render like a table, there are enough people using tables for layout to see a demand for it).

They can be used to format content in a tabular manner when the markup does not use the table element, e.g. because the markup was written by someone who was told not use tables or because the markup is generic XML and not HTML.

You can also design a page using e.g. div elements so that some stylesheet formats them as a table, some other stylesheet lets them be block elements or turns them to inline elements. This may depend e.g. on the device width

5 0
2 years ago
A buffer storage that improve computer performance by reducing access time is​
kvasek [131]
Cache memory

Hope it helps
4 0
3 years ago
Which programming languages is best for game development? ​
kvasek [131]

Answer:

JavaScript. .

HTML 5.

SQL.

Python. .

Explanation:

hold it helps◕‿◕

3 0
2 years ago
US-CERT is a set of moderated mailing lists full of detailed, full-disclosure discussions and announcements about computer secur
n200080 [17]

Answer:

False

Explanation:

BugTraq is a high volume, full disclosure mailing list for the detailed discussion and announcement of computer security vulnerabilities, not US-CERT

3 0
2 years ago
You are researching RAM for a computer you are building for a friend who will be using the system as a home office server for he
belka [17]

Answer:

c) ECC

Explanation:

Based on the usage that the friend will have as well as his concern of the computer crashing due to a memory error, we can say that the best type of RAM that he can purchase is ECC memory. These are regular RAM modules but come with error correcting code. This code checks data as it passes through the RAM and auto corrects it if necessary in order to avoid crashes due to memory error.

I hope this answered your question. If you have any more questions feel free to ask away at Brainly.

5 0
3 years ago
Other questions:
  • Problem 1: Create a list that contains the months of the year. Problem 2: Create a loop to print the month number and name (do n
    7·1 answer
  • What was one of the first inventions that made it possible to communicate almost instantly?
    11·1 answer
  • What was the ENIAC computer and how was it used/what for?
    9·1 answer
  • Suppose the price of a complement to LCD televisions falls. What effect will this have on the market equilibrium for LCD​ TVs? T
    13·1 answer
  • In the formula "=A3/B3", what part of the formula is the "/"?<br><br> A)An operator<br> B)An operand
    5·2 answers
  • Who plays xbox one offline and knows some multiplayer games that can be played offline.
    15·2 answers
  • Analyze the error in the html code :<br><br> HTML
    9·1 answer
  • What does ATM mean on lego mario mean I know that this is not school related but I trying to help my brother ​
    5·1 answer
  • A large retail company hires several new joiners and would like to incorporate Virtual Reality (VR) into their onboarding proces
    11·1 answer
  • Henry wants to create a presentation for his clients. He wants to upload the presentation file directly to the Internet. Which p
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!