From 8d842a64359251efd4c0dad74ad7b41b99bdfc31 Mon Sep 17 00:00:00 2001 From: Prashant Jain Date: Sun, 21 Jun 2026 21:51:32 +0530 Subject: [PATCH] fix(QuickSort): use low instead of hardcoded 0 in left recursive call The left recursive call passed a hardcoded 0 as the lower bound instead of low, so every left-partition call re-sorted the array from index 0 rather than from the start of the current sub-problem. The result stayed correct (the [0, low-1] prefix is already in place) but recursion work blew up to O(n^2): on a descending array of 2000 elements the buggy version makes 1,001,001 quickSort invocations vs 3,999 after the fix, which is what can drive the reported StackOverflowError on large inputs. Co-Authored-By: Claude Opus 4.8 (1M context) --- 4 Other Problems/QuickSort.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/4 Other Problems/QuickSort.java b/4 Other Problems/QuickSort.java index d68902d..45c4b46 100644 --- a/4 Other Problems/QuickSort.java +++ b/4 Other Problems/QuickSort.java @@ -26,7 +26,7 @@ private void quickSort(int[] nums, int low, if (low < high) { int partitionIndex = partition(nums, low, high); - quickSort(nums, 0, partitionIndex - 1); + quickSort(nums, low, partitionIndex - 1); quickSort(nums, partitionIndex + 1, high); } }