Question: Binary Search is performed on a sorted set of elements, it compares the number to be found with the middle element, if it is not
Binary Search is performed on a sorted set of elements, it compares the number to be found with the middle element, if it is not the same, then it checks which (left or right) subarray will contain the element, if mid is less than element, then it would be found in right subarray, similarly for left subarray. Time Complexity: O( log n ) Space Complexity: O( 1 ) Binary Search considerably reduces the search time if the data is sorted. Binary search is not used when the array changes often, or if the elements are unsorted.
Step by Step Solution
3.41 Rating (154 Votes )
There are 3 Steps involved in it
Respected SirMadam Here I am using python for searching an eleme... View full answer
Get step-by-step solutions from verified subject matter experts
