You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Search/BinarySearch/README.md
+5-2Lines changed: 5 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
Binary Search
1
+
##Binary Search
2
2
3
3
Given a sorted array arr[] of n elements, write a function to search a given element x in arr[].
4
4
A simple approach is to do linear search.The time complexity of above algorithm is O(n). Another approach to perform the same task is using Binary Search.
@@ -10,6 +10,9 @@ The idea of binary search is to use the information that the array is sorted and
10
10
We basically ignore half of the elements just after one comparison.
11
11
12
12
1.Compare x with the middle element.
13
+
13
14
2.If x matches with middle element, we return the mid index.
14
-
3.Else If x is greater than the mid element, then x can only lie in right half subarray after the mid element. So we recur for right half.
15
+
16
+
3.Else If x is greater than the mid element, then x can only lie in right half subarray after the mid element. So we recur for right half.
0 commit comments