Skip to content

feat: add Comb Sort algorithm implementation#2177

Open
divorahim13 wants to merge 1 commit into
trekhleb:masterfrom
divorahim13:feat/add-comb-sort
Open

feat: add Comb Sort algorithm implementation#2177
divorahim13 wants to merge 1 commit into
trekhleb:masterfrom
divorahim13:feat/add-comb-sort

Conversation

@divorahim13
Copy link
Copy Markdown

Description

This PR adds a Comb Sort algorithm implementation to the sorting algorithms collection.

What is Comb Sort?

Comb Sort is an improvement over Bubble Sort. It eliminates small values (turtles) near the end of the list by using a gap larger than 1. The gap starts at the length of the list and shrinks by a factor of 1.3 each iteration until it reaches 1.

Files Added

  • src/algorithms/sorting/comb-sort/CombSort.js - Main implementation extending the Sort base class
  • src/algorithms/sorting/comb-sort/README.md - Documentation with complexity analysis and references
  • src/algorithms/sorting/comb-sort/__test__/CombSort.test.js - Test suite following existing patterns

Complexity Analysis

Case Time Complexity Space Complexity
Best O(n log n) O(1)
Average O(n²/2^p) O(1)
Worst O(n²) O(1)

Implementation Highlights

  • Uses the empirically proven shrink factor of 1.3 for optimal gap reduction
  • Properly extends the Sort base class with comparator and visiting callback support
  • Handles edge cases including already sorted arrays and arrays with duplicates
  • Follows the project's coding style and patterns

References

Testing

All existing sorting tests pass with the new implementation.

Add Comb Sort algorithm with:
- Implementation extending the Sort base class
- Documentation with complexity analysis and references
- Test suite following existing patterns
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