From c72c27b81c39c3195aec1ec81f9db05aa074b281 Mon Sep 17 00:00:00 2001 From: aka4rKO Date: Mon, 8 Oct 2018 13:58:08 +0530 Subject: [PATCH 1/2] Create binary_search.exe --- code/binary_search.exe | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 code/binary_search.exe diff --git a/code/binary_search.exe b/code/binary_search.exe new file mode 100644 index 0000000..5fe9148 --- /dev/null +++ b/code/binary_search.exe @@ -0,0 +1,53 @@ +// C# implementation of recursive Binary Search +using System; + +class GFG +{ + // Returns index of x if it is present in + // arr[l..r], else return -1 + static int binarySearch(int []arr, int l, + int r, int x) + { + if (r >= l) + { + int mid = l + (r - l)/2; + + // If the element is present at the + // middle itself + if (arr[mid] == x) + return mid; + + // If element is smaller than mid, then + // it can only be present in left subarray + if (arr[mid] > x) + return binarySearch(arr, l, mid-1, x); + + // Else the element can only be present + // in right subarray + return binarySearch(arr, mid+1, r, x); + } + + // We reach here when element is not present + // in array + return -1; + } + + // Driver method to test above + public static void Main() + { + + int []arr = {2, 3, 4, 10, 40}; + int n = arr.Length; + int x = 10; + + int result = binarySearch(arr, 0, n-1, x); + + if (result == -1) + Console.WriteLine("Element not present"); + else + Console.WriteLine("Element found at index " + + result); + } +} + +// This code is contributed by Sam007. From 765ee4c170d9eac1bd71a5bfab24b58ed8605a05 Mon Sep 17 00:00:00 2001 From: Luke Oliff Date: Mon, 8 Oct 2018 17:27:20 +0100 Subject: [PATCH 2/2] Rename binary_search.exe to aka4rKO.exe --- code/{binary_search.exe => aka4rKO.exe} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename code/{binary_search.exe => aka4rKO.exe} (100%) diff --git a/code/binary_search.exe b/code/aka4rKO.exe similarity index 100% rename from code/binary_search.exe rename to code/aka4rKO.exe