Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I implement a purely functional standard binary heap (ocaml or haskell)?

Tags:

People also ask

How is binary heap is implemented?

Heaps are commonly implemented with an array. Any binary tree can be stored in an array, but because a binary heap is always a complete binary tree, it can be stored compactly. No space is required for pointers; instead, the parent and children of each node can be found by arithmetic on array indices.

Is OCaml a purely functional language?

OCaml is a functional (applicative) programming language, but also an imperative language, and also an object-oriented language.


Are there any implementations of a purely functional standard binary heap? I know there are lots of interesting heaps eg: Binomial, leftist heap, they all have functional implementation, just wonder is there a way to implement standard binary heap or we have to use Array to implement it, because of the immutable type ? Thanks!