Show the hand traced results of the variables first, last and mid of the recursi
ID: 3565716 • Letter: S
Question
Show the hand traced results of the variables first, last and mid of the recursive version of BinarySearch algorithm given below.
Initial values
Array = [1, 9, 12, 21, 24, 32, 45, 47]
target = 45
first = 0
last = Array.length-1
RecursiveBinarySearch(Array, target, first, last){
if (low > high)
return -1
mid = (low + high) / 2
if (Array[mid] > target)
return BinarySearch(Array, target, low, mid-1)
else if (Array[mid] < target)
return BinarySearch(Array, target, mid+1, high)
else
return mid
}
Explanation / Answer
first = 0, last = 7, mid = 3
first = 4, last = 7, mid = 5
first = 6, last = 7, mid = 6
mid = 6
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.