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

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

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