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
int main()
{
int n;
cin >> n;
int a[n];
for(int i = 0; i < n; i++)
cin >> a[i];
int x;
cin >> x;
int result = binarySearch(a, 0, n - 1, x);
if(result == -1)
cout << "Not found";
else
cout << "Found";
return 0;
}
int binarySearch(int a[], int l, int r, int x)
{
if (r >= l) {
int mid = l + (r - l) / 2;
OPTIMISED CODE FOR binary_search.cpp
#include
using namespace std;
int binarySearch(int a[], int l, int r, int x);
int main()
{
int n;
cin >> n;
int a[n];
for(int i = 0; i < n; i++)
cin >> a[i];
int x;
cin >> x;
int result = binarySearch(a, 0, n - 1, x);
if(result == -1)
cout << "Not found";
else
cout << "Found";
return 0;
}
int binarySearch(int a[], int l, int r, int x)
{
if (r >= l) {
int mid = l + (r - l) / 2;
}
The text was updated successfully, but these errors were encountered: