From e5326eccb638f03d65cee0e8b3c7f212f92472eb Mon Sep 17 00:00:00 2001 From: Satish Sharma <135573281+satish-sharma360@users.noreply.github.com> Date: Wed, 8 Apr 2026 17:23:18 +0530 Subject: [PATCH] fix: improve binary search mid calculation to avoid overflow --- Search/BinarySearch.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Search/BinarySearch.js b/Search/BinarySearch.js index c5477cb7b9..03ee875eec 100644 --- a/Search/BinarySearch.js +++ b/Search/BinarySearch.js @@ -8,7 +8,8 @@ */ function binarySearchRecursive(arr, x, low = 0, high = arr.length - 1) { - const mid = Math.floor(low + (high - low) / 2) + // Using optimized mid calculation to prevent overflow + const mid = low + Math.floor((high - low) / 2); if (high >= low) { if (arr[mid] === x) {