# Minor optimization for radix sort

**URL:** <https://forums.kodeco.com/t/minor-optimization-for-radix-sort/157978>\
**Category:** Data Structures & Algorithms in Swift\
**Created:** [November 19, 2021, 1:05am UTC](https://forums.kodeco.com/t/minor-optimization-for-radix-sort/157978 "2021-11-19T01:05:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![suragch](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/suragch/32/109020_2.png) [@suragch](https://forums.kodeco.com/u/suragch)\
**Post date:** [November 19, 2021, 1:05am UTC](https://forums.kodeco.com/t/minor-optimization-for-radix-sort/157978/1 "2021-11-19T01:05:48Z")

</div>

In the radix sort code `remainingPart` is calculated like so:

```swift
let remainingPart = number / digits

```

So if the number is 1772 and the digits are 1000, then the remaining part will be 1. However, when you check whether to go for another round, you check like this:

```swift
if remainingPart > 0 {
  done = false
}

```

Since `remainingPart` is 1, this causes the while loop to do another unnecessary round for the 10000 digits.
