Skip to content

Conversation

Siddhram
Copy link
Contributor

This PR introduces a fully documented implementation of IntroSort in R, a hybrid sorting algorithm designed for robust performance and adaptive behavior on numeric vectors.

Overview

The intro.sort function combines three sorting strategies:

  • Quick Sort for general partitioning
  • Heap Sort when recursion depth exceeds a safe limit
  • Insertion Sort for small partitions

This hybrid approach ensures O(n log n) worst-case performance while maintaining excellent average-case efficiency. It is particularly suitable for sorting arrays where performance consistency is important.

Features

  • Hybrid sorting algorithm: Quick Sort + Heap Sort + Insertion Sort
  • Automatically switches to Heap Sort on deep recursion
  • Efficiently sorts small partitions with Insertion Sort
  • Handles numeric vectors of arbitrary length
  • Includes example usage at the bottom of the script
  • Follows consistent API style with other R sorting algorithms

Complexity

  • Time Complexity: O(n log n) worst-case; O(n log n) average-case
  • Space Complexity: O(log n) due to recursion

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