© Thomas Mailund 2017

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

6. Sets and Search Trees

Thomas Mailund

(1)Aarhus N, Denmark

We saw earlier how we can represent collections of elements such that we can efficiently iterate through them and efficiently merge two such collections. In this chapter, we turn “bags” into “sets” by considering data structures that allow us to efficiently insert, delete, and check for membership of elements:

insert <- function(x, elm) UseMethod("insert")remove <- function(x, elm) UseMethod("remove")member <- function(x, elm) UseMethod("member")

We do this through so-called search trees—trees with the property that all elements in the left subtree of a node will have values ...

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.