Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #21: Implement Selection Sort #32

Merged
merged 4 commits into from
Jan 14, 2025

Conversation

Brad-Edwards
Copy link
Collaborator

This PR implements the selection sort algorithm with the following features:

  • Generic implementation supporting any type implementing Ord + Clone + Debug
  • O(n²) time complexity in all cases
  • O(1) auxiliary space
  • Minimizes the number of swaps (O(n) swaps vs O(n²) comparisons)
  • In-place algorithm
  • Comprehensive documentation
  • Extensive unit tests covering:
    • Empty and single-element arrays
    • Already sorted arrays
    • Reverse sorted arrays
    • Random order arrays
    • Arrays with duplicates
    • Large arrays
    • Arrays with all equal elements
    • Arrays with alternating values
    • Negative numbers
    • Mixed positive and negative numbers
    • Different data types (integers, floats, strings)
    • Verification of O(n) swaps property

Key advantages:

  • Simple implementation
  • Performs well on small arrays
  • Minimal memory writes (good when write cost is high)
  • In-place sorting with O(1) extra space

@Brad-Edwards Brad-Edwards merged commit 1b0ca75 into main Jan 14, 2025
@Brad-Edwards Brad-Edwards deleted the feature/issue-21-selectionsort branch January 14, 2025 07:43
Brad-Edwards added a commit that referenced this pull request Jan 15, 2025
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