From 0a2c7f2e3bb539d3aee68673b5d743d178d455b2 Mon Sep 17 00:00:00 2001 From: Piotr Idzik <65706193+vil02@users.noreply.github.com> Date: Wed, 18 Feb 2026 20:32:32 +0100 Subject: [PATCH] style: include `BL_BURYING_LOGIC` (#7277) --- spotbugs-exclude.xml | 3 -- .../searches/RecursiveBinarySearch.java | 35 +++++++++---------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/spotbugs-exclude.xml b/spotbugs-exclude.xml index 7483d37da..a8eedcfed 100644 --- a/spotbugs-exclude.xml +++ b/spotbugs-exclude.xml @@ -90,9 +90,6 @@ - - - diff --git a/src/main/java/com/thealgorithms/searches/RecursiveBinarySearch.java b/src/main/java/com/thealgorithms/searches/RecursiveBinarySearch.java index daf0c12c0..1716e7896 100644 --- a/src/main/java/com/thealgorithms/searches/RecursiveBinarySearch.java +++ b/src/main/java/com/thealgorithms/searches/RecursiveBinarySearch.java @@ -23,28 +23,27 @@ public class RecursiveBinarySearch> extends SearchAlgori // Recursive binary search function public int binsear(T[] arr, int left, int right, T target) { - if (right >= left) { - int mid = left + (right - left) / 2; + if (right < left) { + // Element is not present in the array + return -1; + } + final int mid = left + (right - left) / 2; - // Compare the element at the middle with the target - int comparison = arr[mid].compareTo(target); + // Compare the element at the middle with the target + final int comparison = arr[mid].compareTo(target); - // If the element is equal to the target, return its index - if (comparison == 0) { - return mid; - } - - // If the element is greater than the target, search in the left subarray - if (comparison > 0) { - return binsear(arr, left, mid - 1, target); - } - - // Otherwise, search in the right subarray - return binsear(arr, mid + 1, right, target); + // If the element is equal to the target, return its index + if (comparison == 0) { + return mid; } - // Element is not present in the array - return -1; + // If the element is greater than the target, search in the left subarray + if (comparison > 0) { + return binsear(arr, left, mid - 1, target); + } + + // Otherwise, search in the right subarray + return binsear(arr, mid + 1, right, target); } public static void main(String[] args) {