© Thomas Mailund 2017

Thomas Mailund, Functional Data Structures in R, https://doi.org/10.1007/978-1-4842-3144-9_5

5. Heaps

Thomas Mailund

(1)Aarhus N, Denmark

Heaps, or priority queues, are collections of elements from an ordered set where besides checking for emptiness and inserting elements

is_empty <- function(x) UseMethod("is_empty")insert <- function(x, elm) UseMethod("insert")

we can also access and delete the smallest element:1

find_minimal <- function(heap) UseMethod("find_minimal")delete_minimal <- function(heap) UseMethod("delete_minimal")

Heaps do not necessarily contain sets. It is possible for heaps to have multiple elements with the same value.

In addition to these operations, we will also require that we can merge two heaps:

merge <- ...

Get Functional Data Structures in R: Advanced Statistical Programming in R 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.