Skip to content

Feat/tim sort#2154

Open
Sadam-jay wants to merge 4 commits intotrekhleb:masterfrom
Sadam-jay:feat/tim-sort
Open

Feat/tim sort#2154
Sadam-jay wants to merge 4 commits intotrekhleb:masterfrom
Sadam-jay:feat/tim-sort

Conversation

@Sadam-jay
Copy link
Copy Markdown

Tim Sort implementation (Hybrid Sort)

This PR adds a Tim Sort implementation to the sorting/ collection.

What it does

Tim Sort is a high-performance, stable, hybrid sorting algorithm derived from Merge Sort and Insertion Sort. It is the default sorting algorithm used in Python (list.sort) and Java (Arrays.sort for objects). It exploits "natural runs" in real-world data to achieve near-linear performance in many cases.

Complexity

  • Best Time Complexity: O(n)
  • Average/Worst Time Complexity: O(n log n)
  • Space Complexity: O(n)
  • Stable: Yes

Files added

  • src/algorithms/sorting/tim-sort/TimSort.js: The algorithm implementation using the base Sort class.
  • src/algorithms/sorting/tim-sort/__test__/TimSort.test.js: Test suite using the project's SortTester.
  • src/algorithms/sorting/tim-sort/README.md: Documentation with complexity analysis and references.

Checklist

  • Code follows the existing project style and patterns.
  • npm run lint passes with no errors (specifically addressed no-param-reassign).
  • npm test passes with 100% coverage for the new code.
  • README.md includes a clear explanation and complexity table.

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