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
Should I Buy a 2070 super or 2060 super
fiasKO [112]

Answer:

Which ever one you want

Explanation:

Make your heart happy

8 0
2 years ago
_____________________ denotes the use of human interactions to gain any kind of desired access. Most often, this term involves e
pishuonlain [190]

Answer:

Social engineering

Explanation:

<u>Social engineering</u> involves exploiting existing relationships and <u>manipulating people to reveal certain confidential information or to grant access to such information, systems, or networks</u>, usually for fraudulent reasons.

4 0
2 years ago
HELP!!!!!!!
Savatey [412]

Answer:

mouse - input

printer - output

keyboard - input

speakers - output

headset - both

6 0
2 years ago
Eight houses represented as cells are arranged in a straight line java int state []
monitta

Answer:

int state[] = new int[8];

8 0
3 years ago
If you don’t have a paper copy of the FAFSA form, how else can you fill it out?
Ronch [10]
Go on your school computer, and find a copy of the form. Then print it from the school printer.
3 0
2 years ago
Read 2 more answers
Other questions:
  • Can i earn money at weegy.com ?
    10·1 answer
  • Over time, attackers have had to increase their skills to be able to attack systems or create viruses. True False
    8·1 answer
  • Which feature is an interface between the user and the file system of a computer?
    6·2 answers
  • Maria is developing an online gaming website. She is working on an interactive game that has a central character guiding the vis
    14·2 answers
  • The Internet and World Wide Web allow almost any business to be global. What are two important results of this process?
    8·1 answer
  • Computers store temporary Internet files in the Recycle Bin. These files take up space and slow down a computer. Which tool can
    10·1 answer
  • Plot element is typically the turning point in the most intense moment of a story
    8·1 answer
  • The greatest common divisor of integers x and y is the largest integer that evenly divides into both x and y. Write a recursive
    7·1 answer
  • 9. DIMMs used in servers can provide additional reliability if they use what specific technology.
    8·1 answer
  • What are 25 items that trees made?
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!