Question: What single line of code would need to be changed if you wanted to do a Binary Search on a list sorted in descending order?

What single line of code would need to be changed if you wanted to do a Binary Search on a list sorted in descending order? How would you change it?
Algorithm binarySearch(a, first, last, desiredItem)
mid =(first+last)/2
if (first > last)
return false
else if (desiredItem equals a[mid])
return true
else if (desiredItem < a[mid])
return binarySearch(a, first, mid-1, desiredItem)
else // desiredItem> a[mid]
return binarySearch(a, mid+1, last, desiredItem)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!