Question: Assume that you execute the binary search algorithm(below) for the following numbers in an array A. ALGORITHM BinarySearch(A[0..n 1], K) //Implements nonrecursive binary search //Input:
Assume that you execute the binary search algorithm(below) for the following numbers in an array A.
ALGORITHM BinarySearch(A[0..n 1], K) //Implements nonrecursive binary search //Input: An array A[0..n 1] sorted in ascending order and // a search key K //Output: An index of the arrays element that is equal to K // or 1 if there is no such element l 0; r n 1 while l r do m (l + r)/2 if K = A[m]return m else if K else l m + 1 return 1
3, 14, 27, 31, 42, 55, 70, 74, 81, 85, 93, 107
Draw a binary search tree for the numbers based on the algorithm.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
