From f4353ff2a46715825461ec11d64eaab7d6af6665 Mon Sep 17 00:00:00 2001 From: Mohnish Deshpande <77594965+mohnishdeshpande@users.noreply.github.com> Date: Sun, 21 Aug 2022 01:50:26 +1000 Subject: [PATCH] enh(CPlusPlus): update comment of binary search (#807) --- algorithms/CPlusPlus/Searching/binary-search.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/algorithms/CPlusPlus/Searching/binary-search.cpp b/algorithms/CPlusPlus/Searching/binary-search.cpp index 0603d02e..c07771de 100644 --- a/algorithms/CPlusPlus/Searching/binary-search.cpp +++ b/algorithms/CPlusPlus/Searching/binary-search.cpp @@ -7,7 +7,7 @@ int binarySearch(int arr[], int l, int r, int x) { if (r >= l) { int mid = l + (r - l) / 2; - //We use (l + (r - l)) rather than using (l - r) to avoid arithmetic overflow. + //We use (l + (r - l)) rather than using (l + r) to avoid arithmetic overflow. //Arithmetic overflow is the situation when the value of a variable increases //beyond the maximum value of the memory location, and wraps around. @@ -15,7 +15,7 @@ int binarySearch(int arr[], int l, int r, int x) if (arr[mid] == x) return mid; - // If element is smaller than mid, then it can only be present in left subarray + // If mid is greater than element, then it can only be present in left subarray if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x);