Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Binary_Search_Explained.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
BINARY SEARCH

GENERAL EXPLANATION :
Binary Search is an algorithm used to search for an element in sorted arrays. Its Time-Complexity is O(logn). Its Time Complexity is much better than Linear Search, that is O(n).
Binary Search starts working by comparing the middle element of the array with the required element. If a matcch occurs then the index of the element is returned. If the middle element is greater than the element we are searching for then a recursive call is made on the first-half of the array. Otherwise , recursive call is made on the second-half of the array.

PSEUDO-CODE :

BINARY_SEARCH(ARR,0,N-1,ITEM)

ARR is the Sorted Array in which we search.
N is the size of ARR.
ITEM is the element to be searched.

START = 0
END = N-1

if END >= L
MID = START + (END-1)/2
if ARR[MID] == ITEM
return MID and EXIT
else if ARR[MID] > ITEM
CALL BINARY_SEARCH(ARR,START,MID-1,ITEM)
else
CALL BINARY_SERACH(ARR,MID+1,END,ITEM);


else
WRITE "Not Found" and EXIT

SUMMARY
Binary search halves the searchable items and thus reduces the number of comparisons to be made significantly less.