Tree searching is the process of locating a record in a tree data structure. Two quantities are generally of interest: the average number of comparisons required to
1. Find an existing random record, and
2. Insert a new random record into a data structure.
The following asymptotics concern digital search trees built by inserting keys into an initially empty tree. The keys are independent
and identically distributed infinite streams of unbiased binary digits. Each
graph vertex stores one key, and the successive digits
choose the left or right child while descending from the
root vertex. A successful query is chosen uniformly
from the stored keys, while an unsuccessful query is an independent stream. One comparison
with the stored key is counted at each visited graph
vertex.
Some constants which arise in this model are
|
(1)
| |||
|
(2)
| |||
|
(3)
| |||
|
(4)
| |||
|
(5)
| |||
|
(6)
|
(OEIS A065442 and A065443), where
is a q-polygamma function. Erdős
(1948) proved that
is irrational, and
is sometimes known as the Erdős-Borwein
constant.
The expected number of comparisons for a successful search is
|
(7)
| |||
|
(8)
|
and for an unsuccessful search is
|
(9)
| |||
|
(10)
|
(OEIS A086309 and A086310). Here
is the Euler-Mascheroni constant, lg is the base 2 logarithm, and
. The terms
,
, and
are small-amplitude oscillations periodic in
. The corresponding variance terms
and
are periodic functions of
.
The variance for searching is
|
(11)
| |||
|
(12)
|
(OEIS A086311) and for inserting is
|
(13)
| |||
|
(14)
|
(OEIS A086312).
A pair of twin vacancies consists of the two null child pointers at a graph vertex. The expected number of such pairs in a digital search tree is
|
(15)
|
where
|
(16)
| |||
|
(17)
|
(OEIS A086313), which can also be written
|
(18)
|
(Flajolet and Richmond 1992, p. 318). Here, the individual pieces are given by
|
(19)
| |||
|
(20)
| |||
|
(21)
| |||
|
(22)
| |||
|
(23)
| |||
|
(24)
| |||
|
(25)
|
(OEIS A048651), where is a Jacobi
theta function and
denotes its derivative with respect to
, evaluated at
, and
|
(26)
| |||
|
(27)
|
(OEIS A086315; Flajolet and Sedgewick 1986, p. 759; Finch 2003, with a typo in the exponent appearing in the original paper corrected).