Skip to main content

Optimal purely functional priority queues

  • Gerth Stølting Brodal (a1) and Chris Okasaki (a2)

Brodal recently introduced the first implementation of imperative priority queues to support findMin, insert and meld in O(1) worst-case time, and deleteMin in O(log n) worst-case time. These bounds are asymptotically optimal among all comparison-based priority queues. In this paper, we adapt Brodal's data structure to a purely functional setting. In doing so, we both simplify the data structure and clarify its relationship to the binomial queues of Vuillemin, which support all four operations in O(log n) time. Specifically, we derive our implementation from binomial queues in three steps: first, we reduce the running time of insert to O(1) by eliminating the possibility of cascading links; second, we reduce the running time of findMin to O(1) by adding a global root to hold the minimum element; and finally, we reduce the running time of meld to O(1) by allowing priority queues to contain other priority queues. Each of these steps is expressed using ML-style functors. The last transformation, known as data-structural bootstrapping, is an interesting application of higher-order functors and recursive structures.

Corresponding author
*Research partially supported by the ESPRIT II Basic Research Actions Program of the EC under contract no. 7141 (project ALCOM II) and by the Danish Natural Science Research Council (Grant No. 9400044).
Research supported by the Advanced Research Projects Agency CSTO under the title “The Fox Project: Advanced Languages for Systems Software”, ARPA Order No. C533, issued by ESC/ENS under Contract No. F19628-95-C-0050.
Hide All

Basic Research in Computer Science, Centre of the Danish National Research Foundation.

Hide All
Brodal, G. S. (1995) Fast meldable priority queues. Workshop on Algorithms and Data Structures: Lecture Notes in Computer Science 955 pp. 282290. Springer-Verlag.
Brodal, G. S. (1996) Worst-case priority queues. ACM-SIAM Symposium on Discrete Algorithms pp. 5258.
Brown, M. R. (1978) Implementation and analysis of binomial queue algorithms. SIAM J. Computing 7(3):298319.
Buchsbaum, A. L. and Tarjan, R. E. (1995) Confluently persistent deques via data structural bootstrapping. J. Algorithms 18(3):513547.
Buchsbaum, A. L., Sundar, R. and Tarjan, R. E. (1995) Data-structural bootstrapping, linear path compression, and catenable heap-ordered double-ended queues. SIAM J. Computing 24(6):11901206.
Crane, C. A. (1972) Linear lists and priority queues as balanced binary trees. PhD thesis, Computer Science Department, Stanford University. (Available as STAN-CS-72-259.)
Driscoll, J. R., Sarnak, N., Sleator, D. D. K. and Tarjan, R. E. (1989) Making data structures persistent. J. Computer and System Sciences 38(1):86124.
Fredman, M. L. and Tarjan, R. E. (1987) Fibonacci heaps and their uses in improved network optimization algorithms. J. ACM 34(3):596615.
Fredman, M. L., Sedgewick, R., Sleator, D. D. K. and Tarjan, R. E. (1986) The pairing heap: A new form of self-adjusting heap. Algorithmica 1(1):111129.
Hood, R. (1982) The Efficient Implementation of Very-High-Level Programming Language Constructs. PhD thesis, Department of Computer Science, Cornell University. (Available as Cornell TR 82-503.)
Hoogerwoord, R. R. (1992) A logarithmic implementation of flexible arrays. Conference on Mathematics of Program Construction: Lecture Notes in Computer Science 669 pp. 191207. Springer-Verlag.
Hudak, P., Peyton Jones, S., Wadler, P., Boutel, B., Fairbairn, J., Fasel, J., Guzḿn, M., Hammond, K., Hughes, J., Johnsson, T., Kieburtz, D., Nikhil, R., Partain, W. and Peterson, J. (1992) Report on the functional programming language Haskell, Version 1.2. SIGPLAN Notices 27(5).
Jones, D. W. (1986) An empirical comparison of priority-queue and event-set implementations. Comm. ACM 29(4):300311.
Kaldewaij, A. and Schoenmakers, B. (1991) The derivation of a tighter bound for top-down skew heaps. Information Processing Letters 37(5):265271.
Kaplan, H. and Tarjan, R. E. (1995) Persistent lists with catenation via recursive slow-down. ACM Symposium on Theory of Computing pp. 93102.
King, D. J. (1994) Functional binomial queues. Glasgow Workshop on Functional Programming pp. 141150.
MacQueen, D. B. and Tofte, M. (1994) A semantics for higher-order functors. European Symposium on Programming pp. 409423.
Milner, R., Tofte, M. and Harper, R. (1990) The Definition of Standard ML. The MIT Press.
Myers, E. W. (1983) An applicative random-access stack. Information Processing Letters 17(5):241248.
Okasaki, C. (1995a) Amortization, lazy evaluation, and persistence: Lists with catenation via lazy linking. IEEE Symposium on Foundations of Computer Science pp. 646654.
Okasaki, C. (1995b) Purely functional random-access lists. Conference on Functional Programming Languages and Computer Architecture pp. 8695.
Okasaki, C. (1995c) Simple and efficient purely functional queues and deques. J. Functional Programming 5(4):583592.
Okasaki, C. (1996) The role of lazy evaluation in amortized data structures. ACM SIGPLAN International Conference on Functional Programming pp. 6272.
Paulson, L. C. (1991) ML for the Working Programmer. Cambridge University Press.
Schoenmakers, B. (1992) Data Structures and Amortized Complexity in a Functional Setting. PhD thesis, Eindhoven University of Technology.
Sleator, D. D. K. and Tarjan, R. E. (1985) Self-adjusting binary search trees. J. ACM, 32(3):652686.
Sleator, D. D. K. and Tarjan, R. E. (1986) Self-adjusting heaps. SIAM J. Computing 15(1):5269.
Tarjan, R. E. (1983) Data Structures and Network Algorithms. CBMS Regional Conference Series in Applied Mathematics, vol. 44. Society for Industrial and Applied Mathematics.
Vuillemin, J. (1978) A data structure for manipulating priority queues. Comm. ACM 21(4):309315.
Wadler, P. (1990) Linear types can change the world! Proceedings of the IFIP TC 2 Working Conference on Programming Concepts and Methods pp. 561581.
Williams, J. W. J. (1964) Algorithm 232: Heapsort. Comm. ACM 7(6):347348.
Recommend this journal

Email your librarian or administrator to recommend adding this journal to your organisation's collection.

Journal of Functional Programming
  • ISSN: 0956-7968
  • EISSN: 1469-7653
  • URL: /core/journals/journal-of-functional-programming
Please enter your name
Please enter a valid email address
Who would you like to send this to? *


Full text views

Total number of HTML views: 0
Total number of PDF views: 0 *
Loading metrics...

Abstract views

Total abstract views: 0 *
Loading metrics...

* Views captured on Cambridge Core between <date>. This data will be updated every 24 hours.

Usage data cannot currently be displayed

Optimal purely functional priority queues

  • Gerth Stølting Brodal (a1) and Chris Okasaki (a2)
Submit a response


No Discussions have been published for this article.


Reply to: Submit a response

Your details

Conflicting interests

Do you have any conflicting interests? *