Question: Work out what the algorithm for trinary search would look like. int binarySearch(int* arr, int lo, int hi, int value) { if (hi >= lo)
Work out what the algorithm for trinary search would look like.
int binarySearch(int* arr, int lo, int hi, int value) { if (hi >= lo) { int mid = lo + (hi - lo) / 2; if (arr[mid] == value) return mid; if (arr[mid] > value) return binarySearch(arr, lo, mid - 1, value); return binarySearch(arr, mid + 1, hi, value); } // Element not present. return -1; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
