binary_search(alower_boundupper_boundvalstep [initializeset beg lower_bound end upper_boundpos step repeat steps and while beg <end step set mid (beg end)/ step if [midval set pos mid print pos go to step else if [midval set end mid else set beg mid [end of if[end of loopstep if pos - print "value is not present in the array[end of ifstep exit foundthen the value of pos is printed and the algorithm exits howeverif match is not foundand if the value of [midis greater than valthe value of end is modifiedotherwise if [midis greater than valthen the value of beg is altered in step if the value of pos - then val is not present in the array and an appropriate message is printed on the screen before the algorithm exits complexity of binary search algorithm the complexity of the binary search algorithm can be expressed as (nwhere is the number of elements in the array the complexity of the algorithm is calculated depending on the number of comparisons that are made in the binary figure algorithm for binary search search algorithmwe see that with each comparisonthe size of the segment where search has to be made is reduced to half thuswe can say thatin order to locate particular value in the arraythe total number of comparisons that will be made is given as (nn or (nlog programming example write program to search an element in an array using binary search ##include #include #include #define size /added to make changing size of array easier int smallest(int arr[]int kint )/added to sort array void selection_sort(int arr[]int )/added to sort array int main(int argcchar *argv[]int arr[size]numinbegendmidfound= printf("\ enter the number of elements in the array")scanf("% "& )printf("\ enter the elements")for( = ; < ; ++scanf("% "&arr[ ])selection_sort(arrn)/added to sort the array printf("\ the sorted array is\ ")for( = ; < ; ++printf(% \ "arr[ ])printf("\ \ enter the number that has to be searched")scanf("% "&num)beg end - while(beg<=endmid (beg end)/ if (arr[mid=numprintf("\ % is present in the array at position % "nummid+ )found = break