diff --git a/Search/QuickSelectSearch.js b/Search/QuickSelectSearch.js index 7d2a5a4c3d..2cf7a17b82 100644 --- a/Search/QuickSelectSearch.js +++ b/Search/QuickSelectSearch.js @@ -18,15 +18,17 @@ export function quickSelectSearch(array, k) { let from = 0 let to = array.length - 1 - while (from < to) { - let [left, right] = [from, to] + let left = from + let right = to const pivot = array[Math.ceil((left + right) * 0.5)] while (left < right) { if (array[left] >= pivot) { - ;[array[left], array[right]] = [array[right], array[left]] + const tmp = array[left] + array[left] = array[right] + array[right] = tmp --right } else { ++left diff --git a/Search/SentinelSearch.js b/Search/SentinelSearch.js index 8f595abf78..c6d14714a4 100644 --- a/Search/SentinelSearch.js +++ b/Search/SentinelSearch.js @@ -1,8 +1,5 @@ /** - * @function sentinelSearch - * @description Sentinel search algorithm for array. - * - * Sentinel linear search is a variation of the standard linear search algorithm used to + * @description Sentinel linear search is a variation of the standard linear search algorithm used to * find a target value in an array or list. The basic idea behind this algorithm is to add a * sentinel value at the end of the array which is equal to the target value we are looking for. * This helps to avoid checking the array boundary condition during each iteration of the loop, @@ -15,10 +12,7 @@ * @example sentinelSearch([1,2,3], 2) => 1 * @example sentinelSearch([4,5,6], 2) => null * @complexity_analysis - * Time Complexity : - * Worst Case -> The time complexity of the Sentinel Linear Search algorithm is O(n) in the worst case. - * Best Case -> In the best case, when the key is found in the first iteration, the time complexity will be O(1). - * Average Case -> However, the average time complexity is still O(n). + * Time Complexity : O(n) * Auxiliary Space: O(1) */