scieee AI-readable full text Open interactive document viewer

On the cost of fixed partial match queries in K-d trees

Duch Brown, Amalia,Lau Laynes-Lozada, Gustavo Salvador,Martínez Parra, Conrado

Abstract

Partial match queries constitute the most basic type of associative queries in multidimensional data structures such as K-d trees or quadtrees. Given a query q=(q0,…,qK-1) where s of the coordinates are specified and K-s are left unspecified (qi=*), a partial match search returns the subset of data points x=(x0,…,xK-1) in the data structure that match the given query, that is, the data points such that xi=qi whenever qi¿*. There exists a wealth of results about the cost of partial match searches in many different multidimensional data structures, but most of these results deal with random queries. Only recently a few papers have begun to investigate the cost of partial match queries with a fixed query q. This paper represents a new contribution in this direction, giving a detailed asymptotic estimate of the expected cost Pn,q for a given fixed query q. From previous results on the cost of partial matches with a fixed query and the ones presented here, a deeper understanding is emerging, uncovering the following functional shape for Pn,q Pn,q=¿·(¿i:qi is specifiedqi(1-qi))a/2·na+l.o.t. (l.o.t. lower order terms, throughout this work) in many multidimensional data structures, which differ only in the exponent a and the constant ¿, both dependent on s and K, and, for some data structures, on the whole pattern of specified and unspecified coordinates in q as well. Although it is tempting to conjecture that this functional shape is “universal”, we have shown experimentally that it seems not to be true for a variant of K-d trees called squarish K-d trees.

Full text

On the Cost of Fixed Partial Match Queries in K-d Trees∗ Amalia Duch Gustavo Lau Conrado Mart´ınez† October 27, 2015 Abstract Partial match queries constitute the most basic type of associative queries in multidimensional data structures such as K-d trees or quadtrees. Given a query q= (q0, . . . , qK−1) where sof the coordinates are specified and K−sare left unspecified (qi=∗), a partial match search returns the subset of data points x= (x0, . . . , xK−1) in the data structure that match the given query, that is, the data points such that xi=qiwhenever qi6=∗. There exists a wealth of results about the cost of partial match searches in many different multidimensional data structures, but most of these results deal with random queries. Only recently a few papers have begun to investigate the cost of partial match queries with a fixed query q. This paper represents a new contribution in this direction, giving a detailed asymptotic estimate of the expected cost Pn,qfor a given fixed query q. From previous results on the cost of partial matches with a fixed query and the ones presented here, a deeper understanding is emerging, uncovering the following functional shape for Pn,q Pn,q=ν· Y i:qiis specified qi(1 −qi)  α/2 ·nα+ l.o.t.1 in many multidimensional data structures, which differ only in the exponent αand the constant ν, both dependent on sand K, and, for some data structures, on the whole pattern of specified and unspecified coordinates in qas well. Although it is tempting to conjecture that this functional shape is “universal”, we have shown experimentally that it seems not to be true for a variant of K-d trees called squarish K-d trees. ∗This work has been partially supported by funds from the Spanish Ministry for Economy and Competitiveness (MINECO), the European Union (FEDER funds) under grant COMMAS (ref. TIN2013-46181-C2-1-R), and the Catalan Agency for Management of Research and University Grants (AGAUR) grant SGR 2014:1034 (ALBCOM). †Department of Computer Science, Universitat Polit`ecnica de Catalunya. Jordi Girona, 1–3, E-08034, Barcelona, Spain. {duch,glau,conrado}@cs.upc.edu. 1Lower order terms, throughout this work. 1 Manuscript 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 1 Introduction Multidimensional data structures have numerous applications in a broad range of areas of Computer Science, like geographical information systems, computer graphics, video games, databases, and data mining just to name a few. Generalpurpose multidimensional data structures, such as K-dimensional trees (K-d trees, for short) [Ben75] or quadtrees [BF74], must support efficient updates (insertions and deletions) and exact searches, as any ordinary dictionary data structure, but they should also efficiently support associative queries:orthogonal range queries (which data points in the data structure have all their coordinates within the ranges specified by given lower and upper bounds along each dimension?), nearest neighbor queries (which data point in the data structure is closest —according to a fixed given distance measure— to a given query point?), and others. Among these, partial match (PM) queries constitute the most basic type of associative query: given a query q= (q0, . . . , qK−1) where only s, 0< s < K, out of the Kcoordinates are specified, find the K-dimensional data points xthat match q, that is, the data points x= (x0, . . . , xK−1) in the data structure such that xi=qiwhenever qiis specified. Besides their intrinsic interest, PM queries are a fundamental associative query since the performance of many other associative queries is closely related to the performance of PM searches [DM02, CDZC01]. There is a vast literature on the analysis of the performance of partial match search2in various multidimensional data structures, starting with the seminal paper by Flajolet and Puech [FP86] that gives the expected performance of a random PM search for several multidimensional data structures. As in [FP86], most of the existing literature only covers the performance of PM search when the query is random, that is, when the query is drawn at random with the same distribution as the data points, with K−sof its coordinates “marked” as unspecified. Here, as in the rest of the literature, the cost of partial match searches will be measured by the number of visited nodes of the tree. In particular, Flajolet and Puech proved the theorem below for random PM search in random standard K-d trees where scoordinates are specified and the pattern of specified and unspecified coordinates is u(e.g., u=SS∗indicates the first and second coordinates are specified, the third is not). Theorem 1 (Flajolet, Puech [FP86]).The expected cost Pn,uof a random PM search with query pattern u, where sout of the Kcoordinates of the query are specified and the other K−sare not, in a random standard K-d tree of size n is Pn,u=βunα(s/K)+l.o.t., where βuis a constant that depends on the pattern uand α(x)is the unique real solution in [0,1] of (α+ 2)x(α+ 1)1−x= 2. 2The algorithm to perform a partial match query is a partial match search; however, sometimes we will abuse the terminology and use the term partial match query when we should actually say partial match search. 2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 Similar results have been shown for other variants of K-d trees and other multidimensional data structures. For instance, for relaxed K-d trees (defined in Section 2) we have the following result. Theorem 2 (Duch et al. [DECM98], Mart´ınez et al. [MPP01]).The expected cost Pn,s,K of a random PM query where sout of the Kcoordinates of the query are specified and the other K−sare not, in a random relaxed K-d tree of size nis Pn,s,K =βs,Knα(s/K)+l.o.t., where α:= α(x) = 1 2√9−8x−1, and the constant βs,K =β(s/K)depends only on the ratio s/K, with β(x) = 1 1−x Γ(2α+ 1) (α+ 1)Γ(α+ 1)α2Γ2(α). In the case of squarish K-d trees (defined in next section) we have the following theorem. Theorem 3 (Devroye et al. [DJZC00]).The expected cost Pn,s,K of a random PM query where sout of the Kcoordinates of the query are specified and the other K−sare not, in a random squarish K-d tree of size nis Pn,s,K = Θ(nα(s/K)),with α(x)=1−x. Only recently a handful of papers have studied the performance of PM search with given fixed queries. In [CJ11, BNS13], the authors investigate the expectation, variance and limit distribution of PM search in 2-dimensional quadtrees; in [DJM14] the authors analyze the expected performance of PM search in standard and relaxed K-d trees when exactly s= 1 coordinate is specified. In the mentioned papers it is shown that E[Pn,q]∼νq·(qi·(1 −qi))α/2·nα+ l.o.t.,(1) where Pn,qis the cost of a PM search with fixed query q,qi∈(0,1) is the unique specified coordinate in q,α=α(1/K) is the same exponent as in the expected cost for random PM queries (the exponent is different for the different multidimensional data structures considered) and νqdepends only on Kand s (e.g., for relaxed trees), or on the pattern uof the query q(e.g., for standard K-d trees). When νq=νu(q)depends on the pattern, it also depends on sand K, but these quantities are implicit in the query pattern. The main contribution of the present paper is the generalization of the analysis for general sin standard and relaxed K-d trees. We will show in Theorems 4 (for relaxed K-d trees) and 7 (for standard K-d trees) in Sections 3 and 4, respectively, that the cost Pn,qof a PM search with fixed query qin a random 3 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 K-d tree of size n, satisfies E[Pn,q] = νq· Y i:qiis specified, qi∈(0,1) qi·(1 −qi)  α/2 ·nα+ l.o.t.,(2) where νqand α=α(s/K) are explicitly computable constants, depending on s and Kand on the multidimensional data structure under consideration. In the case of standard K-d trees the constant νqdepends also on the pattern u(that is, on the way in which specified and unspecified coordinates are distributed in q), whereas for relaxed K-d trees the pattern does not affect the value of νq. We will thus write the constant factor as νufor standard K-d trees and νs,K for relaxed K-d trees. The exponent αof nin (2) is the same (when all qi∈(0,1)) as in the expected cost of a random PM search, as given in Theorems 1 and 2 above. The paper is organized as follows: in Section 2 we review the different K- d tree variants that we will investigate, the partial match algorithm, and the probabilistic model for random K-d trees which we need for the subsequent analysis. Section 3 is devoted to the analysis of Pn,q=E[Pn,q], in particular, to prove Eq. (2) for random relaxed K-d trees (Theorem 4). In the course of this analysis, we will have to study the situation where several specified coordinates attain their extreme value (say qi= 0 or qi= 1); in particular we prove an intermediate result (Theorem 5) about the expected performance of random PM queries where several coordinates are extreme. The next section addresses the analysis of Pn,qin standard K-d trees (Theorem 7); we focus only on the aspects that are specific to standard K-d trees since most of the proofs are very similar to the corresponding ones for relaxed K-d trees. Section 5 covers the experimental study that we have performed to compare our theoretical findings with the experimental data. Given the asymptotic nature of our formulæ, the experiments help us to validate the theoretical results for moderate values of the input size. Although we have not obtained theoretical results for squarish K-d trees the experiments suggest that an analogous equation to (2) does not hold for this variant of K-d trees. We make a conjecture about the expected cost of PM search with fixed queries in squarish K-d trees which has some sound theoretical basis and is supported by the experimental data. Finally, Section 6 summarizes our findings and conclusions, and describes our lines of on-going and future work in this topic. This paper extends many of the preliminary results presented in [DLM14]. 2K-d trees & partial match queries Let Fbe a collection of nmultidimensional records, each one endowed with a K-dimensional key x= (x0, . . . , xK−1), with coordinate xidrawn from a totally ordered domain Di. It is generally assumed, without loss of generality, that no two keys in the collection have the same coordinates in any of the dimensions. For convenience, here we will also assume that, for all 0 ≤i<K,Di= [0,1]. 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 Initially proposed by Bentley [Ben75] a K-dimensional tree storing a collection Fof multidimensional records can be defined as follows. Definition 1 (Bentley [Ben75]).AK-dimensional tree (or K-d tree) Tof size n≥0is a binary tree such that •it is either empty when n= 0, or •its root stores a record with key xand a discriminant i,0≤i < K, and the remaining n−1records are stored in the left and right subtrees of T, say TLand TR, in such a way that both TLand TRare K-d trees, where for any key y∈TL, it holds that yi< xiand for any key y0∈TR, it holds that xi< y0 i. Any K-d tree of size ninduces a partition of the domain D=D0×···×DK−1 into n+ 1 regions, each corresponding to a leaf (or, equivalently an empty subtree) in the K-d tree. Let hx, iidenote a node that contains a key xwith discriminant i. The bounding box of hx, iiis the region of the space delimited by the leaf in which xfalls when it is initially inserted into the tree. Thus, if the root is hx, ii, its bounding box is [0,1]K, the bounding box of its left subtree is [0,1] × ··· × [0, xi)×···×[0,1], and so on. Different variants of K-d trees have been proposed so far; most only differ by the way in which discriminants are assigned to nodes (this is the case for the variants that we will consider here). In the original or standard K-d trees by Bentley [Ben75], the root of the tree (at level 0) gets discriminant 0, its subtrees in the first level get 1, . . . , those in the (K−1)-th level get K−1, those in the K-th level get 0, and so on, in a cyclic way. In general, nodes at level iof the trees discriminate by coordinate imod K. In Figure 1 we show a standard 2-d tree of five nodes together with the partition of the space that it induces. Duch et al. [DECM98] proposed relaxed K-d trees, where each node is assigned a random discriminant, uniformly and independently drawn from {0, . . . , K −1}. The squarish K-d trees of Devroye et al. [DJZC00] try to achieve a more balanced partition of the space by discriminating along the coordinate for which the bounding box of the node is most elongated. Because of their definitions, the insertion and exact search algorithms for K- d trees are straightforward, and we will not give the details here. Insertions work identically in the three variants, except in the way discriminants are assigned to new inserted nodes. The exact search algorithm is the same for all variants. In a partial match search we are given a query q= (q0, . . . , qK−1) with qi∈ Di∪{∗} = [0,1] ∪{∗}. Coordinates such that qi6=∗are called specified, otherwise they are called unspecified; we assume that the number sof specified coordinates satisfies 0 < s < K. Specified coordinates can be extreme (if qi= 0 or qi= 1), otherwise we call them regular. The goal of the PM search is to retrieve all records in the K-d tree that match the pattern q, that is, the records xsuch that xi=qiwhenever qi6=∗. In Figure 1 we show with a dashed line a PM query q= (∗, q1). 5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 Figure 1: A standard 2-d tree T, the partition that it induces and the PM query qsuch that u(q) = ∗Sand r(q, T)=(∗,3) The query pattern,u=u0u1··· uK−1, is such that ui=Sif qi6=∗and ui=∗if qi=∗; for queries with extreme specified coordinates, we write ui=S if the i-th coordinate is regular, and ui=Eif it is extreme. For the query in the example of Figure 1 we have u(q) = ∗S. To perform a PM search with query q, the K-d tree is recursively explored. First, we check whether the root matches qor not, to report it in the former case. Then, if the root discriminates with respect to an unspecified coordinate, we make recursive calls in both subtrees. Otherwise, if the root is hx, iiwe continue recursively in the appropriate subtree, depending on whether qi< xi or qi≥xi. The exact procedure is shown in Algorithm 1. The cost of a PM search with query qin a tree Tis measured as the number of nodes of the tree that are visited by Algorithm 1. We now turn our attention to the probabilistic model that we will use later, when analyzing the expected performance of the previous algorithm. Definition 2. AK-d tree Tof size nis random if and only if it is either empty (n= 0), or if its left and right subtrees, TLand TRare random K-d trees of sizes jand n−1−j, respectively, with P[size of TL=j|size of T=n] = 1 n, for any 0≤j < n. Another usual characterization of random K-d trees is that they are built by performing nrandom insertions into an initially empty tree. An insertion is said to be random if the (j+ 1)-th inserted data point xis equally likely to fall in any of the j+1 leaves of the K-d tree; this is what happens if the data points are independently drawn from a vector of continuous distributions in [0,1]K. 6 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 Algorithm 1 PartialMatch reports all records xin the K-d tree Tthat match q procedure PartialMatch(q,T) . T.discr is the discriminant associated to the root of T . T.key is the key associated to the root of T . T.left is the left subtree of T . T.right is the right subtree of T if T=then return x←T.key if x matches q then Report x i←T.discr if qi=∗then PartialMatch(q, T.left) PartialMatch(q, T.right) else if qi< xithen PartialMatch(q, T.left) else PartialMatch(q, T.right) It is worth remembering here that we will say that a PM query Qis random if all its specified coordinates are randomly generated by the same continuous distribution(s) as the coordinates of the keys in the random K-d tree. In other words, the query is random if it is independently generated from the same distribution as the data points, then some of the coordinates are marked “unspecified” as dictated by the query pattern. When all the specified coordinates have fixed values, we say that the query is fixed, i.e., qis a given element of QK−1 i=0 Di∪{∗}. We will systematically (we have already done that in the introduction) use P to denote the cost of a PM search, with subscripts for the main parameters: Pn,q=E[Pn,q] for the expected cost of a PM search with fixed query q, and Pn,•=E[Pn,Q] for the expected cost of a PM search with a random query Q, the •standing for the other relevant parameters, e.g., the query pattern u(Q), or the number of specified coordinates sand the dimension K. In this paper we will assume that each coordinate i, 0 ≤i<K, of each data point is independently drawn from a continuous distribution Fiin [0,1]. Therefore, a random PM query Qin a random K-d tree corresponds to an “unsuccessful” PM search, since the probability that Qmatches a key in the tree is zero. For the sake of simplicity, we can safely assume that F0=F1=··· = FK−1= Uniform(0,1). However, for the majority of our results this last assumption is not necessary; we will explicitly state those results where the assumption of uniformity cannot be avoided. 7 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 3 Fixed partial match queries in relaxed K-d trees 3.1 Queries and ranks One key observation about the PM algorithm in K-d trees (the same holds in other comparison-based multidimensional data structures, e.g., quadtrees) is that, except for eventual matches, only the relative ranks of the coordinates matter. To be more precise, let us call the rank vector of a query qthe vector r(q, T) = (r0, . . . , rK−1) defined as follows: if qi=∗then ri=∗; if qi6=∗then riis the number of records xin the collection (represented by the K-d tree T) such that xi≤qi. Notice that each specified riranges between 0 and n. We will also use the notation rk(q, T) to refer to the k-th component of r(q, T). For ease of notation, we will usually omit the K-d tree Tand simply write r(q) or rk(q), unless it is necessary to explicitly indicate which is the tree of reference. In the example of Fig. 1, the rank vector r(q, T) = r((∗, q1)) = (∗,3), since 3 data points have coordinate ysmaller that q1. Then, for any two given different queries qand q0with equal rank vectors r(q) = r(q0), the PM algorithm (Algorithm 1) will visit exactly the same set of nodes of the tree. It makes sense thus to consider the random variable Pn,r, the cost of a PM query in a random K-d tree of size nwhere the rank vector of the query is r. The results for Pn,r=E[Pn,r] can easily be translated to Pn,q=E[Pn,q], via conditioning as follows: Pn,q=X r P[r(q) = r]·Pn,r. If the coordinates of the records are independently drawn it follows that P[r(q) = r] = Y qj6=∗ P[rj(q) = rj]. If we assume that the coordinates are uniformly distributed —here the assumption is a must— then, for qj6=∗,rj(q) follows a binomial distribution Bin(n, qj). Because of the smooth behavior of Pn,r=E[Pn,r], and the binomial distribution being highly concentrated around its mean, one can prove that Pn,q=Pn,r+ l.o.t.,(3) with r=nq, i.e., rj=nqjif qj6=∗and rj=∗, otherwise. The technical details to finish the proof of (3) are discussed at the end of Subsection 3.6. Likewise, for a fixed rank vector r= (r0, . . . , rK−1), we have Pn,r=Pn,q+ l.o.t., with qi=ri/n if 0 ≤ri≤nand qi=∗if ri=∗. 8 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 3.2 Main result and outline of its proof Hereinafter we will concentrate on the analysis of Pn,rsince working with ranks conveniently allows a purely combinatorial approach. In this section we will consider the expected cost of a PM search in random relaxed K-d trees, as it turns out to be the multidimensional data structure that is easiest to analyze. The fundamental problems and main steps of the analysis already appear when considering relaxed K-d trees. In Section 4 we are able to extend the analysis to standard K-d trees. The ultimate goal of our analysis is to find the expected cost Pn,qof a PM search with a fixed query q, that is, to formally prove Equation (2) in the Introduction or, as we have discussed, to solve the essentially equivalent problem of finding the expected cost Pn,rof a PM search with a fixed rank vector r. It turns out that the distinction between the specified coordinates of a PM query as extreme (qi= 0 or qi= 1) or as regular (qi∈(0,1)) will be of utmost importance in what follows. In terms of rank vectors, a rank riwill be called extreme if either ri=o(n) or ri=n−o(n); it will be called regular otherwise. The number of extreme coordinates s0, 0 ≤s0≤s(or, equivalently, the number of regular coordinates t=s−s0) will play a fundamental role in the expected cost as we shall see. Namely, we will show that Pn,ris of order nα, where α=α(ρ, ρ0), with ρ=s/K and ρ0=s0/K. When ρ0= 0, α(ρ, 0) coincides with the exponent α(ρ) in the expected cost of a random PM query (see Section 1); indeed, the probability that one or more coordinates of a random query are extreme is 0. Let us now state the main theorem of this section: Theorem 4. For a query qwith rank vector r= (r0, . . . , rK−1)such that ri=zin+o(n),0< zi<1, for all i,0≤i < t,ri=o(n)or ri=n−o(n)for all i,t≤i<sand ri=∗for all i,s≤i<K, the expected cost of a partial match search in a random relaxed K-d tree of size nis Pn,r=νs,t,K · t−1 Y i=0 zi(1 −zi)!α/2 ·nα+o(nα), where ρ=s/K,ρ0=s0/K = (s−t)/K,α=α(ρ, ρ0)is given in Theorem 5 below and νs,t,K is: νs,t,K =β(ρ, ρ0)Γt(α+ 2) Γ2t(α/2 + 1). with βalso as given in Theorem 5: β=β(ρ, ρ0) = 1 (1 −ρ) Γ(2α+1+ρ0) (α+ 1)Γ(α+1+ρ0)α2Γ2(α). Moreover, if the ndata points are drawn from the uniform distribution in [0,1]K then the expected cost of a partial match q= (q0, . . . , qt−1, s0 z }| { 0. . . , 0, K−s z }| { ∗,...,∗) 9 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 can be rewritten as X s≤i<K n−1 X j=0 X r0∈L(i,j) rX δ∈{0,1}sY 0≤k<s P[∆k=δk]j r0 k n−1−j rk−δk−r0 k n−1 rk−δk(Pj,r0+Pn−1−j,r−r0−δ), where ∆is the indicator random vector for the event xk≤qk, and xis the data point at the root of the random K-d tree. The complete recurrence can be written in full by gathering all its different “pieces”: Pn,r= 1 + 1 nK "X 0≤i<s(n−1 X j=riX r0∈L(i,j) rY 0≤k<s,k6=ij r0 kn−1−j rk−r0 k n−1 rkPj,r0(7) + ri−1 X j=0 X r0∈R(i,j) rY 0≤k<s,k6=in−1−j r0 kj+1 rk−r0 k n rkPn−1−j,r0) +X s≤i<K n−1 X j=0 X r0∈L(i,j) r X δ∈{0,1}sY 0≤k<s h(δk)j r0 k n−1−j rk−δk−r0 k n−1 rk−δk(Pj,r0+Pn−1−j,r−r0−δ)#, with h(δk) = P[∆k=δk] = (rk n,if δk= 1, n−rk n,if δk= 0, or more concisely, h(δk)=(δkrk+ (1 −δk)(n−rk))/n. The recurrence looks daunting, and the chances of obtaining the asymptotic behavior of Pn,ras n→ ∞ with the standard machinery of Analytic Combinatorics seem extremely small, not to speak of solving the recurrence exactly. But after several simplifications we can obtain a recurrence which is much easier and can be solved using rather standard asymptotic techniques. 3.6 Proof of Theorem 4 Let us recall our strategy to prove Theorem 4. Once we have derived the recurrence that Pn,rsatisfies, our next step will be to assume that there is some γ > 0 such that limn→∞ n−γPn,r=f(z0, . . . , zt−1) exists and it is not zero, which will allow us to prove that we must have γ=α(ρ, ρ0), and to obtain an integral equation, plus a set of boundary/initial conditions, for which f(z0, . . . , zt−1) is a solution. That is, our assumption here—that limn→∞ n−γPn,rexists and it is not identically null—is just a useful “trick” to transform the original recurrence into the somewhat simpler integral equation (8). This will be formalized in Proposition 1 below. Then we will solve the integral equation and find the explicit form of f(z0, . . . , zt−1) which is given in 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 Proposition 2. The rest of this section is mainly devoted to prove that the fr0 n,...,rt−1 nnα+o(nα) is a solution of the recurrence satisfied by Pn,r. Last but not least, the asymptotic estimate for Pn,rtogether with the discussion in Subsection 3.1 allows us to prove the last part of Theorem 4, namely, the asymptotic estimate for Pn,q. Proposition 1. Let r= (r0, . . . , rK−1)be such that zi= limn→∞ ri/n ∈(0,1) for all i,0≤i<t,ri=o(n)or ri=n−o(n)for all i,t≤i<s, and ri=∗for all i,s≤i < K. Assume that 0< t ≤s < K, that is, the rank vector corresponds to a partial match query with at least one regular specified coordinate and at least an unspecified coordinate. If limn→∞ Pn,r nγexists for some γand it is non-null then γ=α(ρ, ρ0)(as given in Theorem 5) and f(z0, . . . , zt−1) = lim n→∞ Pn,r nγ is the solution of the integral equation f(z0, . . . , zt−1) = λ t−1 X i=0(zγ+1 iZ1 zi f(z0, . . . , zi−1, z, zi+1, . . . , zt−1)dz zγ+2 (8) + (1 −zi)γ+1 Zzi 0 f(z0, . . . , zi−1, z, zi+1, . . . , zt−1)dz (1 −z)γ+2 ), where λ= (α+ 2)/2tand the function fis subject to the following constraints: (a) The function fis symmetric with respect to any permutation of its arguments. (b) For any i,0≤i < t, and zi∈(0,1),f(z0, . . . , zi−1, zi, zi+1, . . . , zt−1) = f(z0, . . . , zi−1,1−zi, zi+1, . . . , zt−1). (c) For any i,0≤i<t, lim zi→0f(z0, . . . , zi−1, zi, zi+1, . . . , zt−1) = lim zi→1f(z0, . . . , zi−1, zi, zi+1, . . . , zt−1)=0. (d) Z1 0···Z1 0 f(y0, . . . , yt−1)dy0···dyt−1=β(ρ, ρ0). For the proof of the proposition above, we have to go through several approximations of recurrence (7); then plugging the assumption Pn,r/nγ= 17 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 f(z0, . . . , zt−1)+o(1) and passing to the limit yields the integral equation (8) for fgiven in the proposition. The constraints (boundary conditions) that fmust satisfy easily follow from the symmetry properties of Pn,r. Constraint (d) and γ=α(ρ, ρ0) are consequences of (6). In fact, we must have γ=α(ρ, ρ0), for otherwise we would have a contradiction with our hypothesis: either we would have that limn→∞ Pn,r/nγ= 0 or that limit does not exist (the limit would be ∞). To establish the constraints in (c) we use induction on t, for fixed s; the crucial point here is that α(ρ, ρ0)> α(ρ, ρ0 0) if ρ0< ρ0 0. More details of the proof can be found in Appendix A. We move next to the second proposition here, giving us the explicit form of the solution to the integral equation (8). Proposition 2. Let f(z0, . . . , zt−1) = νs,t,K · t−1 Y i=0 zi(1 −zi)!α/2 where ρ=s/K,ρ0=s0/K = (s−t)/K,α=α(ρ, ρ0)is given in Theorem 5 and νs,t,K is νs,t,K =β(ρ, ρ0)Γt(α+ 2) Γ2t(α/2 + 1). with β=β(ρ, ρ0) = 1 (1 −ρ) Γ(2α+1+ρ0) (α+ 1)Γ(α+1+ρ0)α2Γ2(α). Then fis a solution of (8) satisfying all the constraints stated in Proposition 1. In order to solve the integral equation, we can take successive partial derivatives to obtain a PDE for f. However, because of the symmetries of fon all its arguments, we can assume that f(z0, . . . , zt−1) = φ0(z0)···φt−1(zt−1) for some φ0, . . . , φt−1. Moreover, we can safely assume that φ0=··· =φt−1= φ. So we end up with an ODE for φand a set of constraints on φ(e.g., φ(z) = φ(1 −z) for all z∈(0,1)) for which the unique solution can be found quite easily. The complete details of the proof are given in Appendix B. To complete the proof of Theorem 4 we carefully compute the errors in passing from recurrence (7) to the integral equation (8). Having the explicit form for f(z0, . . . , zt−1) is crucial here. The details are given in Appendix C, showing that the error is O(∆2/n) + O(1/n) with ∆ = o(√n), that is, the error is o(1). The de Moivre-Laplace method that we mentioned above plays also an important role in these computations. Let us now write recurrence (7) in a more compact form: Pn,r= 1 + 1 nK K−1 X i=0 n−1 X j=0 X r0 ω(i,j) n(r,r0)·Pj,r0, 18 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 where the weights ω(i,j) n(r,r0) denote the average number of recursive calls on a subtree of size jwith rank vector r0when the call is made on a (sub)tree of size n, the rank vector is rand the root discriminates with respect to coordinate i. To simplify, for the rest of the section we will assume that the query has no extreme coordinates, that is, ρ0= 0 (the arguments below can be easily adapted to the case ρ0>0, however the details are slightly messier). It is not difficult to show that if we set P0 n,r=Pn,r−1 1−ρ, then P0 n,rsatisfies the homogeneous recurrence P0 n,r=1 nK K−1 X i=0 n−1 X j=0 X r0 ω(i,j) n(r,r0)·P0 j,r0,(9) and P0 0,r=−1/(1 −ρ), since P0,r= 0. The same can be done for any other toll function τn,rin the recurrence, as long as τn,r=o(nα). That is, if Un,r=τn,r+1 nK K−1 X i=0 n−1 X j=0 X r0 ω(i,j) n(r,r0)·Uj,r0, then we can write Un,r=U[hom] n,r+Vn,r, with U[hom] n,rsatisfying the homogeneous recurrence (9) and Vn,r=O(τn,r) = o(nα). The initial conditions that U[hom] n,r satisfies are of course different from the initial conditions of Un,r. The computations (most of them given in Appendices A and B) that lead to the closed form for factually show that f[hom](z0, . . . , zt−1) = c· t−1 Y i=0 zi(1 −zi)!α/2 , with can arbitrary constant, and zi=ri/n, give us the general solution of the homogeneous recurrence, subject only to the constraints (a), (b) and (c) given in Proposition 1 since these stem from the symmetries in the weights ω(i,j) nof the recurrence (see the discussion in Appendix A). In this sense, the only “arbitrary” initial condition is the one in constraint (d) since it is directly related to the initial values of U[hom] n,r. The computations in Appendix C show that Un,r=f[hom](r/n)·nα+o(nα) is a solution of the homogeneous recurrence (9), satisfying only the structural constraints (a)–(c) of Proposition 1. To establish that, we only need the closed form for fand the computations given in Appendix C: we do not need to hypothesize the existence of the limit f= limn→∞ Pn,r/nγ; the hypothesis is a useful guess to arrive at the closed form for f. Finally, taking into account constraint (d) gives us the value of cand shows that Pn,r=f(r/n)·nα+o(nα). We have already discussed at the end of Subsection 3.1 the connection between Pn,qand Pn,r. Since Pn,r=f(r0/n, . . . , rt−1/n)·nα+o(nα), where fis 19 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 given in Proposition 2, when the coordinates of the ndata points are independent and uniformly distributed we write Pn,q=X r (f(r0/n, . . . , rt−1/n)nα(1 + o(1)) t−1 Y i=0 n riqri i(1 −qi)n−ri =nανs,t,K t−1 Y i=0 X 0≤r≤nn rqr i(1 −qi)n−rr n1−r nα/2+o(nα). Now, the main contribution in each summation of the form X 0≤r≤nn rqr i(1 −qi)n−rr n1−r nα/2 comes from a neighborhood of size ∆ of r=nqi. With ∆ = o(n2/3) we can apply the de Moivre-Laplace limit theorem [Fel71] to show that the contributions of the ranges r < r −∆ and r > r + ∆ are negligible and to compute the contribution from the middle range r−∆≤r≤r+ ∆. Finally, we can expand r n(1 −r n) as r n(1 −r n) + O(∆/n) proving thus X 0≤r≤nn rqr i(1 −qi)n−rr n1−r nα/2=r n1−r nα/2 (1 + O(∆2/n)) = (qi(1 −qi))α/2(1 + o(1)). The asymptotic estimate for Pn,qgiven in the last part of Theorem 4 follows Pn,q=νs,t,K · t−1 Y i=0 qi(1 −qi)!α/2 ·nα+o(nα). 4 Fixed partial match queries in standard K-d trees The analysis of the expected cost of a PM search with a fixed query in random standard K-d trees goes along the same lines as the analysis for relaxed K-d trees in the previous section. The major differences stem from the fact that now the query pattern is relevant for the performance of PM searches. As in Section 3, we will need an intermediate result about the expected cost of random PM queries with tregular coordinates, s0extreme coordinates and K−s=K−(t+s0) unspecified coordinates. The constant factor in the leading term of Pndepends on the query pattern u(q) and thus we shall write Pn,ufor the expected cost of a random PM query with pattern uin a random standard K-d tree of size n. 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 Theorem 6. Let Pn,u=E[P,u,Q]be the expected cost of a PM search in a random standard K-d tree of size nwith a random query Qwith pattern u=u(Q), in which scoordinates are specified and the remaining K−scoordinates are left unspecified. Of the sspecified coordinates exactly tcoordinates are independently drawn at random from the same continuous distribution(s) from which data coordinates are drawn, and exactly s0=s−tcoordinates are extreme (we assume, w.l.o.g., that they are 0). Then Pn,u=βunα(ρ,ρ0)+o(nα(ρ,ρ0)), where the exponent α(ρ, ρ0)is the unique positive real root in (0,1) of the equation α(ρ, ρ0)+2ρ−ρ0α(ρ, ρ0)+11−ρ+ρ0 = 21−ρ0,(10) and the βu’s are constants that depend on the query pattern u(and implicitly on s,s0and K). Proof. Given the fixed rule to assign discriminants to nodes in standard K-d trees we need to introduce some notation. We will abbreviate (i+ 1) mod Kas i⊕1. Let u(i)be the pattern ushifted to the left itimes; in particular we have u(K)=u(0) =u. Let P(i) n,ube the expected cost of a PM query with pattern u in a random standard K-d tree of size nwhen the root discriminates w.r.t. the i-th coordinate; of course, we are interested in P(0) n,u=Pn,u. Let P(i) u(z) = Pn≥0P(i) n,uznbe the generating function for the expected costs P(i) n,u, 0 ≤i < K. If ui=∗the search has to continue in both subtrees, if ui=Ethe search has to continue in only one subtree (w.l.o.g. we can assume that it is in the left subtree), and if ui=Sthe search continues on the left subtree with probability (j+ 1)/(n+ 1) and on the right subtree with probability (n−j)/(n+ 1). This gives us a system of differential equations for the vector hP(0) u(z), . . . , P(K−1) u(z)iwhich can be analyzed using the same techniques as in [FP86] or [CLF89], for instance; the only difference in setting up such a system comes from the extreme coordinates, that is, whenever ui=E. The singularity analysis of this system yields that P(i) u(z)∼ηu(1 −z)−(α+1),0≤i < K, around the singularity z= 1, where α=α(ρ, ρ0) is the unique solution in (0,1) of α(ρ, ρ0)+2ρ−ρ0α(ρ, ρ0)+11−ρ+ρ0 = 21−ρ0. The rest of the proof easily follows from standard singularity analysis techniques [FO90, FS09] with βu=ηu/Γ(α+ 1). It is not too difficult to prove that α(ρ, ρ0), with 0 ≤ρ0≤ρ < 1 is strictly decreasing as ρ0increases (for a fixed ρ) and it is also decreasing if ρincreases, 21 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 just as in the case of relaxed K-d trees (there, the proof of these facts is straightforward, as a simple closed form for α(ρ, ρ0) is available). In particular, α(0,0) = 1, α(ρ, ρ) = 21−ρ−1 and limρ→1α(ρ, g(ρ)) = 0 for any function gsuch that g(x)≤x. Furthermore, α(ρ, ρ0)≥21−ρ−1 for any ρ and ρ0≤ρ. Since the query pattern is relevant, we can no longer assume that the query qor its rank vector rhave particularly convenient forms; instead, we will need to introduce `kfor the index of the k-th specified regular coordinate. Thus q`k∈(0,1) for 0 ≤k < t; all other positions correspond to specified extreme coordinates or unspecified coordinates. We can now state the main result of this section. Theorem 7. For a query qwith rank vector r= (r0, . . . , rK−1)such that r`k=z`kn+o(n),0< z`k<1, for all k,0≤k < t,ri=o(n)or ri=n−o(n) for exactly s0coordinates and ri=∗for the remaining K−scoordinates, the expected cost of the partial match in a random standard K-d tree of size nis Pn,r=νu(r)· t−1 Y k=0 z`k(1 −z`k)!α/2 ·nα+o(nα), where the exponent α(ρ, ρ0)is the same as in Equation (10) of Theorem 6, and νu=βu Γt(α+ 2) Γ2t(α 2+ 1), with βuthe constant factor in the leading term of Pn,u(see Theorem 6). Let P(i) n,rdenote the expected cost of a PM search for a fixed query with rank vector rin a random standard K-d tree of size nwhere the root discriminates with respect to coordinate i, 0 ≤i<K. As before the quantity of interest will be Pn,r:= P(0) n,r. Reasoning as in Subsection 3.5 and using the same notation as we have used there (e.g., h(δk), L(i,j) r, . . . ), we can set up a system of recurrences3: P(i) n,r= 1 + 1 n"n−1 X j=riX r0∈L(i,j) rY 0≤k<s `k6=i j r0 `kn−1−j r`k−r0 `k n−1 r`kP(i⊕1) j,r0 + ri−1 X j=0 X r0∈R(i,j) rY 0≤k<s `k6=i n−1−j r0 `k j+1 r`k−r0 `k n r`kP(i⊕1) n−1−j,r0#,if ui(r)6=∗, 3For brevity, we do not make the distinction between regular and extreme coordinates; `0, ..., `s−1give the indices of specified coordinates. 22 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 and P(i) n,r= 1 + 1 n n−1 X j=0 X r0∈L(i,j) rX δ∈{0,1,∗}KY 0≤k<s h(δ`k)j r0 `k n−1−j r`k−δk−r0 `k n−1 r`k−δk ×P(i⊕1) j,r0+P(i⊕1) n−1−j,r−r0−δ,if ui(r) = ∗. Using the same techniques as in the previous section and Appendix A we can show that if the limits f(i) u(z`0, . . . , z`t−1) = lim n→∞ P(i) n,r nγ exist and are not identically null, with z`k= limn→∞ r`k/n, 0 < z`k<1, and u=u(r), then we get4 f(i)(z`0, . . . , z`t−1) =            2 γ+1 f(i⊕1)(z`0, . . . , z`t−1),if ui=∗, 1 γ+1 f(i⊕1)(z`0, . . . , z`t−1),if ui=E, zγ+1 iR1 zif(i⊕1) (. . . , z, . . .)dz zγ+2 +(1 −zi)γ+1 Rzi 0f(i⊕1) (...,z,...)dz (1−z)γ+2 ,if ui=S. The constraints that this system of integral equations must satisfy are analogous to those in the case of relaxed K-d trees. In particular, we must have γ=α(ρ, ρ0), and (a) For any k, 0 ≤k < t, and z`k∈(0,1), f(...,z`k, . . .) = f(. . . , 1−z`k, . . .). (b) For any k, 0 ≤k < t, lim z`k→0f(z`0, . . . , z`k, . . . , z`t−1) = lim z`k→1f(z`0, . . . , z`k, . . . , z`t−1)=0. (c) Z1 0···Z1 0 fu(y0, . . . , yt−1)dy0···dyt−1=βu. To solve the system of integral equations and to complete the proof of Theorem 7 we can proceed along similar steps to those in Appendices B and C. 5 Experiments Our analysis of the expected cost of PM search for fixed queries is only asymptotic and provides the leading order term. We have conducted several experiments in order to investigate for which input sizes we can expect to get relatively 4From now on, we shall omit the subscript uof fto simplify notation. 23 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 good predictions from the theoretical analysis. As we will see, the main conclusion of our experiments is that, despite the asymptotic nature of our theoretical results, they do quite a reasonable job at predicting the cost of PM queries, even for inputs of moderate size, e.g., n≈5000. Each run of our experiments can be described by a tuple hT ,q, n, Miwhere Tis a type of K-d trees (standard, relaxed or squarish), qis the query, nis the size of the trees in the sample and Mis the size of the sample. For each run we generate Mrandom K-d trees of type Tand size n. In each tree we perform a PM search with query q, counting the total number of visited nodes and taking the corresponding sample mean pn,q:= 1/M PM i=1 P(i) n,q, where the P(i) n,qare independent identical realizations of Pn,q. Most of the plots that follow depict the normalized mean cost cn,q:= pn,q/nα, with αthe appropriate exponent for each case—that is, depending on Tand the ratios ρ0and ρthat correspond to q. For comparison, we depict also the theoretical value f(q0, . . . , qt−1)∼ Pn,q/nα. In all of these plots one of the most conspicuous features is the domelike symmetrical shape of the PM search cost along every specified coordinate. Let us start by reporting results for random relaxed 3-d trees. Figure 2 shows the behavior of the normalized mean cost cn,qfor queries with two specified coordinates, xand y; the plot shows the variation of the experimentally measured cost w.r.t. y, as xtakes several distinct values (x= 0,0.1,0.25,0.5). For x6= 0 we have normalized dividing by nα(2/3,0) =n0.457..., whereas for x= 0 we have normalized dividing by nα(2/3,1/3) =n0.387.... For each value of xwe also plot the theoretical prediction f(x, y) (smooth curves). A simple visual inspection of the plots reveals that the experimental data (ragged curves) match the predicted costs quite well. Because of the normalization the curves for x= 0 lie somewhere between those for x= 0.25 and x= 0.5; however, the reader must recall that different normalizations have been used to plot these curves and the mean cost pn,qwhen x= 0 is actually significantly smaller than the mean cost when xis sufficiently away from 0. Figure 3 plots the relative error in the previous experiment, that is, n,q=qs2 n,q pn,q , where s2 n,qis the sample variance. A plausible explanation for the high relative errors that we get in the experiments is that V[Pn,q] is likely of order n2α (that has been proven true for 2-d quadtrees [BNS13]) and hence there is no concentration around the expectation. More specifically, as we will later discuss, we conjecture that V[Pn,q] = ν(2) s,t,K · t−1 Y i=0 qi(1 −qi)!α/2 ·n2α+ l.o.t. for some constant ν(2) t,s,K and thus n,q≈√ν(2)/ν. The experiments give credibility to this hypothesis; moreover, when x= 0, the constant νchanges (and 24 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 Figure 2: Normalized expected costs (experimental vs. theoretical) for different fixed PM queries in relaxed 3-d trees likely ν(2) does too); from the experiment it seems that their ratio would be larger than the ratio qν(2) s,s,K/νs,s,K. Figure 4 shows how the experimental results get closer to the theoretical predicted expected cost for increasing values of n. As we already have mentioned for moderate input sizes such as n= 5000, the experimental mean costs are already quite close to the theoretical expectation (which is approximated by its leading order term). The queries used in this experiment are of the form q= (0.25, y, ∗). Figures 5 and 6 are similar to Figures 2 and 3, but for standard 3-d trees. In contrast with relaxed K-d trees, the pattern of regular, extreme and unspecified coordinates in the query is relevant. In Figure 5 we try to capture that dependency by considering three different queries which differ in their pattern: q= (0.25, y, ∗), q= (0.25,∗, y) and q= (∗,0.25, y). In all three runs the normalizing factor of the mean costs is n−α(2/3,1/3) =n−0.3146.... We can appreciate again that we obtain qualitatively similar behavior of the average costs as the one for relaxed K-d trees, just as our theoretical results predict. In this case it is important to remark that both the average cost and the variance are smaller than the ones for relaxed K-d trees (the exponent α(2/3,0) = 0.395 . . . for standard 3-d trees, whereas α(2/3,0) = 0.457 . . . for relaxed 3-d trees). Furthermore, the constant coefficient νin Pn,qdepends on the pattern u(q) (because νdepends on β), a dependency that is well reflected in the experi- 25 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 [DECM98] A. Duch, V. Estivill-Castro, and C. Mart´ınez. Randomized kdimensional binary search trees. In K.-Y. Chwa and O.H. Ibarra, editors, Proceedings of the 9th International Symposium on Algorithms and Computation (ISAAC), volume 1533 of Lecture Notes in Computer Science, pages 199–208. Springer-Verlag, 1998. [DJM14] A. Duch, R. M. Jim´enez, and C. Mart´ınez. Selection by rank in kdimensional binary search trees. Random Structures & Algorithms, 45(1):14–37, 2014. [DJZC00] L. Devroye, J. Jabbour, and C. Zamora-Cura. Squarish k-d trees. SIAM Journal on Computing, 30(5):1678–1700, 2000. [DLM14] A. Duch, G. Lau, and C. Mart´ınez. On the average performance of fixed partial match queries in random relaxed k-d trees. In M. Bousquet-M´elou and M. Soria, editors, Proceedings of the 25rd International Meeting on Probabilistic, Combinatorial and Asymptotic Methods for the Analysis of Algorithms (AofA), Discrete Mathematics & Theoretical Computer Science (Proceedings), pages 103– 114, 2014. [DM02] A. Duch and C. Mart´ınez. On the average performance of orthogonal range search in multidimensional data structures. Journal of Algorithms, 44(1):226–245, 2002. [Fel71] W. Feller. An Introduction to Probability Theory and its Applications. John Wiley & Sons, New York, NY, 1971. [FO90] Ph. Flajolet and A. Odlyzko. Singularity analysis of generating functions. SIAM Journal on Discrete Mathematics, 3(1):216–240, 1990. [FP86] Ph. Flajolet and C. Puech. Partial match retrieval of multidimensional data. Journal of the ACM, 33(2):371–407, 1986. [FS09] Ph. Flajolet and R. Sedgewick. Analytic Combinatorics. Cambridge University Press, 2009. [JKK92] N. L. Johnson, S. Kotz, and A.W. Kemp. Univariate Discrete Distributions. John Wiley & Sons, New York, NY, 2nd edition, 1992. [MPP01] C. Mart´ınez, A. Panholzer, and H. Prodinger. Partial match queries in relaxed multidimensional search trees. Algorithmica, 29(1–2):181– 204, 2001. 32 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 A Getting the integral equation (8) The hypothesis of Proposition 1 is that there exists some γsuch that lim n→∞ n−γPn,r=f(z0, . . . , zt−1) exists and is not identically null, with zi= limn→∞ ri/n ∈(0,1), 0 ≤i<t. We shall also assume here that all ri≤n/2, for otherwise we can replace riby n−ri. First of all, in the asymptotic regime, when ri=o(n) , the probability that we recursively continue the PM search in the right subtree is o(1), so we can assume all extremal ranks are ri= 0 (t≤i < s), and thus we can rewrite the recurrence as Pn,r∼1 + 1 nK "X 0≤i<tn−1 X j=riX r0∈L(i,j) r π(i,j) L(r,r0)Pj,r0 + ri−1 X j=0 X r0∈R(i,j) r π(i,j) R(r,r0)Pn−1−j,r0 +X t≤i<s n−1 X j=0 X r0∈L(i,j) r π(i,j) L(r,r0)Pj,r0 +X s≤i<K n−1 X j=0 X hr0,r00 i∈B(i,j) r π(i,j) B(r,r0,r00) (Pj,r0+Pn−1−j,r00 )#. A second simplification comes from the realization that π(i,j) L(r,r0), π(i,j) R(r,r0) are highly concentrated around the expected value of r0; in particular, X r0∈L(i,j) r π(i,j) L(r,r0)Pj,r0∼Pj,←− r where ←− ri=riand ←− rk=j nrkfor k6=i. Similarly, X r0∈R(i,j) r π(i,j) R(r,r0)Pn−1−j,r0∼Pn−1−j,−→ r, where −→ ri=ri−j−1 and −→ rk=n−1−j nrkfor k6=i. Last but not least, X r0∈L(i,j) rX δ∈{0,1}sY 0≤k<s h(δk)j r0 k n−1−j rk−δk−r0 k n−1 rk−δk(Pj,r0+Pn−1−j,r−r0−δ) ∼Pj,←→ r+Pn−1−j,r−←→ r, 33 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 where ←→ rk=j nrk, 0 ≤k < s. Setting Cn,r:= 0 if n= 0, and Cn,r:= n−γPn,rif n > 0, Cn,r∼1 nγ+1 nK "X 0≤i<t n−1 X j=ri Cj,←− r·j nγ + ri−1 X j=0 Cn−1−j,−→ r·n−1−j nγ!# (13) +s0 nK · n−1 X j=0 Cj,←− r·j nγ +(K−s) nK · n−1 X j=0 Cj,←→ r·j nγ +Cn−1−j,r−←→ r·n−1−j nγ. Notice that when t≤i<s, we assume ri= 0 and thus ←− ri= 0 as well. Now, since t > 0, lim n→∞ Pn,r nγ=f(z0, . . . , zt−1) exists and it is not identically null, by hypothesis. If we substitute Cn,rby fr0 n,...,rt−1 nthen fr0 n,...,rt−1 n∼1 nγ +1 nK "X 0≤i<t n−1 X j=ri fr0 n,...,ri j,...,rt−1 n·j nγ + ri−1 X j=0 fr0 n,...,ri−j−1 n−1−j,...,rt−1 n·n−1−j nγ!# +s0 nK · n−1 X j=0 fr0 n,...,rt−1 n·j nγ +(K−s) nK · n−1 X j=0 fr0 n,...,rt−1 n·j nγ +fr0 n,...,rt−1 n·n−1−j nγ!. Passing to the limit when n→ ∞, with zi= limn→∞(ri/n), we replace sums 34 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 by integrals and thus f(z0, . . . , zt−1) = 1 K"X 0≤i<tZ1 zi fz0,...,zi z, . . . , zt−1·zγdz +Zzi 0 fz0,...,zi−z 1−z, . . . , zt−1·(1 −z)γdz +s0·Z1 0 f(z0, . . . , zt−1)·zγdz + (K−s)·Z1 0f(z0, . . . , zt−1)·zγ +f(z0, . . . , zt−1)·(1 −z)γdz#, which can be further manipulated to give f(z0, . . . , zt−1) = 1 K"X 0≤i<tZ1 zi fz0,...,zi z, . . . , zt−1·zγdz +Zzi 0 fz0,...,zi−z 1−z, . . . , zt−1·(1 −z)γdz +s0·f(z0, . . . , zt−1)·1 γ+ 1 + (K−s)·f(z0, . . . , zt−1)·2 γ+ 1#. Hence f(z0, . . . , zt−1) = λ"X 0≤i<tZ1 zi fz0,...,zi z, . . . , zt−1·zγdz +Zzi 0 fz0,...,zi−z 1−z, . . . , zt−1·(1 −z)γdz#, with λ=1 K 1 1−2(K−s)+s0 K(γ+1) . Furthermore, f(z0, . . . , zt−1) = λ t−1 X i=0(zγ+1 iZ1 zi f(z0, . . . , zi−1, z, zi+1, . . . , zt−1)dz zγ+2 + (1 −zi)γ+1 Zzi 0 f(z0, . . . , zi−1, z, zi+1, . . . , zt−1)dz (1 −z)γ+2 ). 35 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 with the substitution z:= zi/z in the first integral and z:= (zi−z)/(1 −z) in the second. Besides the integral equation (8), the properties of Pn,rtranslate into several constraints that f(z0, . . . , zt−1) must satisfy: (a) The function fis symmetric with respect to any permutation of its arguments. (b) For any i, 0 ≤i < t, and zi∈(0,1), f(z0, . . . , zi−1, zi, zi+1, . . . , zt−1) = f(z0, . . . , zi−1,1−zi, zi+1, . . . , zt−1). (c) For any i, 0 ≤i<t, lim zi→0f(z0, . . . , zi−1, zi, zi+1, . . . , zt−1) = lim zi→1f(z0, . . . , zi−1, zi, zi+1, . . . , zt−1)=0. (d) Z1 0···Z1 0 f(y0, . . . , yt−1)dy0···dyt−1=β(ρ, ρ0). Constraint (d) follows because of (6). In fact, we must have γ=α(ρ, ρ0), for otherwise we would have a contradiction with our hypothesis: either we have that limn→∞ Pn,r/nγ= 0 or that limit does not exist (→ ∞). Also, because γ=α(ρ, ρ0) =: αwe must have, λ=α+ 2 2t, since 1−2(K−s) + s0 K(γ+ 1) =2t K(α+ 2). Constraint (c) follows from inductive reasoning. Suppose that for any rank vector r0with s0+ 1 extreme values we have Pn,r0= Θ nα(ρ,ρ0+1/K). Since setting zi= 0 or zi= 1 corresponds to one more extreme rank, dividing Pn,rby n−α(ρ,ρ0)yields that fis 0, because α(ρ, ρ0+1/K)< α(ρ, ρ0). To prove the basis of this induction, we must analyze the case when all the specified coordinates of a query are extreme. The recurrence for Pn,rin this case (s0=s) is greatly simplified. Indeed, for such queries we have Pn,r= 1 + s nK n−1 X j=0 Pj,r+K−s nK n−1 X j=0 (Pj,r+Pn−1−j,r) as the query (actually, its rank vector) does not change as we proceed recursively with the PM search; moreover, whenever the discriminant at the root is one of the specified extreme coordinates we will systematically continue in the left subtree. The solution of the recurrence above is straightforward: Pn,r= Θ(n1−ρ0), 36 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 that is, Pn,r= Θ nα(ρ0,ρ0), as we wanted to show. It is also interesting to note that constraint (c) can also be proved as a consequence of the symmetries (a) and (b), and the symmetries of the weights of the recurrence lead to constraints (a) and (b). B Solving the integral equation (8) In order to solve the integral equation (8) given in Proposition 1, together with constraints (a)–(d) we transform it into an equivalent partial differential equation (PDE). For any function f(z0, z1, . . . , zt−1) let Li[f] := zα+1 iZ1 zi f(z0, . . . , zi−1, z, zi+1, . . . , zt−1)dz zα+2 , and, similarly let Ri[f] := (1 −zi)α+1 Zzi 0 f(z0, . . . , zi−1, z, zi+1, . . . , zt−1)dz (1 −z)α+2 . If we set T:= λPt−1 i=0(Li+Ri) where λ=α+2 2tthen the function fwe are looking for is a non-trivial solution to the fix-point equation f=T[f] with the constraints (a)–(d). Let us now assume that the solution to the integral equation is a function in separable variables, namely f(z0, z1, . . . , zt−1) = φ0(z0)·φ1(z1)···φt−1(zt−1). Because of the symmetry of f(constraint (a)), it follows that we can safely assume φ0=φ1=··· =φt−1=: φ. Furthermore, because of constraint (b), we must have φ(z) = φ(1−z) for any z∈(0,1). We must also have limz→0φ(z)=0 to satisfy constraint (c). Going back to the integral equation, if we denote φi:= φ(zi) we must have φ0·φ1···φt−1=λ t−1 X i=0 φ0···φi−1·φi+1 ···φt−1Li[φi] + Ri[φi]. If, for all i, 0 ≤i<t, φi=tλLi[φi] + Ri[φi],(14) then λ t−1 X i=0 φ0···φi−1·φi+1 ···φt−1·Li[φi]+Ri[φi]=λ t−1 X i=0 φ0···φt−1 tλ =φ0···φt−1. The solution of (14), namely, the solution of φ(z) = tλ zα+1 Z1 z φ(u)du uα+2 + (1 −z)α+1 Zz 0 φ(u)du (1 −u)α+2  37 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 can be obtained by solving the equivalent ordinary differential equation that we obtain applying the operator Φi[g(zi)] := zi(1 −zi)d2g dz2 i +α(2zi−1) dg dzi−α(α+ 1)g(zi), to both sides. The linear operator Φ allows us to remove the integrals in Liand Ri: Φi[Li[g]] = (zi−1) dg dzi−αg Φi[Ri[g]] = zi dg dzi−αg Φi[(Li+Ri)[g]] = (2zi−1) dg dzi−2αg. In particular, we obtain the following ODE for φ(z), after rearranging: z(1 −z)φ00(z) + α(2z−1)φ0(z)−α(α+ 1)φ(z) = tλ(2z−1)φ0(z)−2αφ(z), or more conveniently, z(1 −z)φ00(z)+(α−tλ)(2z−1)φ0(z)−α(α+ 1 −2tλ)φ(z) = 0, with the initial condition φ(0) = 0. Again we have a second order linear hypergeometric ODE, and without too much effort, as in [DJM14], we can obtain the solution φ(z) = µ(z(1 −z))α/2, for some constant µand α=α(ρ, ρ0). We have thus f(z0, . . . , zt−1) = νs,t,K t−1 Y i=0 zi(1 −zi)!α/2 , with νs,t,K := µt. This family of solutions (parameterized by the “arbitrary” νs,t,K) obviously satisfies constraints (a), (b) and (c). Constraint (d) yields the sought function, as we impose νs,t,K Γ2t(α/2 + 1) Γt(α+ 2) =β(ρ, ρ0). C Bounding the errors Once we have an explicit form for f(z) := f(z0, . . . , zt−1), we can compute error bounds for the successive approximations that led us from the recurrence in (7) to the integral equation (8). Our knowledge of the function f(z0, . . . , zt−1) and its derivatives in (0,1) is the key to find these bounds. First, we can use the trapezoid rule or the Euler-Maclaurin summation formula to bound the error in 38 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 passing from sums to integrals; for instance 1 n n−1 X j=ri fr0 n,...,ri j,...,rt−1 nj nγ = 1 nZn ri fr0 n,...,ri u,...,rt−1 nu nγdu −1 2nfr0 n,...,ri n,...,rt−1 n+O(n−2), and similarly for the other integrals. Now, if we compare recurrence (7) for Pn,rto the recurrence (13) for Cn,r, apart from the normalizing factor nγ, the difference comes from the splitting probabilities π(i,j) L(r,r0), π(i,j) R(r,r0) and π(i,j) B(r,r0,r00), which we argued are highly concentrated around their respective means. Here, Laplace’s method for summations can be used to bound the error in that step. For instance, take X r0∈L(i,j) r π(i,j) L(r,r0)fr0 0 j,...,ri j,...,r0 t−1 j =νs,t,K X r0∈L(i,j) r φri j·   Y 0≤k<t k6=i j r0 kn−j rk−r0 k n rkφr0 k j   , for some jsuch that j/n →c, for some constant 0 < c < 1. Now, the right-hand side above can be re-written as φri jY 0≤k<t k6=iX 0≤r0 k≤rkj r0 kn−j rk−r0 k n rkφr0 k j and we can deal with each factor separately (here, the fact that f(z0, . . . , zt−1) = φ(z0)···φ(zt−1) greatly simplifies the proof). With our assumption that rk/n → zkfor some 0 < zk<1, we need just to show that X 0≤r0 k≤rkj r0 kn−j rk−r0 k n rkφr0 k j∼φrk n The splitting probabilities are given by products of the hypergeometric distribution (owing to the independence with which coordinates of each data point are drawn) π(i,j) L(k) = j r0 kn−j rk−r0 k n rk 39 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 and then we can apply the following approximation to the binomial distribution [JKK92] as long as rk=zkn+o(n) and j=cn +o(n) j r0 kn−j rk−r0 k n rk=rk r0 kj nr0 k1−j nrk−r0 k1 + r0 k−(r0 k−rk)2 2j+O1 j2, where rk=rkj nis the mean value of the hypergeometric distribution. If we divide the range of summation of r0 kinto three parts, from 0 to rk−∆−1, from rk−∆ to rk+ ∆ and from rk+ ∆ + 1 to rk, we can consider the three parts separately, with the main contribution coming from the middle range. In particular, we need ∆3/n2→0 as n→ ∞, that is ∆ = o(n2/3), to be able to apply the de Moivre-Laplace limit theorem to the middle sum. With σ=rkj n1−j n, we have that the middle sum is rk+∆ X r0 k=rk−∆ 1 √2πσ e−(r0 k−rk)2/(2σ)+O(∆3/n2)+O(∆/n) ×φr0 k j1 + O(∆/n) + O(∆2/n) + O1 n2, where we have also expressed the error bounds for the approximation of the hypergeometric distribution in terms of ∆; we need ∆ = o(√n) too for the approximation to be of any use. Using ex= 1 + O(x) we can write the sum above as rk+∆ X r0 k=rk−∆ 1 √2πσ e−(r0 k−rk)2/(2σ)(1 + O(∆/n))φr0 k j1 + O(∆2/n), since O(∆3/n2) = O(∆/n) for ∆ = o(√n). Finally, we can expand φ(r0 k/j) = φ(rk/j +y/j) for y=r0 k−rk,y∈[−∆,∆] as φ(r0 k/j) = φ(rk/j) + O(∆/n) to get rk+∆ X r0 k=rk−∆ 1 √2πσ e−(r0 k−rk)2/(2σ)(1+O(∆/n))φrk j(1 + O(∆/n)) 1 + O(∆2/n) =φrk j(1 + O(∆2/n)) = φrk j(1 + o(1)). To complete this part of the analysis we only need to show that the other two sums (with r0 k< rk−∆ and r0 k> rk+ ∆) are negligible as n→ ∞. This immediately follows since φ(r0 k/j) is bounded by a constant, and we only need to note that the tails of the hypergeometric distribution (or its binomial approximation) decay polynomially as we move away from the mean rk, then exponentially. To have an error bound as small as possible it helps to take ∆ as large as possible, as long as it remains o(√n). 40 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 We handle the other inner sums (for rank vectors in L(i,j) r,R(i,j) rand B(i,j) r) in (7) analogously; we have thus that the error bound inside each summation on jis (1 + O(∆2/n)), but the approximations are not valid if j=o(n). However these can be disregarded as their total contribution is negligible, since the tail of the hypergeometric distribution decays exponentially. This also justifies the assumption that all extreme ranks are ri= 0 when we actually have extreme ranks ri=o(n) (or ri=n−o(n), but then we can take ri:= n−ribecause of the symmetry). Altogether, these computations show that C0 n,r=f(r/n) + o(1) satisfies C0 n,r∼o(1) + 1 nK "X 0≤i<t n−1 X j=ri C0 j,←− r·j nγ + ri−1 X j=0 C0 n−1−j,−→ r·n−1−j nγ!# (15) +s0 nK · n−1 X j=0 C0 j,←− r·j nγ +(K−s) nK · n−1 X j=0 C0 j,←→ r·j nγ +C0 n−1−j,r−←→ r·n−1−j nγ, and hence f(r/n)·nα+o(nα) satisfies the full recurrence (7), with toll function o(nα) instead of the toll function τn,r= 1. 41 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 Click here to download Figure pointplo3d.jpg