Skip to content

Commit b6add13

Browse files
committed
docs: added comments on O(N) implementation trick
1 parent 86825a6 commit b6add13

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/main/java/algorithms/sorting/radixSort/RadixSort.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ private static void radixSort(int[] arr, int[] sorted) {
4747
sorted[freqMap[id] - 1] = curr;
4848
freqMap[id]--;
4949
}
50-
// we do a swap so that our results above for this segment is
51-
// saved and passed as input to the next segment
50+
// We do a swap so that our results above for this segment is
51+
// saved and passed as input to the next segment.
52+
// By doing this we no longer need to create a new array
53+
// every time we shift to a new segment to sort.
54+
// We can constantly reuse the array, allowing us to only use O(n) space.
5255
int[] tmp = arr;
5356
arr = sorted;
5457
sorted = tmp;

0 commit comments

Comments
 (0)