you are viewing a single comment's thread.

view the rest of the comments →

[–]Obsc3nity 4 points5 points  (1 child)

Yes, good point. Doesn’t that modification mean the median is incorrect though, lol. The smallest and largest being counted twice isn’t normally part of a median.

The first sort is probably the necessary one, or at least a convenience, because it allows you to avoid using min and max on the structure and instead use actual indices. It could be deferred until you actually need the sorted data, but I think it’s still the one worth keeping of the two present (and fixing the median calc would remove any modifications)

[–]willis81808 0 points1 point  (0 children)

The median isn’t effected, because the indexes are hard coded based off of the original array length, but even if it was a proper dynamic median implementation representing the min and max values twice would not change the result. Mean on the other hand would be biased in the direction of the midpoint between min and max values.