✔Binary search is a searching algorithm that finds the position of a target value within a sorted array.
✔It is a divide-and-conquer algorithm that repeatedly divides the search space in half.
✔Time Complexity:O(log n)
Compare the middle element of the search space with the key.
• If the key is found at middle element, the process is terminated.
• If the key is not found at middle element, choose which half will
be used as the next search space.
• If the key is smaller than the middle element, then the left side
is used for next search.
• If the key is larger than the middle element, then the right side
is used for next search.
Consider an array arr[] = {2, 5, 8, 12, 16, 23, 38, 56, 72, 91}, and the target = 23
First Step: Calculate the mid and compare the mid element with the key. If the key is less than mid element,
move to left and if it is greater than the mid then move search space to the righ
• Key (i.e., 23) is greater than current mid element (i.e., 16). The search space moves to the right.
• Key is less than the current mid 56. The search space moves to the left
Second Step: If the key matches the value of the mid element, the element is found and stop search
✔Fast Search Time
✔Memory Efficiency
✔Sorted Data Requirement
✔Limited Applicability