Skip to content

Conversation

Siddhram
Copy link
Contributor

This PR introduces a fully documented implementation of Pigeonhole Sort in R, designed for sorting integer vectors efficiently when the range of elements is not significantly larger than the number of elements.

Overview

The pigeonhole_sort function sorts an integer vector by placing elements into "holes" corresponding to their values. It counts the occurrences of each integer within the range of input values and then reconstructs the sorted array. The algorithm is efficient for integers with a small range relative to the size of the array.

Features

  • Sorts integer vectors efficiently
  • Handles empty vectors gracefully
  • Validates input to ensure only integer values are processed
  • Reconstructs sorted array from counts in "pigeonholes"
  • Includes a simple demonstration example
  • Follows consistent API style with other R sorting algorithm modules

Complexity

  • Time Complexity: O(n + range), where range = max(arr) - min(arr) + 1
  • Space Complexity: O(range)

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.

1 participant