We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 86825a6 commit b6add13Copy full SHA for b6add13
src/main/java/algorithms/sorting/radixSort/RadixSort.java
@@ -47,8 +47,11 @@ private static void radixSort(int[] arr, int[] sorted) {
47
sorted[freqMap[id] - 1] = curr;
48
freqMap[id]--;
49
}
50
- // we do a swap so that our results above for this segment is
51
- // saved and passed as input to the next segment
+ // We do a swap so that our results above for this segment is
+ // 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.
55
int[] tmp = arr;
56
arr = sorted;
57
sorted = tmp;
0 commit comments