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]
4 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]4 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
Any task done by software can also be done using computer hardware, and any operation performed directly by hardware can be done
skad [1K]

Answer:

True.

Explanation:

A platform can be defined as a computing environment for building and executing sets of code in a software application or program such as an application programming interface (API).

The two parts of the platform used to run an application software are both hardware and operating system (software).

A hardware platform can be defined as a collection of hardware that are compatible with each other and the software application or program to be executed. All hardware platforms have their respective low level or high level machine language that are compatible with the software application. Some examples of a hardware platform are x86, i860, MIPS, video game consoles (joysticks), IBM Z, ARM, unisys, powerpc, SPARC etc.

An operating system platform is a system software pre-installed on a computing device to manage or control software application, computer hardware and user processes. Some examples of an operating system are QNX, Linux, OpenVMS, MacOS, Microsoft windows, IBM, Solaris, VM etc.

Hence, any task done by software can also be done using computer hardware, and any operation performed directly by hardware can be done using software.

6 0
3 years ago
Provide examples of how information technology has created an ethical dilemma that would not have existed before the advent of I
Kamila [148]
Hrhdhhdhdjhdhcnbcgfgbsbnenwnsn

7 0
3 years ago
Why is it difficult to detect a Trojan horse?
marishachu [46]

Answer:

Explanation:

Because the virus disguises it self as something you are trying to download, then it attackes your device

8 0
3 years ago
Read 2 more answers
there are these numbers that I've seen before but I don't know what they mean can someone help. I will give brainiest
Ne4ueva [31]

Answer:

Those numberss are binary code

Explanation:

Computers use binary - the digits 0 and 1 - to store data. A binary digit, or bit , is the smallest unit of data in computing. It is represented by a 0 or a 1. Binary numbers are made up of binary digits (bits), eg the binary number 1001.

5 0
3 years ago
Read 2 more answers
In which order do the DHCP messages occur when a client and server are negotiating address configuration?
Leona [35]
One two three and four
8 0
3 years ago
Other questions:
  • Brenda is a college student who enjoys downloading music, movies, and television shows from the Internet. She also uses the Inte
    7·1 answer
  • We observe diffusion in nature and in our technology on a daily basis, but seldom stop to think about the physical process behin
    8·1 answer
  • This is not a removable media device
    15·1 answer
  • Assume that you want to create an array containing ten Die objects. Which of the following code segment accomplishes this correc
    11·1 answer
  • What is it called when you give credit in your writing to someone else's quote?
    10·1 answer
  • More Loops: All versions of foods.py in this section have avoided using for loops when printing to save space. Choose a version
    13·1 answer
  • Which is an example of a local government enforcing a national law?
    5·2 answers
  • In a meeting, Juan hears someone say a product mix is "wide." What does
    13·1 answer
  • Which group on the home ribbon contains commands to control the alignment of text in a document?
    15·1 answer
  • What best describes the computer's BIOS (basic input-output system)?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!