Skip to content

Conversation

Siddhram
Copy link
Contributor

This PR introduces Sleep Sort, a playful and educational sorting algorithm implemented in R.
Sleep Sort launches one task per element, sleeps for a duration proportional to the element's value, and outputs the value when the task completes. The values appear in ascending order based on their "wake-up" times.

Overview

  • Algorithm Type: Demonstrative / Novelty sorting algorithm
  • Target Data: Numeric vectors (supports negative values via offsetting)
  • Execution: Uses parallel tasks via a PSOCK cluster from the parallel package
  • Windows Compatible: Handles timing via file modification times to capture completion order
  • Notes: Intended for educational purposes; not recommended for production due to its reliance on sleep delays

Features

  • Sorts numeric vectors using timed task execution
  • Supports negative numbers by shifting all values to non-negative sleep times
  • Adjustable scale parameter to control sleep duration
  • Parallel execution with configurable number of workers
  • Automatic fallback to base R sort() if parallel execution fails

Complexity

  • Time Complexity (TC): O(n) in terms of task scheduling, but overall runtime depends on the largest element × scale
  • Space Complexity (SC): O(n) for temporary files and parallel tasks

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