Summary

Like stacks, queues are fundamental data structures. Queues help us realize the FIFO approach. We looked at how FIFO queues are implemented in the imperative world. We noted that we would end up with too much of copying if we insert new nodes at the end of a list. We could do this in the imperative world but would end up with O(n) copying performance to achieve persistent FIFO queues.

Instead, we looked at an innovative design involving two stacks. We also looked at the Scala implementation and discussed some Scala idioms.

Priority queues are an important variation of queues. We define a priority for each element of the queue and wish to pop the element with the highest priority.

Heap is a famous data structure for implementing the priority ...

Get Learning Functional Data Structures and Algorithms now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.