-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #23: Add countingsort interface and documentation
- Loading branch information
1 parent
2fa5c89
commit 57b780a
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |