An Optimal Algorithm for Sorting in Trees

Authors Jishnu Roychoudhury , Jatin Yadav

Thumbnail PDF


  • Filesize: 0.83 MB
  • 14 pages

Document Identifiers

Author Details

Jishnu Roychoudhury
  • Princeton University, NJ, USA
Jatin Yadav
  • Indian Institute of Technology Delhi, India

Cite AsGet BibTex

Jishnu Roychoudhury and Jatin Yadav. An Optimal Algorithm for Sorting in Trees. In 43rd IARCS Annual Conference on Foundations of Software Technology and Theoretical Computer Science (FSTTCS 2023). Leibniz International Proceedings in Informatics (LIPIcs), Volume 284, pp. 7:1-7:14, Schloss Dagstuhl – Leibniz-Zentrum für Informatik (2023)


Sorting is a foundational problem in computer science that is typically employed on sequences or total orders. More recently, a more general form of sorting on partially ordered sets (or posets), where some pairs of elements are incomparable, has been studied. General poset sorting algorithms have a lower-bound query complexity of Ω(wn + n log n), where w is the width of the poset. We consider the problem of sorting in trees, a particular case of partial orders. This problem is equivalent to the problem of reconstructing a rooted directed tree from path queries. We parametrize the complexity with respect to d, the maximum degree of an element in the tree, as d is usually much smaller than w in trees. For example, in complete binary trees, d = Θ(1), w = Θ(n). The previous known upper bounds are O(dn log² n) [Wang and Honorio, 2019] and O(d² n log n) [Ramtin Afshar et al., 2020], and a recent paper proves a lower bound of Ω(dn log_d n) [Paul Bastide, 2023] for any Las Vegas randomized algorithm. In this paper, we settle the complexity of the problem by presenting a randomized algorithm with worst-case expected O(dnlog_d n) query and time complexity.

Subject Classification

ACM Subject Classification
  • Theory of computation → Design and analysis of algorithms
  • Sorting
  • Trees


  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    PDF Downloads


  1. Ramtin Afshar, Michael T. Goodrich, Pedro Matias, and Martha C. Osegueda. Reconstructing Biological and Digital Phylogenetic Trees in Parallel. In Fabrizio Grandoni, Grzegorz Herman, and Peter Sanders, editors, 28th Annual European Symposium on Algorithms (ESA 2020), volume 173 of Leibniz International Proceedings in Informatics (LIPIcs), pages 3:1-3:24, Dagstuhl, Germany, 2020. Schloss Dagstuhl - Leibniz-Zentrum für Informatik. URL:
  2. Ramtin Afshar, Michael T Goodrich, Pedro Matias, and Martha C Osegueda. Parallel network mapping algorithms. In Proceedings of the 33rd ACM Symposium on Parallelism in Algorithms and Architectures, pages 410-413, 2021. Google Scholar
  3. Noga Alon, Manuel Blum, Amos Fiat, Sampath Kannan, Moni Naor, and Rafail Ostrovsky. Matching nuts and bolts. In SODA, pages 690-696. Citeseer, 1994. Google Scholar
  4. Indranil Banerjee and Dana Richards. Sorting under forbidden comparisons. In 15th Scandinavian Symposium and Workshops on Algorithm Theory (SWAT 2016). Schloss Dagstuhl - Leibniz-Zentrum fuer Informatik, 2016. Google Scholar
  5. Arindam Biswas, Varunkumar Jayapaul, and Venkatesh Raman. Improved bounds for poset sorting in the forbidden-comparison regime. In Conference on Algorithms and Discrete Applied Mathematics, pages 50-59. Springer, 2017. Google Scholar
  6. Jean Cardinal and Samuel Fiorini. On generalized comparison-based sorting problems. In Space-Efficient Data Structures, Streams, and Algorithms, pages 164-175. Springer, 2013. Google Scholar
  7. Thomas H Cormen, Charles E Leiserson, Ronald L Rivest, and Clifford Stein. Introduction to algorithms. MIT press, 2022. Google Scholar
  8. C Daskalakis, RM Karp, E Mossel, SJ Riesenfeld, and E Verbin. Sorting and selection in posets. SIAM Journal on Computing, 40(3), 2011. Google Scholar
  9. U Faigle and Gy Turán. Sorting and recognition problems for ordered sets. SIAM Journal on Computing, 17(1), 1988. Google Scholar
  10. Brent Heeringa, Marius Cătălin Iordan, and Louis Theran. Searching in dynamic tree-like partial orders. In 12th international conference on Algorithms and data structures (WADS), 2011. Google Scholar
  11. Jotun J Hein. An optimal algorithm to reconstruct trees from additive distance data. Bulletin of mathematical biology, 51(5):597-603, 1989. Google Scholar
  12. Zhiyi Huang, Sampath Kannan, and Sanjeev Khanna. Algorithms for the generalized sorting problem. In 2011 IEEE 52nd Annual Symposium on Foundations of Computer Science (FOCS), pages 738-747. IEEE, 2011. Google Scholar
  13. M. Jagadish and Anindya Sen. Learning a bounded-degree tree using separator queries. In Sanjay Jain, Rémi Munos, Frank Stephan, and Thomas Zeugmann, editors, Algorithmic Learning Theory - 24th International Conference, ALT 2013, Singapore, October 6-9, 2013. Proceedings, volume 8139 of Lecture Notes in Computer Science, pages 188-202. Springer, 2013. URL:
  14. Shaofeng H.-C. Jiang, Wenqian Wang, Yubo Zhang, and Yuhao Zhang. Algorithms for the generalized poset sorting. arXiv preprint, 2023. URL:
  15. William Kuszmaul and Shyam Narayanan. Stochastic and worst-case generalized sorting revisited. In 2021 IEEE 62nd Annual Symposium on Foundations of Computer Science (FOCS), pages 1056-1067. IEEE, 2022. Google Scholar
  16. K. Onak and P. Parys. Generalization of binary search: Searching in trees and forest-like partial orders. In IEEE Symposium on Foundations of Computer Science (FOCS), 2006. Google Scholar
  17. Carla Groenland Paul Bastide. Optimal distance query reconstruction for graphs without long induced cycles. arXiv preprint, 2023. URL:
  18. Lev Reyzin and Nikhil Srivastava. On the longest path algorithm for reconstructing trees from distance matrices. Information processing letters, 101(3):98-100, 2007. Google Scholar
  19. Zhaosen Wang and Jean Honorio. Reconstructing a bounded-degree directed tree using path queries. In 2019 57th Annual Allerton Conference on Communication, Control, and Computing (Allerton), pages 506-513. IEEE, 2019. Google Scholar
  20. Michael S Waterman, Temple F Smith, Mona Singh, and William A Beyer. Additive evolutionary trees. Journal of theoretical Biology, 64(2):199-213, 1977. Google Scholar
  21. Li Zhang, Valerie King, and Yunhong Zhout. On the complexity of distance-based evolutionary tree reconstruction. In Proceedings of the fourteenth annual ACM-SIAM symposium on Discrete algorithms, page 444. SIAM, 2003. Google Scholar
Questions / Remarks / Feedback

Feedback for Dagstuhl Publishing

Thanks for your feedback!

Feedback submitted

Could not send message

Please try again later or send an E-mail