mirror of
https://github.com/TheAlgorithms/C.git
synced 2026-02-04 05:44:35 +00:00
[PR #1489] [FEATURE] Add implementation of IntroSort in C #2092
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?
Original Pull Request: https://github.com/TheAlgorithms/C/pull/1489
State: closed
Merged: No
This PR adds an implementation of the IntroSort (Introspective Sort) algorithm in C.
IntroSort is a hybrid sorting algorithm that combines QuickSort, HeapSort, and InsertionSort.
It begins with QuickSort, switches to HeapSort when recursion depth exceeds a certain limit,
and uses InsertionSort for small partitions. This ensures both fast average-case performance
and worst-case optimality. IntroSort is the algorithm behind std::sort.
Proposed Changes:
introsort.cwith the full IntroSort implementation.2 * log2(n)(bit-hack__builtin_clzused for log2).swap,heapify,printArray, and test cases inmain().Benefits:
Testing:
This implementation ensures IntroSort is easy to compile and run on any system without additional dependencies (
math.hremoved;log2replaced with bit-hack).Closes #1488.