mirror of
https://github.com/TheAlgorithms/C.git
synced 2026-02-13 13:54:36 +00:00
[FEATURE] Add implementation of Intro Sort #197
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @R2-STAR on GitHub (Sep 30, 2025).
Detailed description
Description:
I would like to contribute an implementation of the IntroSort (Introspective Sort) algorithm in C.
IntroSort is a hybrid sorting algorithm that begins with QuickSort, switches to HeapSort when recursion depth exceeds a certain limit, and uses InsertionSort for small partitions. This makes it both fast in practice and worst-case optimal. In fact, it is the algorithm behind std::sort.
Proposed Changes:
Add a new file intro_sort.cpp under the sorting/ directory.
Implementation will include:
-QuickSort as the base algorithm
-Depth-limit detection to switch to HeapSort
-InsertionSort for small arrays
-Include time and space complexity in comments.
-Add sample test cases in main() for verification.
Benefits:
1)Adds a widely used, practical, and high-performance sorting algorithm.
2)Complements the existing collection of sorting algorithms.
Context
Context
This change is important because IntroSort is one of the most widely used practical sorting algorithms, being the default in C’s
std::sort.I would use it to:
This can benefit other users by:
std::sortis so efficient.Possible implementation
Possible Implementation
The implementation of IntroSort in C can be structured as follows:
Threshold for small partitions
Recursion depth monitoring
2 * log2(n).Partitioning
Driver function
introSort()that initializes the depth limit and calls the recursive utility.Testing
main()to validate correctness.The final file will be named
intro_sort.cppunder thesorting/directory, following the style of existing algorithms.Kindly assign me this issue so that I can start working on it.
@kokatesaurabh commented on GitHub (Oct 1, 2025):
Hi @R2-STAR,
I’ve completed the implementation of the IntroSort algorithm in C as described in this issue.
The
introsort.cfile includes QuickSort as the base, switches to HeapSort at the depth limit,and uses InsertionSort for small partitions. All test cases have been verified and it’s working correctly.
You can review the PR for the full implementation.
@github-actions[bot] commented on GitHub (Nov 1, 2025):
This issue has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@github-actions[bot] commented on GitHub (Nov 9, 2025):
Please ping one of the maintainers once you add more information and updates here. If this is not the case and you need some help, feel free to ask for help in our Gitter channel or our Discord server. Thank you for your contributions!