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
Graphic design has as its goal the communication of some __________ message to a group of people.
Aleks [24]
Graphic design has as its goal the communication of some specific message to a group of people.

Specific is your answer.
3 0
3 years ago
40 POINTS PLZ HELP NEED ASAP!!!
dem82 [27]
I Think The answer is c I hope it helps Message Me if I’m wrong and I’ll change My answer and fix it for you
7 0
3 years ago
The autocorrect feature can automatically capitalize the first letter in the names of days. true false
Westkost [7]
The answer is that it is true
3 0
3 years ago
Hello, this is a 2 part question for my beginning assembly class. Thank you in advance for your help
madam [21]

Answer:

Complete code is given below:

Explanation:

INCLUDE Irvine32.inc

.data

msgMenu BYTE "---- Boolean Calculator ----", 0dh,0ah

BYTE 0dh,0ah

BYTE "1. x AND y"     ,0dh,0ah

BYTE "2. x OR y"      ,0dh,0ah

BYTE "3. NOT x"       ,0dh,0ah

BYTE "4. x XOR y"     ,0dh,0ah

BYTE "5. Exit program",0

msgAND      BYTE "Boolean AND",0

msgOR       BYTE "Boolean OR",0

msgNOT      BYTE "Boolean NOT",0

msgXOR      BYTE "Boolean XOR",0

msgOperand1 BYTE "Input the first 32-bit hexadecimal operand: ",0

msgOperand2 BYTE "Input the second 32-bit hexadecimal operand: ",0

msgResult   BYTE "The 32-bit hexadecimal result is:            ",0

caseTable   BYTE '1'     # lookup value

DWORD _AND_op        # address of the procedure

EntrySize = ($ - caseTable )

   BYTE '2'

   DWORD _OR_op

   BYTE '3'

   DWORD _NOT_op

   BYTE '4'

   DWORD _XOR_op

   BYTE '5'

   DWORD _ExitProgram

NumberOfEntries=($ - caseTable)/EntrySize

.code

main08stub PROC

   call Clrscr

Menu:

   mov edx, OFFSET msgMenu # menu choices

   call WriteString

   call Crlf

L1: call ReadChar

   cmp al, '5' # is selection valid (1-5)?

   ja L1   # if above 5, go back

   cmp al, '1'

   jb L1   # if below 1, go back

   call Crlf

   call **BLANK**

   jc quit # if CF = 1 exit

   call Crlf

   jmp Menu    # display menu again

quit: exit

main08stub ENDP

#----------------------------------------

**BLANK** PROC

#

# It selects a procedure from the case table

# Receives: AL = number of procedure

# Returns: nothing

#-----------------------------------

   ret

**BLANK** ENDP

#------------------------------------------------

_AND_op PROC

#

# Performs a boolean AND operation

# Receives: Nothing

# Returns: Nothing

#------------------------------------------------

   ret

_AND_op ENDP

#------------------------------------------------

_OR_op PROC

#

# Performs a boolean OR operation

# Receives: Nothing

# Returns: Nothing

#------------------------------------------------

   ret

_OR_op ENDP

#------------------------------------------------

_NOT_op PROC

#

# Performs a boolean NOT operation.

# Receives: Nothing

# Returns: Nothing

#------------------------------------------------

   ret

_NOT_op ENDP

#------------------------------------------------

_XOR_op PROC

#

#

# Performs an Exclusive-OR operation

# Receives: Nothing

# Returns: Nothing

#------------------------------------------------

   ret

_XOR_op ENDP

#------------------------------------------------

_ExitProgram PROC

#

# Receives: Nothing

# Returns: Sets CF = 1 to signal end of program

#------------------------------------------------

   ret

_ExitProgram ENDP

END main08stub

3 0
3 years ago
Write two recursive versions of the function minInArray. The function will be given a sequence of elements and should return the
Viktor [21]

Answer:

Following are the code to this question:

#include <iostream>//defining header file

using namespace std;//using namespace

int minInArray1(int arr[],int arrSize)//declaring method minInArray1

{

if(arrSize == 1)//use if block to check arrSize value is equal to 1  

{

return arr[0];//return first element of array

}

else //defining else block

{

int max= minInArray1(arr, arrSize-1);//use integer variable max to call method recursively  

if(arr[arrSize-1] < max)//use if block to check array value  

{

max = arr[arrSize-1];//use max to hold array value

}

return max;//return max variable value

}

}

int minInArray2(int arr[], int low, int high)//defining a method minInArray2  

{

if(low == high) //use if to check low and high variable value are equal

{

return arr[low];//return low variable value

}

else //defining else block

{

int minimum = minInArray2(arr, low+1, high);//defining integer variable minimum to call method minInArray2 recursively

if(arr[low] < minimum)

{

minimum = arr[low];//use minimum variable to hold array value

}

return minimum;//return minimum value

}

}

int main()//defining main method

{

int arr[10] = { 9, -2, 14, 12, 3, 6, 2, 1, -9, 15 };//defining an array arr

int r1, r2, r3, r4;//defining integer variable

r1 = minInArray1(arr, 10);//use r1 variable to call minInArray1 and hold its return value

r2 = minInArray2(arr, 0, 9);//use r1 variable to call minInArray2 and hold its return value

cout << r1 << " " << r2 << endl; //use print method to print r1 and r2 variable value

r3 = minInArray2(arr, 2, 5);//use r3 variable to call minInArray1 and hold its return value

r4 = minInArray1(arr + 2, 4); //use r4 variable to call minInArray2 and hold its return value

cout<<r3<< " " <<r4<<endl; //use print method to print r3 and r4 variable value

return 0;

}

Output:

please find the attached file.

Explanation:

In the given code two methods, "minInArray1 and minInArray2" is defined,  in the "minInArray1" it accepts two-variable "array and arrSize" as the parameter, and in the "minInArray2" method it accepts three integer variable "array, low, and high" as the parameter.

  • In the "minInArray1" method, and if the block it checks array size value equal to 1 if the condition is true it will return the first element of the array, and in the else block the max variable is defined, that calling method recursively
  • and store its value.
  • In the "minInArray2" method, an if the block it checks low and high variable value is equal. if the condition is true it will return a low array value. In the next step, the minimum value is defined, which checks the element of the array and uses a low array to store its value.
  • In the main method an array and four integer variable "r1, r2, r3, and r4" is defined, which calls two methods "minInArray1 and minInArray2" and use print method to print its value.
7 0
3 years ago
Other questions:
  • ________ is a command-line utility installed in the windows\system32 folder that displays information about your windows version
    9·1 answer
  • Write a for loop to verify that your function is correctly returning the expected output for the radius values between 0 and 11.
    14·1 answer
  • In 3–5 sentences, describe how technology helps business professionals to be more efficient.
    7·2 answers
  • Kyle asked his supervisor which type of computing model was used when the enterprise first started. She explained that the organ
    14·1 answer
  • How do i move a file in python3
    10·1 answer
  • IT professionals should help to protect users’ personal information, such as bank account information or Social Security numbers
    14·1 answer
  • All of the following are benefits of automation except
    5·1 answer
  • How do you use VMware Fusion to make a Tip Calculator?
    10·1 answer
  • When using correct ergonomic technique be sure to _____.
    11·2 answers
  • What are your initial thoughts regarding copyright and fair use after watching the clip?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!