Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Questions 13 -14 require you to fill in the missing steps of the binary search a

ID: 3584894 • Letter: Q

Question

Questions 13 -14 require you to fill in the missing steps of the binary search algorithm. (6.25 points each) The binary search algorithm searches for a number in an ordered list by continuously halving the list and only searching in the relevant half. Here's an example: Let's say we wanted to search for the number 10 in the following list [ 15 10 12 15 20 21 25]. We start by picking the middle number (15). 15 is larger than 10, so we repeat this process for the left half of the array: [1 5 10 12] This time, we pick 5 as our middle number. 10 is larger than 5, so we repeat this process for the right half of the array. 10 12] We pick 10 as our middle, and we have a match, so we return the position of 10 in the list. Step 1: function binary search(A: array of sorted random numbers, x: number being searched for) returns position of number in list if found, otherwise returns -1 Step 2: low = 1, high-length of A Step 3: while low

Explanation / Answer

13)

Thus, the correct option is B

14)

According to the question the final step which is step 9 does the folowing:

Hence, correct option is C

-----------------

Below is the complete algorithm for your reference:

Step1: function binary_search (A, x)
Step2: low = 1, high = length of A
Step3: while low <= high
Step4:        mid = the floor of (low + high)/2
Step5:        if A[mid] == x
Step6:           return mid
Step7:       else if A[mid] < x
Step8:           low = mid + 1
Step9:       else high = mid - 1
Step10:   return -1

If you have any queries, you can ask in the comment section.