Skip to content

Conversation

@Siddhram
Copy link
Contributor

This implementation provides decimal LSD (Least Significant Digit) Radix Sort in R.
It sorts non-negative integers by repeatedly applying a stable counting sort to each digit, from the least significant to the most significant.

Overview

  • Algorithm Type: Non-comparative, stable, digit-based sorting
  • Target Data: Non-negative integer vectors
  • Execution: Iteratively sorts by each digit place (1s, 10s, 100s, ...) using counting sort
  • Notes: Mirrors typical Java implementations; uses base-10 digit processing

Features

  • Stable sorting per digit ensures the relative order of equal elements is preserved
  • Efficient for integers with limited digit width
  • Easy to understand and implement using counting sort
  • Handles large numbers by increasing the exponent (exp) iteratively

Complexity

  • Time Complexity (TC): O(d × (n + k))
    • n = number of elements, d = number of digits in the maximum element, k = radix/base (10 here)
  • Space Complexity (SC): O(n + k)
    • Temporary array for output + counting array per digit

@siriak siriak requested a review from Copilot October 23, 2025 21:01
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds an implementation of Postman Sort (LSD Radix Sort) for sorting non-negative integers in R. The algorithm processes digits from least to most significant using stable counting sort, following the typical base-10 radix sort pattern.

Key Changes:

  • New implementation of LSD Radix Sort with digit-by-digit counting sort
  • Input validation for numeric vectors, non-negative integers only
  • Helper functions for finding maximum value and performing counting sort per digit

# For safety, coerce to integer-like values
if (any(elements.vec != floor(elements.vec))) stop("postman.sort: values must be integers")

get.max <- function(a) max(a)
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The get.max helper function is unnecessary and reduces readability. It simply wraps the built-in max() function without adding any value. Consider using max() directly on line 47 instead.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check

# For safety, coerce to integer-like values
if (any(elements.vec != floor(elements.vec))) stop("postman.sort: values must be integers")

get.max <- function(a) max(a)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants