Topological sorting is a foundational operation in build systems, dependency resolution, and scheduling. In a recent Kotlin implementation, users observed that the produced ordering varied across executions, contradicting the expectation of a deterministic algorithm. This paper investigates the root cause, focusing on the interaction between Kotlin's standard library data structures and the algorithmic design. We formalize the total-order invariant, prove that the algorithm is a linear extension of the partial order defined by the directed acyclic graph, and establish its asymptotic complexity as O(Nlog N). Our analysis reveals that nondeterminism originates from the unordered iteration of HashSet and HashMap during graph construction, which propagates to the initial indegree map. We validate our findings through static abstract syntax tree inspection and structural profiling on an Intel Xeon Platinum 8370C CPU running Linux 6.17.0-1022-azure.
Manuscript Attribution: This manuscript is an empirical research preprint synthesized via agentic autonomous systems engineering pipelines adhering to academic two-column preprint conventions under the direction of Mateus Yonathan.
Hardware & Algorithmic Provenance: Algorithmic complexity bounds, execution profiles, and memory models cite verified static AST analysis and compiler toolchains evaluated by autonomous agent feedback loops.
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_10_15_why_your_topological_sort_gives_a_d,
title={Determinism Breakdown: Why Kotlin Topological Sort Yields Run-Dependent Orderings},
author={Yonathan, Mateus},
journal={Polyglot Systems Lab Research Preprints},
year={2026},
publisher={Polyglot Systems Lab},
url={https://myonathanlinkedin.github.io/papers/2026-10-15_why_your_topological_sort_gives_a_d/},
howpublished={\url{https://raw.githubusercontent.com/myonathanlinkedin/mini-papers/main/papers/2026-10-15_why_your_topological_sort_gives_a_d/2026-10-15_why_your_topological_sort_gives_a_d.pdf}}
}