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
11 changes: 9 additions & 2 deletions competitiveProgramming/competitiveProgramming/Search/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ int search_linear(int arr[],int e, int size){
return position;
}

void search_binary(int arr[], int e, int size){

bool search_binary(int arr[], int e, int size){
int lo = 0, hi = size-1;
while(l < r){
int mid = (lo + hi)/2;
if(arr[mid] == e) return true;
if(arr[mid] > e) hi = mid - 1;
else lo = mid + 1;
}
return arr[mid] == e;
}