Skip to content

Conversation

@GziXnine
Copy link
Contributor

@GziXnine GziXnine commented Jan 9, 2026

Checklist

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new algorithms include a corresponding test class that validates their functionality.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java.

Summary

This Pull Request adds an implementation of Smooth Sort to the com.thealgorithms.sorts package. Smooth Sort is an adaptive, in-place sorting algorithm invented by Edsger W. Dijkstra (1981), designed to achieve near-linear performance on already sorted or nearly sorted inputs while maintaining an O(n log n) worst-case bound.

Features

  • Adaptive behavior with improved performance on nearly sorted arrays
  • In-place sorting with O(1) auxiliary space
  • Handles edge cases (empty array, single-element array, sorted input, reverse sorted input, and random input)
  • Implements SortAlgorithm consistently with existing sorting implementations

Implementation Details

  • Uses Leonardo numbers to manage the sizes of heap-ordered Leonardo trees
  • Core operations implemented:
    • sift: restores heap order within a Leonardo tree
    • trinkle: restores global heap order across the forest using the “stepson” relationship between roots
  • Documentation follows the repository’s Javadoc conventions and includes reference links

Tests

  • Adds SmoothSortTest extending the shared SortingAlgorithmTest suite
  • Validates correctness across common scenarios used throughout the repository (including empty/singleton/duplicates/strings/random arrays)

Complexity

  • Best Case: O(n)
  • Average Case: O(n log n)
  • Worst Case: O(n log n)
  • Space: O(1) auxiliary space (in-place)

Closes #6632

@codecov-commenter
Copy link

codecov-commenter commented Jan 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.98%. Comparing base (ca4bebc) to head (8bf1a0e).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7200      +/-   ##
============================================
+ Coverage     78.89%   78.98%   +0.09%     
- Complexity     6880     6907      +27     
============================================
  Files           774      775       +1     
  Lines         22746    22822      +76     
  Branches       4468     4482      +14     
============================================
+ Hits          17945    18027      +82     
+ Misses         4078     4076       -2     
+ Partials        723      719       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@DenizAltunkapan DenizAltunkapan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution @GziXnine

@DenizAltunkapan DenizAltunkapan merged commit fe6066b into TheAlgorithms:master Jan 9, 2026
7 checks passed
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.

[FEATURE REQUEST] Smooth Sort Sorting Algorithm

3 participants