Skip to content

Commit

Permalink
Issue #23: Add countingsort interface and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
openhands-agent committed Jan 1, 2025
1 parent 2fa5c89 commit 57b780a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
4 changes: 3 additions & 1 deletion crates/cs/blocks-cs-sort/src/algorithms.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Sorting algorithms
pub mod quicksort;
pub mod countingsort;

// Re-export commonly used functions for convenience
pub use self::quicksort::sort as quicksort;
pub use self::quicksort::sort as quicksort;
pub use self::countingsort::sort as countingsort;
41 changes: 41 additions & 0 deletions crates/cs/blocks-cs-sort/src/algorithms/countingsort.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use std::fmt::Debug;

/// Counting Sort implementation for sorting slices of unsigned integers.
///
/// # Algorithm Overview
/// Counting sort works by:
/// 1. Finding the range of input data (min to max)
/// 2. Counting the frequency of each value in the input range
/// 3. Building the cumulative frequency array
/// 4. Placing each element in its sorted position
///
/// # Time Complexity
/// - Best Case: O(n + k) where k is the range of input
/// - Average Case: O(n + k)
/// - Worst Case: O(n + k)
///
/// # Space Complexity
/// - O(k) auxiliary space where k is the range of input
///
/// # Stability
/// - Stable sort algorithm
///
/// # Advantages
/// - Linear time complexity when k = O(n)
/// - Excellent for integers with known, limited range
/// - Stable sorting algorithm
/// - Can be used as a subroutine in radix sort
///
/// # Limitations
/// - Only works with non-negative integers
/// - Not efficient when the range of input values is much larger than n
/// - Requires extra space proportional to the range of input
pub fn sort(slice: &mut [u32]) {
// Implementation will be added later
}

/// Finds the maximum value in the slice
fn find_max(slice: &[u32]) -> u32 {
// Implementation will be added later
0
}

0 comments on commit 57b780a

Please sign in to comment.