From fb72617aeab98bcda18f36b3ab6b3977713e08ec Mon Sep 17 00:00:00 2001 From: sangamcse Date: Sun, 30 Sep 2018 23:25:25 +0530 Subject: [PATCH 1/3] PULL_REQUEST_TEMPLATE: Add important checks This adds important checks to read for the contributers before opening a Pull Request. --- .github/PULL_REQUEST_TEMPLATE.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 2ff91bb7..44fd2630 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -3,6 +3,13 @@ Thanks for your contribution! Please take a quick look at those things down there. They're quite important. Really! We wrote them for you. Yes you! With utmost care. Read them. + +In order to help us evaluate PRs better, we ask you to have a look at the +following declaration and check the points you agree with. ( [x] ) +PRs which don't agree to all the points mentioned below will be rejected. + +Also make sure that this PR corresponds to one and only one issue. Write the +issue number in the space provided below. --> **For short term contributors:** we understand that getting your commits well @@ -11,4 +18,18 @@ look to help without wanting to contribute long term there's no need for you to learn this. Just drop us a message and we'll take care of brushing up your stuff for merge! -After you submit your pull request, **DO NOT click the 'Update Branch' button. +Fixes #{ISSUE_NUMBER} + + +**By submitting this pull request I confirm I've read and complied with the +below declarations.** + +- [ ] I have read the [Contribution guidelines](https://github.com/NITSkmOS/Algorithms/blob/master/CONTRIBUTING.md) and I am confident that my PR reflects them. +- [ ] I have followed the [commit guidelines](https://github.com/NITSkmOS/Algorithms/blob/master/CONTRIBUTING.md#write-good-commit-messages) for this project. +- [ ] My code follows the [standard code structure](https://github.com/NITSkmOS/Algorithms/blob/master/CONTRIBUTING.md#samples-code). +- [ ] This pull request has a descriptive title. For example, `{Tag}: Add {Algorithm/DS name} [{Language}]`, not `Update README.md` or `Added new code`. +- [ ] This pull request will be closed if I fail to update it even once in a continuous time span of 7 days. +- [ ] This pull request shall only be reviewed and merged once all the checks passes. No maintainer or supporter shall be obliged to review it before this condition is met. +- [ ] I have mentioned the issue number correctly (with hyperlink) in this pull request description. + +After you submit your pull request, **DO NOT** click the 'Update Branch' button. From 4dd554257ea09fb7e4c33c837c46de1402d0a7ea Mon Sep 17 00:00:00 2001 From: Sudhir Saharan Date: Mon, 1 Oct 2018 00:46:35 +0530 Subject: [PATCH 2/3] BinarySearch.java: Add binary search recursive algorithm THis adds BinarySearch algorithm which searches and returns the index position or position of a particular element in an array , if it is not found then it returns index value -1 Closes https://github.com/NITSkmOS/Algorithms/issues/52 --- binary_search/Java/BinarySearch.java | 56 ++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 binary_search/Java/BinarySearch.java diff --git a/binary_search/Java/BinarySearch.java b/binary_search/Java/BinarySearch.java new file mode 100644 index 00000000..234ed396 --- /dev/null +++ b/binary_search/Java/BinarySearch.java @@ -0,0 +1,56 @@ +/*Binary Search: + +Search a sorted array by repeatedly dividing the search interval in half. +Begin with an interval covering the whole array. If the value of the search key is +less than the item in the middle of the interval, narrow the interval to the lower +half. Otherwise narrow it to the upper half. Repeatedly check until the value is +found or the interval is empty. + + Java implementation of recursive Binary Search +*/ + +class BinarySearch +{ + // Returns index of x if it is present in arr[l.. + // r], else return -1 + 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(String args[]) + { + BinarySearch ob = new BinarySearch(); + int arr[] = {2,3,4,10,40}; + int n = arr.length; + int x = 10; + int result = ob.binarySearch(arr,0,n-1,x); + if (result == -1) + System.out.println("Element not present"); + else + System.out.println("Element found at index " + + result); + } +} \ No newline at end of file From a9c35cb4dd790a475ad5a4f7e11ec484894b31f0 Mon Sep 17 00:00:00 2001 From: Sudhir Saharan Date: Mon, 1 Oct 2018 01:27:40 +0530 Subject: [PATCH 3/3] BinarySearch.java: Added fix for pr quality check fail This adds fixes for package not present and explicit scoping in the java program Closes https://github.com/NITSkmOS/Algorithms/issues/46 --- binary_search/Java/BinarySearch.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/binary_search/Java/BinarySearch.java b/binary_search/Java/BinarySearch.java index 234ed396..59d0b0bc 100644 --- a/binary_search/Java/BinarySearch.java +++ b/binary_search/Java/BinarySearch.java @@ -8,12 +8,12 @@ Java implementation of recursive Binary Search */ - +package searchalgo; class BinarySearch { // Returns index of x if it is present in arr[l.. // r], else return -1 - int binarySearch(int arr[], int l, int r, int x) + private int binarySearch(int arr[], int l, int r, int x) { if (r>=l) {