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

15. (15 points) Briefly describe the problem this code is solving in the text bo

ID: 3587124 • Letter: 1

Question

15. (15 points) Briefly describe the problem this code is solving in the text box below. (Hint: Describe the purpose, inputs, outputs algorithm Big-oh) public static void WhatHappens (intl 1 array, int lowerbound, int upperbound, int key) int position; int comparisoncount = 1; // counting the number of comparisons (optional) // To start, find the subscript of the middle position position = ( lowerbound + upperbound) / 2; while ((array [position] != key) && (lowerbound key.. // decrease position by one. upperbound = position- 1; else lowerbound- position 1; // Else, increase position by one. position = (lowerbound + upperbound) / 2; if (lowerbound

Explanation / Answer

Function NAME : WhatHappens
Parameters : Array A [Sorted ] , lowerbound , higherbound , key [to search]

Explanation : Function starts by finding the midIndex which is sum of ( lowerbound + higherbound ) / 2 ,
Then check if A[midIndex] is equal to the key (The one we are searching for) . If found we move out of the loop

Otherwise If the key to be search is less than the the element in middle then we need to search in the first half.
If the key to be search is more than the the element in middle then we need to search in second half

Purpose : To find an element (key) in an array
Input : Sorted Array , lowerindex, higher index and key to be searched
Output: If we find the element , we print the position where it was found and the number of comparison it took to find the element.
If not found we just tell the the number of comparison it took

Time Complexity is same as that of Binary search i.e O(log n) . BECAUSE Our search space keep reducing to half


Thanks, let me know if you need morde details

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote