# `Tempo.IntervalSet.Backend.Tree`
[🔗](https://github.com/elixir-tempo/tempo/blob/v1.6.4/lib/tempo/interval_set/backend/tree.ex#L1)

An interval-tree `Tempo.IntervalSet.Backend`: a balanced binary tree
over the members, ordered by `from` endpoint, with each node
augmented by the maximum `to` endpoint in its subtree.

The augmentation is what makes the tree an *interval* tree: an
`overlapping/2` query prunes every subtree whose maximum end lies at
or before the queried range, answering stabbing and overlap questions
in O(log n + k) instead of a full scan. Construction is O(n) — the
member list `Tempo.IntervalSet.new/2` supplies is already sorted, so
the tree is built perfectly balanced with no rebalancing.

Endpoint positions are precomputed once at construction as gregorian
UTC seconds (`Tempo.Compare.to_utc_seconds/1`), so tree comparisons
are integer comparisons and remain correct across calendars and
zones.

Because that projection needs a year, **members must be anchored**
(and bounded, as every set member already is). Building a tree from
non-anchored members (`~o"T10:00/T11:00"`) raises an
`ArgumentError` — keep those sets on the default list backend.

Choose this backend for large, query-heavy sets — multi-year
calendar feeds probed with `Tempo.IntervalSet.covered?/2` or used as
a `skipping:` busy set:

    Tempo.IntervalSet.new(events, backend: :tree)

---

*Consult [api-reference.md](api-reference.md) for complete listing*
