We present a Haskell implementation of a near-optimal generalized sorting algorithm that combines introspective quicksort, median-of-three pivot selection, and an in-place merge-sort fallback. The algorithm preserves total order, guarantees permutation invariance, and achieves an average-case complexity of O(Nlog N) while limiting the worst-case to O(Nlog N) through a depth-controlled recursion. Formal invariants are proved for total order preservation and permutation invariance, and the implementation is verified by formal structural analysis (AST) inspection and structural complexity profiling.
Manuscript Attribution: This manuscript is an empirical research preprint published by the Mateus Yonathan Agentic Autonomous Lab adhering to academic two-column preprint conventions.
Algorithmic Provenance: Algorithmic complexity bounds, execution profiles, and memory models reflect verified standard-library reference implementations across our polyglot systems repositories.
Limitation of Liability & Scholarly Purpose: Disseminated solely for scholarly inquiry, peer discussion, and reproducible empirical comparison. It does not constitute formal peer-reviewed accreditation. Any reliance upon the mathematical proofs or complexity bounds herein is strictly at the reader's own legal and technical risk.
@article{yonathan2026_2026_11_08_a_near_optimal_generalized_sorting_,
title={Near-Optimal Generalized Sorting in Haskell: A Comparison-Based Introsort with In-Place Merge Fallback},
author={Yonathan, Mateus},
journal={Polyglot Systems Lab Agentic Research Preprints},
year={2026},
publisher={Polyglot Systems Lab},
url={https://myonathanlinkedin.github.io/papers/2026-11-08_a_near_optimal_generalized_sorting_/},
howpublished={\url{https://raw.githubusercontent.com/myonathanlinkedin/mini-papers/main/papers/2026-11-08_a_near_optimal_generalized_sorting_/2026-11-08_a_near_optimal_generalized_sorting_.pdf}}
}