September 2017
Beginner to intermediate
396 pages
9h 46m
English
We implemented a Leftist Tree here. This is a very good example of immutability, data persistence, and in general, how to implement a data structure in Haskell. We started with a representation for a queue, heap, and an invariant Leftist property. A typical leftist tree looks like the one shown in this diagram:

Then, we proceeded to implement a mergeQs function, which is at the heart of the implementation. The operations insert and deleteMin both result in an operation that changes the structure of the tree. This change can violate the leftist property or the heap order. The mergeQs function merges two trees and restores these ...
Read now
Unlock full access