From d7934faf964734c9c4ff55f1917e1f9f2c4c7f85 Mon Sep 17 00:00:00 2001 From: sidmisro Date: Sun, 19 Apr 2026 20:29:21 +0530 Subject: [PATCH 1/2] Improved the documentation and comments in merge_sort.cpp - Fixed grammatical errors in comments - Updated misleading statement about built-in sorting algorithms - Added explanation about stability of merge sort --- sorting/merge_sort.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sorting/merge_sort.cpp b/sorting/merge_sort.cpp index 80409c79074..42b22d0ab57 100644 --- a/sorting/merge_sort.cpp +++ b/sorting/merge_sort.cpp @@ -12,9 +12,10 @@ * based sorting algorithm. * Merge Sort is a divide and conquer algorithm * Time Complexity: O(n log n) + * Merge Sort is a stable sorting algorithm (preserves relative order of equal elements). * It is same for all best case, worst case or average case - * Merge Sort is very efficient when for the small data. - * In built-in sort function merge sort along with quick sort is used. + * Merge Sort performs efficiently for large datasets due to its O(nlogn) complexity. + * Many standard libraries use hybrid sorting algorithms (e.g., introsort). */ #include #include From 21da7160b826c9290c70204105a0753383909312 Mon Sep 17 00:00:00 2001 From: sidmisro Date: Sun, 19 Apr 2026 22:25:32 +0530 Subject: [PATCH 2/2] Fix out-of-bounds access in jump_search implementation - Fixed potential out-of-bounds access in jump search loops - Added boundary checks for empty array - Improved safety of index access conditions --- search/jump_search.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/search/jump_search.cpp b/search/jump_search.cpp index f7b100a4e03..5fb0822e911 100644 --- a/search/jump_search.cpp +++ b/search/jump_search.cpp @@ -11,12 +11,13 @@ */ int jumpSearch(int arr[], int x, int n) { // Finding block size to be jumped + if(n <= 0) {return -1;} int step = std::sqrt(n); // Finding the block where element is // present (if it is present) int prev = 0; - while (arr[std::min(step, n) - 1] < x) { + while (step < n && arr[std::min(step, n) - 1] < x) { prev = step; step += std::sqrt(n); if (prev >= n) @@ -25,7 +26,7 @@ int jumpSearch(int arr[], int x, int n) { // Doing a linear search for x in block // beginning with prev. - while (arr[prev] < x) { + while (prev <= std::min(step, n) && arr[prev] < x) { prev++; // If we reached next block or end of @@ -34,7 +35,7 @@ int jumpSearch(int arr[], int x, int n) { return -1; } // If element is found - if (arr[prev] == x) + if (prev < n && arr[prev] == x) return prev; return -1;