From cc3ba053fb71a050d1ffbda35a8ff2f48f6b4174 Mon Sep 17 00:00:00 2001 From: Neetansh <56220285+Neetansh@users.noreply.github.com> Date: Sat, 12 Oct 2019 20:29:17 +0530 Subject: [PATCH] Create bsea.py --- bsea.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 bsea.py diff --git a/bsea.py b/bsea.py new file mode 100644 index 0000000..4241e91 --- /dev/null +++ b/bsea.py @@ -0,0 +1,16 @@ +import java.util.Scanner; +class BinarySearch { + int binarySearch(int arr[], int l, int r, int x) { + if (r >= l) { + int mid = l + (r - l) / 2; + if (arr[mid] == x) + return mid; + + if (arr[mid] > x) + return binarySearch(arr, l, mid - 1, x); + + return binarySearch(arr, mid + 1, r, x); + } + return -1; + } +}