Skip to content

Commit 7a0fbe7

Browse files
fix(QuickSort): use low instead of hardcoded 0 in left recursive call (#2)
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) <noreply@anthropic.com>
1 parent b995241 commit 7a0fbe7

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

4 Other Problems/QuickSort.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private void quickSort(int[] nums, int low,
2626
if (low < high) {
2727
int partitionIndex = partition(nums, low,
2828
high);
29-
quickSort(nums, 0, partitionIndex - 1);
29+
quickSort(nums, low, partitionIndex - 1);
3030
quickSort(nums, partitionIndex + 1, high);
3131
}
3232
}

0 commit comments

Comments
 (0)