Book contents
- Frontmatter
- Contents
- Preface
- Introduction
- I Basic Principles
- II Applications
- 5 Formal Terms, Pattern Matching, Unification
- 6 Balanced Trees
- 7 Graphs and Problem Solving
- 8 Syntactic Analysis
- 9 Geometry and Drawings
- 10 Exact Arithmetic
- III Implementation
- Quick Reference to the Syntax of Caml Light
- How to Get Caml, MLgraph, and the Examples
- References
- Index
- Index of Types and Functions
6 - Balanced Trees
Published online by Cambridge University Press: 05 June 2012
- Frontmatter
- Contents
- Preface
- Introduction
- I Basic Principles
- II Applications
- 5 Formal Terms, Pattern Matching, Unification
- 6 Balanced Trees
- 7 Graphs and Problem Solving
- 8 Syntactic Analysis
- 9 Geometry and Drawings
- 10 Exact Arithmetic
- III Implementation
- Quick Reference to the Syntax of Caml Light
- How to Get Caml, MLgraph, and the Examples
- References
- Index
- Index of Types and Functions
Summary
This chapter defines a group of functions to manage large-scale data sets. These functions use trees as data structures because they are so well adapted to representing data sets that evolve dynamically, that is, data sets where the size can grow or shrink during computations.
The specific data structure we use is a binary tree. The algorithms we propose make it possible to keep these binary trees balanced, and this property ensures the efficiency of operations we want to carry out.
The main operations for managing a data set are these:
searching for an element in the data set;
adding an element to the data set;
removing an element from the data set.
To search naively for an element in a data set, we can simply sweep sequentially through all the elements of the set, but that takes time proportional to the size of the data set. Its complexity is thus O(n). This technique is the only one we can use when we are managing data sets generically because we do not know any particular properties of the set.
In order to search more efficiently, we have to make hypotheses about the structure of the data set under consideration. For example, if we can assume that the data are ordered, then we can use a binary search as we did in Section 4.4.1 to represent sets by sorted arrays.
- Type
- Chapter
- Information
- The Functional Approach to Programming , pp. 157 - 194Publisher: Cambridge University PressPrint publication year: 1998