Design a recursive function to find the immediate successor of a target integer in an array of
Question:
Design a recursive function to find the immediate successor of a target integer in an array of sorted integers. Here the immediate successor of a target is defined as the smallest number that is no smaller than the target in this sorted array. int binarySuccessor(const int anArray[], const int first, const int last, int target); In the above function declaration, the function searches the array anArray[first] through anArray[last] to find the smallest entry that is larger or equal to a given value target by using a binary search type of algorithm. The function returns the index of the entry that is found. When such an entry cannot be found (i.e. all entries of the array is smaller than the target), the function returns -
1. You may assume the array is sorted in an ascending order of the integers and has no duplication. An example of such a sorted array without duplicated items is {-10, 2, 3, 5}. If you call binarySuccessor() to find the Successor for 4 in this array, the function returns the index 3. If you call binarySuccessor() to find the Successor for 5, the function also returns the index 3. If you call binarySuccessor() to find the Successor for 100, the function will return -1.
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest