Aggregating large amounts of data plays an increasingly important role across various scientific fields. However, what makes the aggregated data so important is the same element that renders the privacy of the individuals critical. For example, in the medical field while patient records may be used aggregately to offer faster and better diagnoses, it also amplifies concerns regarding individual privacy in how this data is being used. Similar concerns permeate nowadays various fields of modern society, forcing even governments to adopt new and sweeping privacy laws such as the EU's General Data Protection Regulation 2016/679 (GDPR). From a statistics point of view, the natural and urging associated statistical question is what information of the data can be released while respecting, to the maximum possible extent, the privacy of the individuals involved. Straightforward approaches, such as removing obvious identifiers or releasing only the summaries that concern at least a certain number of members, i.e in a social network or in a HIV-patient health-care database, can be easily broken [DSSU17, RG20, BCSZ18b] .
To understand the emerging trade-off between information and privacy, researchers have employed the notion of differential privacy [Dwo06, DMNS06, DR14]. In this framework, researchers reported the outcome of their analyses having firstly injected a well-calibrated noise. More precisely, the level of the noise has been chosen in such a way that it would be computationally arduous to reconstruct any personal micro data but would simultaneously permit an accurate estimation of group statistics.
In this work, we study the optimal statistical performance of a differential private estimator for the task of median estimation, one of the simplest and most preferred statistical index in various scientific fields associated with an one-dimensional data-set. Despite the fact that the introduction of the median even as a term is relatively recent (the earliest trace in English literature appears to be in 1881 by Francis Galton in one of his surveys [G + 82, Dav95]), it seems that, as a measure of central tendency, it behaves much more robustly [Hub81, HRRS11] than many other statistical indices, such as mean and mode, especially due to its high break-down point [DG07, HR81]. As a simple, yet relevant example, the nominal median income reflects much better the real-life setting than the mean corresponding index. Indeed, the median household income -the income cut-off where half of the households earn more, and half earn less -is much more robust and illustrative than the mean estimator which could easily have been biased by a small number of billionaires. Furthermore, even the task of determining the critical high-risk age groups during the ongoing COVID-19 pandemic, median estimator plays a significant role in balancing out some possible outliers [DCKP06, CDC19] .
In all these cases, median gives crucial information causing probably several social, political and financial implications. More importantly, however, safeguarding the individual privacy of the members of a survey could prevent acts of discrimination based on the leaked personal data. In social networks [TC12, KRWY16, ZLZP17, LXJ + 20] or medical applications [DE13, MEO13, FLJ + 14, ZLZ + 17, YKÖ17] for instance, samples may correspond to human subjects and it is crucial that the estimator maintains their privacy while still producing accurate results.
Our model. We focus on the statistical problem of estimating the median of a probability distribution under privacy constraints. Given sample access to an unknown distribution D with median m (D), the goal is to produce an estimatem that satisfies |m (D) −m| ≤ α with probability 1 − β while respecting the privacy of the samples. An important property of the median estimation task is that it can be efficiently estimated using few samples even under heavy tailed distributions whose mean may not even be well-defined. A minimal statistical assumption for estimation is a mild concentration of the distribution around the median, i.e. that for some parameters L and r, the distribution has density at least L in an interval [m (D) − r, m (D) + r] around the median. In such a case it can be shown that O(log(1/β)/(α 2 L 2 )) samples suffice to learn the median within α < r with probability 1 − β [BA20] .
As mentioned above, differential privacy is the leading measure for quantifying privacy guarantees for an arbitrary randomized function of many input points. It is parameterized by a value ε and it requires that changing the value of any input point may change the probability of any output by at most a factor of e ε . More formally we use the Hamming distance d H (X, X ′ ) := |{i ∈ [n] X i = X ′ i }|, defined for two n-tuples of samples X, X ′ ∈ R n . Definition 1.1. A randomized algorithm A is ε-differential private if for all subsets S ∈ F of the output space (Ω, F) and n-tuples of samples X 1 , X 2 ∈ R n , it holds P (A(X 1 ) ∈ S) ≤ e εd H (X 1 ,X 2 ) P (A(X 2 ) ∈ S) .
(1.1)
While there has been extensive work in statistical estimation under privacy constraints, obtaining private estimators with optimal sample complexity was only recently shown to be possible. Karwa and Vadhan [KV18] studied the basic problem of learning the parameters of a univariate Gaussian and obtained the optimal rate for estimation. Subsequently, sample efficient estimators were obtained for learning multi-variate Gaussians and product distributions [KSSU19, ZKKW20, KLSU19]. Further work obtained minimax rates for various other statistical problems [CKS20, KSU20, DWJ16], including mean estimation for heavy tailed distributions [KSU20, DWJ16] , parameter estimation for Erdős-Rényi graphs and stochastic block models [BCS15, BCSZ18c, SU19] and general hypothesis selection [BKSW19, GKK + 20].
Our work considers the setting of the recent work by Avella-Medina and Brunel [BA19, BA20] who studied the problem of median estimation under arbitrary distributions D that satisfy a mild concentration condition and whose median lies in a bounded range. Note that, under the Assumption 1.2 the distribution can output arbitrarily large values and is not required to have finite moments.
We call distributions that satisfy this Assumption 1.2 admissible. For the class of admissible distributions, [BA19] obtained two private estimators that inÕ(n)-time produce an estimatem for the median such that |m (D) −m| ≤ α with probability 1 − β using a sample size n. The estimators achieve sample complexity Ω log 1 β L 2 α 2 + log 2 1 β log 1 δ ε 2 Lα + log( R α + 1) log 1 δ εLr and Ω log 1 β L 2 α 2 + log 2 1 β (log 1 β + log 1 δ ) ε 2 Lα They both work under the (ε, δ)-differential privacy setting (see Definition A.1) which is a weaker guarantee than pure differential privacy.
While, the estimators from [BA19] establish indeed the finite sample complexity on learning the median privately, our main result is a significantly improved estimator which learns the median using less samples and works under the stricter pure ε-differential privacy. Our result improves upon several aspects of the prior bound and gives stronger privacy guarantees. It has linear dependence in both 1/ε and log(1/β) as opposed to quadratic/cubic. Importantly, we show that the sample complexity we obtain is tight in all possible parameters up to absolute constants. We obtain matching lower-bounds showing that any estimator that produces an α-accurate estimate of the median must use at least a constant fraction of the samples used by our estimator. Our results can also be applied for location estimation in the case of a Gaussian distribution N (µ, σ 2 ) with known variance σ 2 . In this case, the median is equal to the mean and we recover the exact tight bounds obtained in recent work of [KLSU19, KV18] . Thus, despite our minimal distributional assumptions, the trade-off between samples, accuracy and privacy that we obtain is the same as the simpler parametric setting of Gaussian distributions. Finally, one of the two estimators constructed by Avella-Medina and Brunel [BA19, BA20] are leveraging the notion of smooth sensitivity to create the private median estimator. Interestingly, some recent work by Asi and Duchi [AD20, Lemma 5.2.] proved that any successful ε-private median estimator which is adding noise based on the smooth sensitivity of the median function requires the use of n = Ω 1 αε 2 samples. Hence, the result of Asi and Duchi combined with our result that in some regime the correct scaling for the sample complexity isΘ( 1 εα ), allows us to conclude the suboptimality of the smooth sensitivity method in the private median estimation task. A similar notion of suboptimality of smooth sensitivity for median estimation has been establish by Asi and Duchi themselves in the slightly different context of instance-optimality [AD20] .
To obtain our main result we devise a more general principled framework that can be applied to many other problems in private statistical estimation. Our framework splits the design problem in two steps, and is inspired by earlier work on learning Erdős-Rényi graphs and, their generalization, graphons [BCSZ18a, BCSZ18c] :
1. We obtain private algorithms for a subset of the domain. We focus our attention to a restricted class of instances that are "typical" with respect to the distribution. We define a set of constraints that samples should satisfy with high probability and focus only on instances that meet those constraints. In this restricted setting, we obtain an estimator that is accurate and private for these instances only.
2. We extend our estimator to all instances and guarantee privacy globally. We want to do this while preserving the output of our estimator in the set of typical instances.
In the first step, we make careful use of the well-studied Laplace mechanism, that is a common method for a turning a non-private algorithm to a private one. It works by adding Laplace noise to the deterministic final output of the algorithm in order to ensure privacy. The amount of noise that needs to be added crucially depends on the sensitivity of the algorithm to changes in the input.
For the task of computing the median of n points, the sensitivity can be quite high as even if all points are bounded in [−R, R] there are instances where changing a single input may change the median by R 1 .
While a worst case instance might have large sensitivity, as argued above, one expects that, in a "typical instance" drawn randomly from a concentrated distribution, the median does not change so drastically when few of the points move. Indeed, we quantify the notion of a typical instance as the family of instances that have many points in various distances from the sample median and show that for such "typical" instance, even changing a small fraction of input points cannot move the median of the sample dramatically.
To obtain our main result, we exploit this observation and initially focus only on typical instances of the distribution. For those instances, we show that a variant of the Laplace mechanism, which we call "flattened" Laplace mechanism ensures that differential privacy is guaranteed when focusing only on typical instances. Importantly, while working on these instances this simple variant suffices for obtaining high probability accuracy guarantees, a more delicate approach is necessary to ensure privacy guarantees, which should work even under worst case instances.
In the second step, we aim to define the output distribution of our estimator in the atypical instances to ensure privacy globally. To achieve this, we employ a method for Lipschitz extensions that has been developed in prior work for estimating parameters of Erdős-Rényi graphs, called the "Extension Lemma" (Check Proposition 2.1, [BCSZ18a] ) The "Extension Lemma" shows that it is always possible to extend a private algorithm from a smaller domain A to a larger domain B without changing the output distribution for instances in A. It achieves this by explicitly defining what the output distribution should be for instances in B \A and only worsens the privacy guarantee by a factor of 2. This allows to obtain worst-case private estimators that are guaranteed to produce accurate estimates with high probability over the instances drawn from the distribution.
Finally, an important technical contribution of our work is showing that the extension can be computed in polynomial time. We do this by characterizing the structure of the resulting extended output distributions showing that they are piece-wise "constant" or "exponential" with poly(n) number of pieces. We can identify all these pieces through a simple greedy algorithm and sample exactly from the resulting distribution. This provides the first instance of a natural problem for which the extension given by the Extension Lemma [BCSZ18a] can be computed in polynomial time making progress on a direction suggested by the authors of [BCSZ18a] .
Lipschitz-extensions is a popular technique for designing private algorithms that was used for example in [BBDS13, KNRS13] . A common theme in those methods is that they develop a Lipschitz estimator for a quantity of interest in a small domain that is extended to be Lipschitz throughout the whole domain and can then be made private through the Laplace mechanism. Developing a Lipschitz median estimator for our setting would lead to suboptimal rates that scale linearly with the range of possible values R 2 . In contrast, our framework does not simply add noise to a Lipschitz extended estimator but constructs directly a private mechanism for the small "typical" domain and extends it to the whole domain via the more general Extension Lemma that has been developed in recent work [BCSZ18a, BCSZ18c] .
The framework of Lipschitz-extensions was also recently used for estimation of the median along with other statistics such as the variance and the trimmed mean [CD20] . Their paper focuses on arbitrary data-sets without statistical assumptions. Applied to our setting, their methods would yield sub-optimal sample complexity, scaling linearly with the range possible values R, again as opposed to the optimal logarithmic dependence we obtain in our work. Median estimation has also been studied in [DL09], who gave an (ε, δ)-differentially private mechanism that is consistent in the limit but did not provide explicit non-asymptotic rates.
In this section for the reader's convenience, we present briefly a main tool behind of our approach, which we refer to from now on as the Extension Lemma. The Extension Lemma is originally stated and proved in [BCSZ18c, BCSZ18a] .
Using the notation of Definition 1.1 let us consider an arbitrary ε-differentially private algorithm defined on input belonging in some set H ⊆ R n . Then the Extension Lemma guarantees that the algorithm can be always extended to a 2ε-differentially private algorithm defined for arbitrary input data from M with the property that if the input data belongs in H, the distribution of output values is the same with the original algorithm. The result in [BCSZ18a] is generic, in the sense of applying to any input metric space, but here we present it for simplicity only when the input space if the input space is R n and is equipped with the Hamming distance d H . Formally the result is as following, Proposition 2.1 ("The Extension Lemma" Proposition 2.1, [BCSZ18a] ). LetÂ be an ε-differentially private algorithm designed for input from H ⊆ R n with arbitrary output measure space (Ω, F). Then there exists a randomized algorithm A defined on the whole input space R n with the same output space which is 2ε-differentially private and satisfies that for every X ∈ H, A(X) d =Â(X).
In this section, we present an optimal ε-differentially private algorithm for median estimation. We defer the proofs of the stated results to the appendix. We start with the model of estimation.
In our statistical model, for some n ∈ N one is given n independent identically distributed (i.i.d.) samples X 1 , · · · , X n from a distribution D. We make the minimal assumption that the distribution D is admissible per Assumption 1.2 for some fixed, but arbitrary, parameters L, R, r > 0 satisfying Lr ≤ 1 2 . We are interested in estimating the median of D, denoted by m (D) , from the n samples using an ε-differentially private algorithm. Importantly, we assume that the algorithm designer has access to the exact values of the parameters L, r, R > 0 for which the distribution D satisfies the admissibility assumptions. Our main interest is to study the following minimax rate:
(3.1) where in the above min we use the abbreviation D.P. for differential privacy and (L, R, r)−D admissible for being admissible with parameters L, R, r. Our focus is on the sample complexity defined for any α ∈ (0, r), β ∈ (0, 1) and R, L, r with Lr ≤ 1 2 as following. n sc (α, β, R, L, r, ε) := inf{n ∈ N : R (n, ε, L, R, r) (α) ≤ β}.
(3.2)
In words, we want to understand the minimum number of samples that are required for an εdifferentially private estimator to estimate the median with accuracy α with probability 1 − β.
We offer a tight, up to absolute constants, characterization of the sample complexity. Our results follow by proposing and analyzing the performance of an ε-differentially private algorithm and also proving the corresponding minimax lower bound.
Theorem 3.1. Assume ε ∈ (0, 1). Then for any L, R, r > 0 with Lr ≤ 1 2 and α ∈ (0, min{R, r}), β ∈ (0, 1 2 ) it holds
We describe here the construction of the optimal ε-differentially private algorithm. We use the Extension Lemma and follow the path described in items 1,2 in Section 1.2. Our high-level approach is to first define a a "typical" subset of the input space and a restricted differentially private algorithm defined only on the "typical" subset, and then use the Extension Lemma (Proposition A.3) to extend it to a private algorithm on the whole input space. All stated results are proven in the Appendix.
The typical set We first define a "typical" subset H ⊆ R n of the input space. Let C > 1 be a constant we are going to choose sufficiently large. We define
where by m(X) we denote the left empirical median of the set (X 1 , · · · , X n ) (see Definition A.2). In words, the first two families of constraints assume that there are sufficiently many samples falling sufficiently close to the empirical median m(X), at distances which are multiples of C/Ln. The motivation for this choice comes from the fact that each interval [0, κC/Ln] is assigned from any admissible distribution D at least Cκ/n probability mass based on the Assumption 1.2. Hence, in expectation, it contains at least Cκ > κ out of the n samples. The last constraint of H assumes that the m(X) falls sufficiently close to the interval the population median m (D) is assumed to belong to, based on the Assumption 1.2.
m(X) Figure 1 : "The flattened"-Laplacian Mechanism
The restricted algorithm We now define the algorithm on inputs from H as a randomised algorithm with density given by
where the normalizing constant iŝ
We call this distribution a "flattened" Laplacian mechanism (see Figure 1 ). Note that the normalizing constantẐ does not need to be indexed by the n-tuple X as it can be easily proven that for C > 1/2 the integral on the left hand side of (3.5) gives the same value for all X ∈ H. Furthermore, observe that to implement the restricted algorithm given as input a data-set X ∈ H, we first compute the left empirical median m(X) and then sample from the "flattened" Laplacian distribution, one part of which is a uniform distibution and the other one is a truncated Laplacian distribution. The exact sampling details from the distribution are defered to Section 4. The motivation to select this distribution is to ensure that the algorithmÂ is ε/2-differentially private. The reason is that the median m(X) as a function from (H, d H ) to the reals, is unavoidably highly sensitive (e.g. it can move distance Ω (R) with n/2 + 1 changes) and therefore by simply adding Laplace noise, as customary in the design of private algorithms, would not suffice to obtain optimal rates. Nevertheless we show that it satisfies the following "approximate" Lipschitz constraint with a "Lipschitz" constant which is independent of R.
Using this constraint and the definition of the "flattened" Laplacian mechanism, it can be shown using elementary arguments that indeed for inputs X, Y ∈ H it indeed holds for all real q, fÂ (X) (q) ≤ e ε 2 d H (X,Y ) fÂ (Y ) (q), which certifies the ε/2-differential privacy. The following lemma holds.
Lemma 3.3. The algorithmÂ defined on H is ε 2 -differentially private. With respect to accuracy guarantees the following elementary result can be proven by using the density of the "flattened" Laplace distribution, as defined in Equation (3.4).
Lemma 3.4. Suppose C > 1 and a fixed X ∈ H. Then for any L, R, r > 0 with Lr ≤ 1 2 and α ∈ (0, r), β ∈ (0, 1) for some n = O
where the probability is with respect to the randomness of the algorithmÂ.
The general algorithm Now we construct the final algorithm using the Extension Lemma (Lemma 2.1). First, note that the algorithmÂ defined on H based on Lemma 3.3 is ε 2 -differentially private. Hence, using the Extension Lemma there is an ε-differentially private algorithm A defined on the whole input space R n with the property that for any X ∈ H it holds A(X) d =Â(X). This is the algorithm we consider for the upper bound.
An investigation on the proof of the Extension Lemma in [BCSZ18a] , deferred due to space constraints to the appendix and specifically Section A.2, shows that the algorithm A can be described as receiving input X ∈ R n and outputting a sample from the continuous distribution with density given by
where ω ∈ [−R − 4Cr, R + 4Cr] and Z X is the appropriate normalizing constant. We now briefly elaborate on its accuracy guarantee. The set H, besides crucial for Lemma 3.2, is important to our construction because of the following technical "typical" guarantee it has.
Lemma 3.5. Let D be an admissible distribution for some parameters L, R, r > 0 with Lr ≤ 1 2 , let β ∈ (0, 1), n ≥ 3 and let X = (X 1 , . . . , X n ) consisting of i.i.d. samples from D. Suppose C > 5 satisfies 4Ce exp − 2C 27 < 1/2. Then for some C ′ = C ′ (C) > 0 and n = O
In words, the lemma claims that with probability 1 − β an n-tuple of i.i.d. samples from D, call it X, has O log 1 β Hamming distance from at least one element X ′ ∈ H with m(X) = m(X ′ ). Now the accuracy argument for the performance of A follows from the following high-level idea. By the definition of ε-differential privacy (Definition 1.1) we know that the algorithm A when applied to two inputs of sufficiently "small" Hamming distance the outputs are "close" in distribution. Hence, Lemma 3.5 implies that the law of A(X) with input X is "close" to the law of A(X ′ ) where the input is some X ′ ∈ H with m(X ′ ) = m(X). Now since X ′ ∈ H by construction the law of A(X ′ ) equals the law ofÂ(X ′ ). Furthermore from Lemma 3.3 we know thatÂ(X ′ ), and therefore also A(X), concentrates around m(X ′ ) = m(X). Finally standard concentration results (see e.g. [BA20, Lemma 3]) imply that with n = Ω log 1 β /(L 2 α 2 ) samples it holds |m(X) − m(D)| ≤ α with probability 1 − β.
Using the above idea we obtain the following result.
Theorem 3.6. Suppose C > 0 is a sufficiently large constant, ε ∈ (0, 1), D is an admissible distribution with respect to some arbitrary L, R, r > 0 with Lr ≤ 1 2 and A is the ε-differentially private algorithm defined above. Then for any α ∈ (0, r) and β ∈ (0, 1) for some
Finally, the discussion on the computationally efficient implementation of the algorithm A is deferred to Section 4.
In this subsection we discuss the lower bound part on n sc (α, β) as stated in Theorem 3.1. We establish that all three terms are necessary for all values of the parameters, using a different method for each one of them. We omit the complete proofs for the appendix and provide only brief hints for the methods followed. First, we start with the ε-independent part (the "non-private" part).
. Then for any algorithm A there exists an admissible distribution D for this specific value of the parameters with the property
The key argument behind the proposition is to show that learning a a Bernoulli random variable at accuracy γ > 0 with probability 1 − β reduces to learning the median of an admissible distribution at accuracy γ/L with probability 1−β. Then using that the sample complexity of learning a Bernoulli distribution is known to require Θ log 1 β /γ 2 samples we conclude the proof. We are ready to state the lower bound on the first term on the ε-dependent part.
Proposition 3.8. Let L > 0, ε ∈ (0, 1), R, r > 0 with Lr ≤ 1 2 and α ∈ (0, min{r, R 2 }), β ∈ (0, 1 2 ). Suppose n = o log 1 β /(εLα) . Then for any ε-differentially private algorithm A there exists an admissible distribution D for this specific value of the parameters with the property
The proof of this lower bound follows by a "local" argument. We construct two admissible distribution D, D ′ with medians of distance O (α) which we can couple so that drawing X, X ′ two i.i.d. n-tuples from D, D ′ respectively, it holds d H (X, X ′ ) = O(αLn) with high probability. Using the definition of differential privacy we conclude that A(X), A(X ′ ) assign the same probability to each event up to a multiplicative factor e O(εαLn) . Yet, we prove that an algorithm contradicting the assumptions of Proposition 3.8 will imply that while A(X) assigns mass at least 1 − β on the interval of width 2α around m(D), the algorithm A(X ′ ) needs to assign mass at most β. Hence combining the above, we conclude that it must be true that e −εαLn = O (β) or n = Ω log 1 β /(εLα) .
Proposition 3.9. Let L > 0, ε ∈ (0, 1), R, r > 0 with Lr ≤ 1 2 and α ∈ (0, min{r, R}), β ∈ (0, 1 2 ). Suppose n = o log R α + 1 /(εLr) . Then for any ε-differentially private algorithm A there exists an admissible distribution D for this specific value of the parameters with the property
This lower bound follows by a "global" argument. We show that any ε-differentially private algorithm contradicting the conclusion of Proposition 3.9 needs to assign at least Ω e −Lrn probability mass in at least R α + 1 distinct intervals in [−R, R]. Since the total probability mass must sum up to one we obtain the desired lower bound.
In the previous section we constructed an differential private estimator denoted by A and proved that it is up-to-constants rate-optimal with respect to sampling complexity. In this section we report the following results. In the first subsection we prove that it can be efficiently implemented in worst-case polynomial time and average-case almost-linear time. Specifically, in the first subsection we sketch the high-level ideas to provide intuition. In the following subsections we offer the exact implementation details as well as the statements and their proofs regarding its computational complexity guarantees.
We start with a pseudocode for the general algorithm sampling A as defined in Equation (3.6) and its crucial property that it extends the simple "flattened Laplacian" algorithm given byÂ as defined in Equation 3.4.
else m ← Sample from D general (Case (B)) return m Algorithm 1: PrivateMedian(X = (X 1 , . . . , X n )): This is the pseudocode for the general algorithm of sampling from the extended mechanism based on Equation (3.6). The notation D ∼ p(ω) is used to denote that the density of the distribution D is proportional to the function p(ω).
We start with describing the high level ideas behind our implementation and its worst-case computational complexity guarantees. We then conclude with its average-time computational complexity guarantees as well.
First, notice that in the case of a data-set X that belongs to the typical set H, our estimator corresponds to sampling from D restricted − the "flattened-Laplacian" continuous distribution ofÂ(X ′ ) as defined in Equation (3.4). Therefore, the implementation of the algorithm with input from H corresponds to a simple two-phase protocol. In the first round we flip an appropriately biased coin to decide between the two regions where the estimator behaves differently: i) the region where the estimator samples proportional to the Laplacian density and ii) the region where the estimator samples proportional to the uniform distribution. In the second round we simply apply conditional sampling either from a Laplacian or a uniform distribution, depending on the outcome of the coin flip. Now, notice that we can sort X in O(n log n)-time, the query X ∈ H can be easily answered with counting binary-searches in O(n log n) time and, as we just discussed, it is easy to sample in poly(n)time from D restricted . Therefore, to implement efficiently the extended mechanism A, a poly(n)-time sample generator is sufficient and necessary for the (appropriately normalized) distribution D general (See Equation (3.6)) whose unnormalized density is given by:
. Notice that such a task is a-priori challenging as even the evaluation of UnNormalized(X, ω) at a single instance of ω appears non-trivial because it involves a complicated optimization problem over X ′ ∈ H.
Our main technical contribution is to show that this underlying constrained optimization problem associated with the definition of the density of D general can be solved in polynomial-time for every fixed ω and then show how to use it to obtain a polynomial-time sample generator for the desired distribution. A key observation is that UnNormalized(X, ω) depends only on the possible values of the median m(X ′ ) and the distance d H (X, X ′ ), for any data-set X ′ ∈ H. To simplify our notation, we introduce in our analysis the notion of the TypicalHamming distance of a data-set X and the typical set H, which we prove that it can be computed in poly(n)-time.
Lemma 4.1. Let us define TypicalHamming(X, ξ) as:
Then for any data-set X, TypicalHamming(X, ·) is piece-wise constant function in [−R − r/2, R + r/2] with at most poly(n) changes. Additionally, for any ξ and data-set X, TypicalHamming(X, ξ) can be computed exactly using the poly(n) 3 -time algorithm described in Algorithm 3.
Leveraging the partition of the interval [−B, B] implied by the different constant parts of Lemma 4.1 we are able to show the following for UnNormalized(X, ω):
Lemma 4.2. For any given data-set X, there is a partition of [−B, B] to a collection J of poly(n) consecutive intervals, J = {J 1 , · · · , J poly(n) } such that :
Moreover, we can compute exactly J and the constants (α i , β i ) for every J i ∈ J in poly(n) time.
In words, Lemma 4.2 implies that our extended mechanism consists a concatenation of poly(n) exponential or uniform distributions. Therefore, its implementation corresponds again to a simple two-phase protocol, similar to the implementation of the much simpler D restricted . In the first round we sample from a discrete distribution on a poly(n)-cardinality domain to decide among the regions J 1 , · · · , J poly(n) . In the second round we simply apply conditional sampling from the corresponding either exponential or uniform which will be truncated on the region which was the outcome of the first round. Notice that all our decomposition results apply to any input vector X. Combining the above, we show that a worst-case poly(n)-implementation of PrivateMedian is possible via the aforementioned decomposition of D general . Now, a potentially interesting remark is in order. Recall that the typical set H as defined in (3.3), which is used to define the algorithm A, is a function of the parameter C > 1. Furthermore, recall that based on Theorem 3.6, the algorithm A with C > 0 being a sufficiently large constant is proven to achieve, up-to-constants, the optimal sample complexity. Now, importantly, our implementation of A remains worst-case polynomial-time for any choice of C, possibly scaling with n, since such a change affects only the arithmetic operations which are assumed to be executed always in O(1)-time. Using this observation, we can show that by tweaking appropriately this parameter C from an absolute constant Θ(1) to scaling logarithmically-in-n factor Θ(log n) that the average-case time complexity of the algorithm becomes up-to-logarithms linear. Furthermore, we can maintain for the algorithm for this choice of C = Θ(log n) an, up-to-logarithms this time, optimal sample complexity guarantee.
More precisely, combining all the above, the following theorem holds, which slightly generalizes Theorem 3.6, as it allows C to scale with n.
Theorem 4.3. Suppose C = C n > 0, possibly scaling with n, is bigger than a sufficiently large constant, ε ∈ (0, 1), D is an admissible distribution. Then for any α ∈ (0, r) and β ∈ (0, 1), there exists an ε-differentially private implementation of PrivateMedian such that if it holds
it produces an estimatem that satisfies |m(D) −m| ≤ α with probability 1 − β and runs (i) at most in poly(n) time , for some sufficiently large constant C > 0.
(ii) on expectation inÕ(n) time, for some sufficiently large constant C 0 > 0 and C = C 0 log n.
The following clarification remark is in order.
Remark 4.4. Using the elementary property that for two diverging sequences A n , B n , n ∈ N, it holds A n / log A n = Ω(B n ) if and only if A n = Ω(B n log B n ), the ε-differentially private implementation of PrivateMedian mentioned in Theorem 4.3 in the case C = C 0 log n for some sufficiently large constant C 0 > 0, requires a sample size of order
to output an estimatem that satisfies |m(D) −m| ≤ α with probability 1 − β.
In this section we prove Theorem 4.3. In Section 4.2.1, we focus on the, arguably pessimistic, model of worst-case analysis, and we show that we can implement the algorithm A at most in poly(n) time. The worst-case complexity guarantee of our implementation hold under arbitrary C = C n > 0 bigger than a sufficiently large constant. Notice that combining this time-complexity guarantee with the sample complexity results from Theorem 3.6 we can conclude the part (i) of Theorem 4.3. We then proceed with average-case analysis presented in Section 4.2.2 where we assume that C is scaling logarithmically with n. We show that this sacrifices the optimality of our sample complexity just up to a logarithmic factors and in that case our implementation actually runs on expectation inÕ(n) time.
Note:For our worst-case and average-case analysis, we will assume that there is an oracle O such that we can always sample from Bernoulli, Uniform, Laplace, (Negative) Exponential Distribution and their truncated versions in an interval I in O(1) time. The exact details are in Appendix D.
We start by presenting a simple random generator for D restricted (Case (A) of Algorithm 1, X ∈ H.):
Lemma 4.5. For a given a date-set X = (X 1 , · · · , X n ) ∈ H and its median m(X), there exists a O(1)−protocol that generates a sample from D restricted . We continue by presenting the construction of our sample generator for D general ((Case (B) of Algorithm 1, X ∈ H.)). Firstly, let's recall the un-normalized term of D general , using the definition of f A(X) (Equation (3.6)):
Our main technical contribution for this part is showing that the above constrained optimization problem can be solved in polynomial-time and then using it to obtain a polynomial-time sample generator for the desired distribution. A key observation is that UnNormalized(X, ω) depends only on the possible values of the median m(X ′ ) and the distance d H (X, X ′ ), for any data-set X ′ ∈ H.
To motivate our first technical lemma let's re-write the above optimization expression with an Let I left , I center , I right be the decomposition of I = [−B, B] as described in the above figure // For extreme values of C, r, m(X), // either I left , I center or I right may equal to ∅
if c outputs C then
In order to discretize the optimization space over H, we use the following observation that we presented in Lemma 4.1.
Lemma 4.6 (Restated Lemma 4.1). Let us define TypicalHamming(X, ξ) as:
Then for any data-set X, TypicalHamming(X, ·) is piece-wise constant function in [−R − r/2, R + r/2] with at most poly(n) changes. Additionally, for any ξ and data-set X, TypicalHamming(X, ξ) can be computed exactly using the poly(n) 5 -time algorithm described in Algorithm 3.
Proof. Our proof follows by combining the following claims:
1. (Claim 4.7) We begin the proof by presenting a simple greedy algorithm, Algorithm 3, that outputs a data-set X ′ such that it belongs to the typical set H, and its median m(X ′ ) equals to an input value ξ. From all the possible choices of X ′ the greedy algorithm chooses the one that minimizes the Hamming distance from an input data-set X = (X 1 , X 2 , . . . , X n ).
2. (Claim 4.8) Having established the correctness of the greedy method, we show that there exists a partition of [−R − r/2, R + r/2] to a collection of poly(n) disjoint subintervals such that in every subinterval, the output of the greedy algorithm remains constant.
Claim 4.7. The procedure Algorithm 3 for solving TypicalHamming(X = (X 1 , . . . , X n ), ξ) outputs a data-set X ′ satisfying the conditions that m(X ′ ) = ξ and X ′ ∈ H that minimizes the Hamming distance between X, X ′ over all X ′ ∈ H, i.e arg min
Proof. Firstly, we will write down the list of the constraints that the above optimization algorithm needs to satisfy:
Our algorithm, as described in Algorithm 3, runs based on the following greedy choice:
In order to transform X to X ′ with the least number of changes min d H (X, X ′ ) s.t ξ is a well-concentrated left-median of X ′ ,
If an LS/RS constraint is violated, we change firstly the further element of ξ from the right/left side. If we change an element of X, we set it always ξ.
It is easy to check using classical exchange arguments for both part (A) and part (B) that the algorithm outputs an optimal solution. Indeed, let X O be an optimal data-set for the above combinatorial problem, in other words:
We show that for any optimal data-set X O , different from the the output X ′ of the Algorithm 3, we can transform X O to the output X ′ of the Algorithm 3 without increasing the Hamming distance from the input data-set X. To describe uniquely X O , it suffices to list its modifications from the set X. Let's denote this list
. ≤ X ′ n -Tie breaker: Maintain the order before the sorting.-Extract the permutation π :
Part 2.Rebalance the data-set to achieve concentration around ξ
return d H (X, X ′ ) Algorithm 3: TypicalHamming(X = (X 1 , . . . , X n ), ξ). In words, our greedy algorithm has three parts. As preliminary steps, we firstly copy the data-set to a table X ′ , we sort it and compute its left-median. In the case that ξ is not equal with its left median, we compute between which elements ξ lies inside the ordered table X ′ . In the case of ties, we "position" ξ to the closest possible to the median. In Part 1. if ξ is less than the median, then we change the highest possible values of the table to ξ until ξ becomes the median, symmetrically for the other case. In Part 2. we follow the same strategy like Part 1 but our goal now to maintain the concentration requirements of
Firstly we mention that the greedy choice of setting any changed element of X to ξ is always as good as any other optimal choice, since ξ is by definition the median of X O . This holds because ξ is the central value for any of the interval constraints. Thus we can transform
Secondly, it is easy to check because of the nesting nature of the constraints around the median that the greedy choice of changing firstly the further element of ξ is again always as good as any other optimal choice. Indeed, let T be the list of modifications provided by our method, M T = {X T 1 → ξ, · · · , X T ℓ → ξ}. Indeed, if M T and M O differ in one change we can always follow the greedy's choice since it will satisfy at least the same number of constraints than any other solution.
Thus without never worsening the optimal solution, we can eliminate any differences by changing inductively X O to the solution of TypicalHamming(X = (X 1 , . . . , X n ), ξ). Claim 4.8. For a given data-set X = (X 1 , . . . , X n ), there is a poly(n)-time computable ordered collection of O(n 2 ) points P = {−R − r/2 = P 0 , P 1 , · · · , P k , P k+1 = R + r/2]} such that for every open interval I = (P i−1 , P i ) , it holds that :
For any ξ 1 , ξ 2 ∈ I : TypicalHamming(X, ξ 1 ) = TypicalHamming(X, ξ 2 ).
Proof. We will start by describing the set P. For each point of our data-set we create 2⌊ Lnr 2C ⌋ + 1 anchor-points. More precisely for the point X i , we set as anchor points:
Let P be the union of all the anchor points plus the limit points of the interval [−R − r/2, R + r/2]:
It is easy to see, since Lr ≤ 1/2, C > 1 that we need O(n 2 ) time for its construction:
Algorithm 4: Construction − P(X = (X 1 , . . . , X n ))
Finally, we show that for any consecutive points of P, let p i , p i+1 , the algorithm TypicalHamming(X, ξ) outputs the same value for any ξ ∈ (p i , p i+1 ).
Indeed, let's assume any ξ = ξ ′ such that ξ, ξ ′ ∈ (p i , p i+1 ), where p i , p i+1 ∈ P. Since between ξ, ξ ′ we assumed that there is no point of P, by definition we have that
By inspection of the algorithm, it follows that all the decision of the algorithm have been taken based on the queries of the form:
More precisely the queries Q 1 (ξ), Q 2 (ξ) are used in Part(A) and Q 3 (ξ), Q 4 (ξ) in the Part (B). Additonally, it is easy to check that any query calculates sums of indicators of the form of eq. (Oblivious Property). Therefore for any ξ, ξ ′ that belong to the open interval (p i , p i+1 ), it holds that:
which implies that the output of the optimal algorithm is the same and therefore TypicalHamming(X, ξ) = TypicalHamming(X, ξ ′ )
From the above claim, we showed that TypicalHamming(X, ξ) stays constant inside an open subcover of [−R − r/2, R + r/2]. To complete our proof for Lemma 4.6, we just extend the definition also in the breakpoints P, i.e
TypicalHamming(X, P 0 +P 1 2 ) ξ ∈ I 2 := (P 0 , P 1 ) TypicalHamming(X, P 1 ) ξ ∈ I 3 := [P 1 , P 1 ] ≡ P 1
TypicalHamming(X, P 1 +P 2 2 ) ξ ∈ I 4 := (P 1 , P 2 ) TypicalHamming(X, P 2 ) ξ ∈ I 5 := [P 2 , P 2 ] ≡ P 2 . . . An immediate consequence of Lemma 4.6 is that the following definition is well-defined. We also define the following collection of intervals and points: For any J i ∈ J : UnNormalized(X, ω) = exp (α i ω + β i ) ∀ω ∈ J i Moreover, we can compute exactly J and the constants (α i , β i ) for every J i ∈ J in O(poly(n)) time. 6
Proof. Using TypicalHamming we can reduce the optimization problem for a given ω as:
inf TypicalHamming(X,ξ)=k
h k (ω) (4.1)
We now focus on understanding the structure of the functions h k (ω) −B B ξ sup,k ξ inf,k ξ inf,k +ξ sup,k 2 ξ inf,k + 3Cr ξ sup,k − 3Cr Figure 3) , it is not difficult to check that every h k (ω) is a piecewise linear function with at most four 7 linear pieces 8 :
5 } are the breakpoints of h k in which the function changes its expression. Since each h k (ω) is a piece-wise function with at most 4 pieces, its minimum is also a piece-wise linear function. Consequently, for any given data-set X there is a partition of [−B, B] to a collection J consecutive intervals, J = {J 1 , · · · , J |J| } such that :
h k (ω) = α i ω + β i ∀ω ∈ J i or equivalently using eq. (4.1):
To conclude the proof of our lemma it suffices to show that the size of the collection J is polynomial and to describe a poly(n)-time procedure that computes the piece-wise linear function min k∈[n] h k .
Observe that to calculate min k∈[n] h k (ω), it suffices to know the relative ordering of h 1 (ω), · · · , h n (ω) for each ω ∈ [−B, B]. By continuity of h k , the relative order of a pair h k , h ℓ can not change inside an interval J where there is no solution of the equation h k (ω) = h ℓ (ω). Let us have Π [k,ℓ] = π [k,ℓ] 1 , · · · , π [k,ℓ] c k,ℓ be the ordered set of solutions of h k (ω) = h ℓ (ω) for every k = ℓ. Let us denote denote also as Π = k =ℓ Π [k,ℓ] ∪ {−B, B}. Observe that in any interval J of consecutive points of Π, the relative ordering of h k (ω), h ℓ (ω) for any k, ℓ ∈ [n] does not change inside J. Thus the minimizing function h ⋆ does not change inside the interval J. We can further subdivide the interval J, if it is needed into sub-intervals based on its breakpoints where h ⋆ is linear.
We present the algorithm to construct the set J:
Keep a list of the current order h k : Σ = {h i 1 ≤ · · · ≤ h in } Keep a list of the current liner form of h k : T = {h 1 : (α • To compute the constants (α i , β i ) : min k h k (ω) = α i ω + β i ∀ω ∈ J i , we can start from left to right. We compute the relative ordering of h 1 (−B), · · · , h n (−B). For each solution h k (ω) = h ℓ (ω), we update the relative ordering and for each breakpoint of h k we update its current linear form.
Lemma 4.13. For a given a date-set X = (X 1 , · · · , X n ) and its median m(X), there exists a poly(n)−time protocol that generates a sample from D general .
Proof. We use the decomposition described in Lemma 4.12. In the first round we sample from a discrete distribution on a poly(n)-cardinality domain to decide among the regions J 1 , · · · , J poly(n) . In the second round we simply apply conditional sampling from the corresponding either exponential or uniform which will be truncated on the region which was the outcome of the first round. More specifically:
Execute Construction − (J, α α α, β β β)(X = (X 1 , . . . , X n )) Let {(J i , α i , β i )} m be the poly(n)-decomposition of I = [−B, B] as described in lemma 4.12 // For any J i :
Toss a m-nary coin c := {1, · · · , m} with probability ( p 1 p , · · · , pm p ), correspondingly. if c outputs C then
Algorithm 7: Sample from D general
The correctness of our estimator is derived by Lemma 4.12.As we showed, the size of J = {(J i , α i , β i )} m is poly(n) and we need poly(n) time to compute {(J i , α i , β i )} m . Our final step is to toss a m-nary coin which needs an extra Θ(m) = poly(n) time.
In this section we discuss about the average-case time complexity of the algorithm PrivateMedian(X = (X 1 , . . . , X n )) which implements the algorithm A defined in (3.6). We consider running the algorithm for C = C 0 log n for some appropriate constant C 0 > 0. Note that this is different from the worstcase analysis section where it discusses the algorithm for a sufficiently large constant C > 0 and establishes its rate-optimality. We establish the following Corollary establishing that the algorithm remains rate-optimal up to logarithmic factors for this value of C.
Corollary 4.14. Suppose C = C 0 log n for some constant C 0 > 0. Suppose also ε ∈ (0, 1), D is an admissible distribution and A is the ε-differentially private algorithm defined in (3.6) for this value of C. Then for any α ∈ (0, r) and β ∈ (0, 1) for some
The corollary follows directly by applying for this value of C the Theorem B.5 (a slight generalization of Theorem 3.6, using a constant C > 0 possible scaling with n) and using the basic asymptotic formula that for A = Ω(1), it holds n/ log n = Ω (A) if and only if n = Ω (A log A). In particular, Corollary 4.14 combined with the results of Section 3.4 allows us to conclude that the algorithm where C scaling logarithmically with n remains rate-optimal up to logarithmic factors.
We now show that for appropriate tuning of the parameter C 0 > 0 and under a weak bound on the sampling size n, satisfied for instance by the third term in the almost optimal rate of Corollary 4.14, the algorithm runs in average-case inÕ(n) time. Proof. We have by the law of total expectation,
We now consider each term separately.
In the case where X ∈ H we need to check that X ∈ H to confirm the inclusion to the set H and then sample from the D restricted distribution. For the first part, standard O(n log n) counting binary searches and locating the value of the median m(X) suffices to certify that X ∈ H. Furthermore, given 
A similar notion to ε-differential privacy (Definition 1.1) is the notion of (ε, δ)-differential privacy.
Definition A.1. A randomized algorithm A is (ε, δ)-differential private if for all subsets S ∈ F of the output measurable space (Ω, F) and n-tuples of samples X 1 , X 2 ∈ R n , such that d H (X 1 ,
It is rather straightforward that (ε, δ)-differential privacy is a weaker notion to ε-differential privacy, in the sense that for any ε, δ > 0 any ε-differentially private algorithm is also an (ε, δ)differentially private algorithm.
Of importance to us in the design of the algorithm desicred in the main body of this work is the notion of the left (empirical) median of an n-tuple of samples. 
In this section we provide more details on the Extension Lemma as stated in Proposition 2.1.We repeat it here for convenience. Proposition A.3 ("The Extension Lemma" Proposition 2.1, [BCSZ18a] ). LetÂ be an ε-differentially private algorithm designed for input from H ⊆ R n with arbitrary output measure space (Ω, F). Then there exists a randomized algorithm A defined on the whole input space R n with the same output space which is 2ε-differentially private and satisfies that for every X ∈ H, A(X) d =Â(X).
Albeit the generality of the result, as mentioned in the conclusion of [BCSZ18a] , the Extension Lemma does not provide any guarantee that the extension of the algorithmÂ can be made in a computationally efficient way. In this work, as described in the main body of the paper, we show that the Extension Lemma is applicable in the context of median estimation, and furthermore the extension can be implemented in polynomial time. Hence, naturally, to perform this extension in a computationally efficient way we don't use the Extension Lemma as a "blackbox" but rather need to use the specific structure of the extended private algorithm, by digging into the proof of it in [BCSZ18a, Proposition 2.1.].
The density of the extended algorithm -general For simplicity, we present the density of the extended algorithm under certain assumptions that will be correct in the context of our work. As everywhere in this paper, let us first focus on the case the input space is M = R n equipped with the Hamming distance and the output space is the real line equipped with the Lebesgue measure. Furthermore let us assume also that for any X ∈ H the randomised restricted algorithmÂ(X) follows a real-valued continuous distribution with a density fÂ (X) with respect to the Lebesque measure, given by Equation (3.4) . We repeat here the definitions for convenience;
where the normalizing constant iŝ
As claimed in Section 3.3 the normalizing constantẐ does not have an index X because the right hand side of (A.3) takes the same value for any X ∈ H. This follows by the following Lemma. Note: For readability reasons, we omit the proofs of the below propositions in the following section Lemma A.4. Suppose C > 1/2. Then for any X ∈ H,
Then from the proof of the Extension Lemma [Section 4, [BCSZ18a] ] we have that the "extended" ε-differentially private algorithm A on input X ∈ R n admits also a density given by
For reasons of completeness we state the corollary of the Extension Lemma that establishes that in our setting the algorithm A satisfies the desired properties of the Extension Lemma.
Proposition A.5. Under the above assumptions, the algorithm A is ε-differentially private and for every X ′ ∈ H, A(X ′ ) d =Â(X ′ ).
As a technical remark note that for the density in equation (A.4) to be well-defined we require that for every X ∈ R n the "unnormalized" density function
is integrable and has a finite integral as well. Both conditions follows by the following Lemma, which establishes -among other properties -that G X is a continuous function almost everywhere and therefore it has a finite integral.
Lemma A.6. Suppose the above assumptions hold and fix X ∈ R n . Then,
, whereẐ is given in (A.3) .
Furthermore, it holds 0 ≤ ω∈R G X (ω)dω ≤ 1.
Plugging in now the densities of the restricted algorithm (Equations (A.2)) to the general extended algorithm (Equations (A.6)) and finally using also that according to Lemma A.4 the normalizing constant for the restricted algoriths is independent of X ′ ∈ H, we have
where ω ∈ [−R − 4Cr, R + 4Cr] and Z X is the appropriate normalizing constant.
Proof of Lemma A.4. Since X = 0 ∈ H and the left hand side for X = 0 evaluates to the right hand side, it suffices to show that the left hand side does not depend on the value of m(X).
Lrn dω.
Now since X ∈ H we have m(X) ∈ [−R − r/2, R + r/2]. Hence, using C > 1/2 we have [−3Cr, 3Cr] ⊆ I − m(X). Therefore the last summation of integrals simplifies to
which does not depends on X as we wanted.
For the proof of Proposition A.5, we start with using the [BCSZ18a, Lemma 4.1.] applied in our setting, which gives the following Lemma.
Lemma A.7. Let A ′ be a real-valued randomized algorithm designed for input from H ′ ⊆ R n . Suppose that for any X ∈ H ′ , A ′ (X) admits a density function with respect to the Lebesque measure f A ′ (X) . Then the following are equivalent
(1) A ′ is ε-differentially private on H;
(2) For any X,
almost surely with respect to the Lebesque measure.
We now proceed with the proof of Proposition A.5.
Proof of Proposition A.5. We first prove that A is ε-differentially private over all pairs of input from R n . Using Lemma A.7 it suffices to prove that for any X 1 , X 2 ∈ H,
almost surely with respect to the Lebesque measure. We establish it in particular for every ω ∈ R. Notice that if ω ∈ I, both sides are zero from Lemma A.6. Hence let us assume ω ∈ I. Let X 1 , X 2 ∈ R n . Using triangle inequality we obtain for every ω ∈ I,
which implies that for any X 1 , X 2 ∈ M,
Therefore using the above two inequalities we obtain that for any X 1 , X 2 ∈ R n and ω ∈ I,
as we wanted. Now we prove that for every X ∈ H, A(X) d =Â(X). Consider an arbitrary X ∈ H. We know thatÂ is ε/2-differentially private which based on Lemma A.7 implies that for any X, X ′ ∈ H
almost surely with respect to the Lebesque measure. Observing that the above inequality holds almost surely as equality if X ′ = X we obtain that for any X ∈ H it holds
almost surely with respect to the Lebesque measure. Using that fÂ (X) is a probability density function we conclude that in this case Z X = fÂ (X) (ω)dω = 1.
Therefore
almost surely with respect to the Lebesque measure and hence
almost surely with respect to the Lebesque measure. This suffices to conclude thatÂ(X) d = A(X) as needed.
The proof of Proposition A.5 is complete.
Proof of Lemma A.6. First notice that if ω ∈ I, from (3.4) for any X ′ ∈ H, fÂ (X ′ ) (ω) = 0. Therefore indeed
We prove now that for all X ′ ∈ H, the function exp ε 2 d H (X, X ′ ) fÂ (X ′ ) (ω) is R-Lipschitz on I. The claim then follows by the elementary real analysis fact that the pointwise infimum over an arbitrary family of R-Lipschitz functions is an R-Lipschitz function. Now recall that for all a, b > 0 by elementary calculus, |e −a − e −b | ≤ |a − b|. Hence, for fixed X ′ ∈ H, using the definition of the density in equation (A.2), we have for any ω, ω ′ ∈ I,
Now combining with Property B.1 we conclude
In particular, exp ε
. The proof of the Lipschitz continuity is complete. The final part follows from the fact that G is non-negative by definition and again by definition for arbitrary fixed X ′ ∈ H, fÂ (X ′ ) integrates to one and upper bounds pointwise the function G X . Consider two data-sets X := {x 1 , x 2 , . . . , x κ , C 1 , . . . , C n−κ } Y := {y 1 , y 2 , . . . , y κ , C 1 , . . . , C n−κ } ∈ H. Without loss of generality we assume that the common part is sorted in an increasing order, i.e. it holds C 1 ≤ . . . ≤ C n−κ .
Notice that the left median of data-set can be altered by the addition of M ′ new data-points only to some data-point among the ⌊M ′ /2⌋ + 1 data-points on the right and the ⌊M ′ /2⌋ + 1 datapoints on the left of it. Hence the interval [C ⌊ n−κ 2 ⌋ , m(X)] ∪ [m(X), C ⌊ n−κ 2 ⌋ ] (respectively the interval
there can be at most ⌊ κ 2 ⌋ + 1 data-points of the data-set X (respectively of the data-set Y ).
Therefore, leveraging the definition of sensitivity set, we have that
which implies by the triangle inequality
Proof. We start with the following elementary property is important in what follows for the proof of Lemma 3.3.
Property B.1 (Lemma 9.2. in [BCSZ18c] ). For any a, b > 0 the function f : R → R, with f (x) = min{a|x|, b}, for all x ∈ R, satisfies the triangle inequality, f (x + y) ≤ f (x) + f (y) for all x, y ∈ R.
Additionally, using Lemma 3.2 we have for any X, Y ∈ H,
We firstly analyze the non-normalized ratio corresponding to two data-sets X, Y :
Furthermore for the ratio of the two normalizing constants we have
Combining the two final inequalities above we conclude
The proof is complete.
Lemma 3.4 follows from the following more general lemma where C > 1 is allowed to grow with n while in the context of Lemma 3.4 is considered in the asymptotic analysis as a constant.
Lemma B.2. Suppose C > 1, possibly scaling with n, and α ∈ (0, r), β ∈ (0, 1). For some
where the probability is with respect to the randomness of the algorithmÂ(X).
Proof.
•
Step 1: Observe: Since C > 1/4 it holds R + 4Cr > R + r. Hence, by change of variables q = q − m(X),
Step 2:Now using that m(X) ∈ [−R − r/2, R + r/2] and by change of variables q = q − m(X) we have:
Hence we conclude for all X ∈ H
From this and elementary asymptotics we conclude that for C > 1 with
it holds for all X ∈ H, P[|Â(X) − m(X)| ≥ α] ≤ β. Using that α ≤ r the above sample complexity bound simplifies to
The proof of the Lemma is complete.
We need the following technical lemma. 
Before proving the Lemma B.3, we show how it can be used to prove the following more general version of Lemma 3.5 where C > 0 is allowed to potentially scale with n.
Lemma B.4. Let D be an admissible distribution, β ∈ (0, 1), n ≥ 3 and X = (X 1 , . . . , X n ) consisting of i.i.d. samples from D. Suppose C > 5, possibly scaling with n, which satisfies 4Ce exp − 2C 27 < 1/2. Then for some E > 0,
Proof of Lemma B.4. We begin by applying Lemma B.3 for sufficiently large E > 0.
We will choose T = C ′ (C) 2 log 1 β for appropriate choice C ′ (C) > 0 with C ′ (C) = Θ(1/C) as C grows. We claim that for any choice of such a function C ′ (C) and in particular choice of T for sufficiently large E > 0 it holds
which suffices for us to apply the Lemma. To prove this note that the equivalently we need
Lr . Hence, using that C ′ (C) = Θ(1/C) by choosing E > 0 sufficiently large but constant, the choice of T is indeed valid for apply the Lemma B.3.
We choose T = C ′ (C) 2 log 1 β for appropriate C ′ (C) > 0 with C ′ (C) = Θ(1/C) as C grows, so that using Lemma B.3 both the two probabilistic guarantees hold with probability at least
Notice that this is possible since this is the exact scaling of T for which (8Ce exp − C 8 ) ⌈T ⌉ = Θ (β) . Taking now E > 0 further sufficiently large but still constant since n ≥ E log 1 β L 2 r 2 we can make sure the probabilistic guarantees hold with probability at least 1 − β. Combining the above, with probability at least 1 − β the following event holds: for all κ ∈ [T, Lr
In words, all but, the closest to m(X), T = C ′ (C) 2 log 1 β intervals on the left of m(X), and all but, the closest to m(X), T = C ′ (C) 2 log 1 β interval on the right of m(X), satisfy their corresponding constraints described in the typical set H. Now let us consider a data-set X for which (B.2) and (B.3) hold. We show that given these events one can construct an X ′ ∈ H satisfying the conditions described in the event considered in Lemma B.4. First recall that as T ≤ Lr 4C n since Lr ≤ 1/2 and C > 5, it necessarily holds T ≤ n/40. Since we assume n ≥ 3 it holds T < n/2 − 2. Now, as there are at least n/2 − 2 data-points on the left of m(X) and n/2 − 2 data-points on the right of m(X) we can modify X by choosing arbitrary T data-points on the right of m(X) and arbitrary T data-points on the left of m(X) and change all their position to m(X). Notice that such a change produces a new data-set X ′ which has Hamming distance 2T = C ′ (C) log 1 β with X and has the same median with X, m(X) = m(X ′ ). Notice that as we moved data-points closer to the median, all satisfied constraint from H by the data-set X according to (B.2) and (B.3) continue to be satisfied from X ′ . On top of this, since at least 2T data-points of X ′ take now exactly the value of the left empirical median, the data-set X ′ necessarily satisfies also the, potentially violated by X, constraints corresponding to the T intervals on the left of m(X ′ ) = m(X) and the T intervals on the right of m(X ′ ) = m(X). We conclude that X ′ satisfies all the constraints described in H and therefore, X ′ ∈ H, which completes the proof.
For the rest part we focus on proving Lemma B.3.
Proof of Lemma B.3. We start by noticing that by identical reasoning as the derivation of inequality (14) of [BA19] in the proof of Lemma 3 in [BA19] we have for t = r/2 ∈ [0, r] P (|m(X) − m(D)| ≥ r/2) ≤ 2e −nL 2 r 2 /8 .
Now we focus on proving the first out of the two probabilistic guarantee,
as the second follows naturally by the symmetric argument around zero. We make the following three observations. First, observe that generating i.i.d. samples from D and then determining the left empirical median m(X) based on the realization of X 1 , . . . , X n is equal in law with first sampling the place of the left empirical median m(X) based on its distribution and sampling uniformly at random an X i so that X i = m(X) and then generating ⌈ n−1 2 ⌉ − 1(n is even) i.i.d. samples from D conditional to be on the left of m(X) and generating ⌈ n−1 2 ⌉ i.i.d. samples from D conditional to be on the right of m(X). To model the underlying the randomness we can define for each i, the trinary random variables where C i = −1 if the sample i is chosen to be on the left of m(X), C i = 0 if the sample equals m(X) and C i = 1 if they are chosen to be on the right.
Second, using the fact that D has density lower bounded by L in [m(D) − r, m(D) + r], observe that our distribution D can be decomposed as a mixture,
for some other probability measure D ′ on the reals. Now using the first observation, we first sample the position of m(X) and describe the sampling of X i as follows. If C i = 0 we simply set X i = m(X).
For the other two cases, we assume C i = 1 as the other case is symmetric. If m(X) − m(D) ≥ r then we sample from the distribution 1 − rL 2 D ′ conditional on being on the right of m(X). If m(X) − m(D) ≤ r then we first flip a coin B i d = Bernoulli( rL 2 ) and with probability rL 2 (that is when B i = 1) we sample from Unif[m(D) − r, m(D) + r] conditional on being on the right of m(X) and with probability 1 − rL 2 (that is when B i = 0) we sample from some distribution D ′ conditional on being on the right of m(X).
Third, observe that both the event of interests in the statement Lemma B.3 of becomes less probable when we restrict ourselves to only a subset of the n samples. Hence, since we want to prove a lower bound on the probability of the event we can restrict ourselves to an arbitrary subset. Now, using (B.4) by neglecting an event of probability 2e −nL 2 r 2 /8 ≤ e −Θ(L 2 r 2 n) from now on we condition on |m(X)−m(D)| ≤ r/2. Now using the three observations above, we restrict ourselves only on the n 1 ≤ n samples that satisfy B i = C i = 1, that is they are samples from Unif[m(D)−r, m(D)+r] conditional on being on the right of m(X). We denote these samples by X 1 , . . . , X n 1 for simplicity. Notice that Unif[m(D) − r, m(D) + r] conditional on being on the right of m(X) is just distributed as Unif[m(X), m(D) + r]. Hence, conditioning on the value of n 1 , the density of the conditional distribution of each X 1 , . . . , X n 1 given the m(X) can be straightforwardly check to satisfy for each i = 1, 2, . . . , n 1 , 
Since m(X) = X i for some i by definition of the left empirical median, it suffices to prove that for J κ := (m(X), m(X) + Cκ Ln ], κ = ⌈T ⌉, ⌈T ⌉ + 1, . . . , ⌊ Lr 2C n⌋ − 1 and sequence of events
Using a union bound it suffices to show
Observe that as we are conditioning on |m(X) − m(D)| ≤ r/2 for all κ of interest
Hence using (B.6) we have that, conditioned on n 1 , for each i ∈ [n 1 ] and κ,
Furthermore recall that n 1 d = Binom ⌊ n−1 2 ⌋, Lr 2 and that it holds κ ≤ Lrn 2C . Since C > 5 by standard concentration inequalities, we have that with probability 1 − e −Θ(L 2 r 2 n) , it holds for all κ of interest κ < Lrn 9 < n 1 2 < Lrn.
In what follows we condition on the event (B.8). Suppose κ = ⌈T ⌉. Then using (B.7) by definition the probability of A c ⌈T ⌉ is at most the probability a sample from a binomial distribution with N := n 1 draws and probability 2 r |J ⌈T ⌉ | = 2C⌈T ⌉ nLr is at most ⌈T ⌉. Now conditioning on n 1 and denoting the Binomial random variable by Z we have by the additive form of the Chernoff's inequality,
Using now that we condition on (B.8) it holds 2Lnr 9 < n 1 < 2Lrn and T < Lnr 2C⌈T ⌉ which since C > 5 > 9 7 gives that
Now for every κ > ⌈T ⌉ notice that the event A c κ ∩ κ−1 s=0 A s can happen if and only if κ of the samples belong in J κ−1 and the rest n 1 − κ samples belong to J c κ . Therefore using the above observations and (B.7),
where we used the elementary inequalities m m ′ ≤ me m ′ m ′ , 1 + x ≤ e x and that by definition n 1 ≤ n. The last displayed inequality conditioned on the event (B.8) implies
Using (B.9) for the first term and since 4Ce exp − 2C 27 < 1/2 a geometric summation over κ ≥ ⌈T ⌉ for the rest terms, we have that conditional on (B.8),
Taking now into account the probability of the conditioned event we have (B.8),
where in the last line since C 8 > 2C 27 and 8Ce > 1 under our assumptions it holds for all T ≥ 0
The proof is complete.
B.5 Proof of Theorem 3.6
We establish instead the following slightly more general result which does not assume that C is a constant, but could scale with n.
Theorem B.5. Suppose C > 0, possibly scaling with n, is bigger than a sufficiently large constant, ε ∈ (0, 1), D is an admissible distribution and A is the ε-differentially private algorithm defined above. Then for any α ∈ (0, r) and β ∈ (0, 1) for some
Proof. Let X = (X 1 , . . . , X n ) the n-tuple of i.i.d. samples from D. Let us use a parameter γ ∈ (0, 1) which we later choose a polynomial function of β. We consider the event
where C ′ = C ′ (C) is chosen to satisfy the conclusion of Lemma B.4. In particular it holds C ′ (C) = Θ( 1 C ) as C grows to infinity. Notice that since α ≤ r for some n = O log 1 γ L 2 α 2 it holds n ≥ D log 1 γ L 2 r 2 for the D > 0 defined in Lemma B.4. Furthermore, we can assume C > 5 is sufficiently large such that 4Ce exp − 2C 27 < 1/2. Hence, by applying Lemma B.4 we have
Now conditioning on X ∈ T γ we have that there exists an X ′ ∈ H with d H (X, X ′ ) ≤ C ′ log 1 γ and m(X ′ ) = m(X). Since the algorithm A is ε-differentially private by its definition, we have that A(X) and A(X ′ ) assigns to each output value the same probability mass up to a multiplicative factor of
where in the last inequality we use that ε < 1. Hence 
(B.14)
Using classical results we have that for some n = O
Combining the (B.14) and (B.15) we have for some n = O log( 1 γ )
or, combining with (B.12),
or, combining with (B.11),
Since C ′ (C) = Θ( 1 C ) we can assume C > 0 sufficiently large so that C ′ (C) < 1 2 . Hence for these values of C some n = O log( 1 γ )
Choosing γ appropriately of the order γ = Θ β The proof is complete.
Proof of Proposition 3.7. We argue by contradiction and consider an algorithm A satisfying the negation of the statement of the proposition. We first prove that n = Ω r 2 log( 1 β ) α 2 (C.1) and then
Notice that combined the lower bounds imply
where for the last equality we use Lr ≤ 1 2 . The last displayed equation yields the desired contradiction. To prove C.1 notice that all uniform distributions which are supported on an interval of width 2r inside [−R − r, R + r] are admissible. Observe now that for a uniform distribution the mean and the median of it are identical. For this reason, A to satisfy the negation of our statement, it should learn the mean of these uniform distributions of width r from n samples with accuracy α with probability 1 − β. Standard learning theory implies that it should hold n = Ω r 2 log( 1 β ) α 2 .
We now turn to C.2. Notice that if Lr = 1 2 the lower bound on n is trivial. Hence, to establish C.2, we focus on the case where Lr < 1 2 . Recall the standard fact that learning the parameter p of a Bernoulli random variable Bernoulli (p) at accuracy γ > 0 with probability 1 − β requires Ω log 1 β γ 2 samples.
We know fix p. We construct the admissible distribution D which assigns probability mass (1 − 2Lr)(1 − p) at −2r, probability mass (1 − 2Lr)p at 2r and with probability 2Lr samples from the uniform distribution on [−r, r]. It can be easily checked that D is admissible with the assumed parameters and median p 1 L − 2r + r − 1 2L . In particular, learning the median at accuracy α is equivalent with learning the parameter p at accuracy α 2L 1−2Lr which from our assumption on Lr < 1 2 is Θ (1 − 2Lr) −1 Lα . Furthermore, notice that for learning the parameter p using the samples from D one needs to focus only the samples from which are equal to either 2r or −2r. Therefore the task of learning the median of D with n samples at accuracy α, reduces to learning the parameter p of a Bernoulli(p) distribution with N 1 = Binom(n, 1 − 2Lr) samples at accuracy Θ (1 − 2Lr) −1 Lα . Using the standard fact mentioned above and this equivalence, we have that conditional on the event, call it E α,β (D), that we can learn the median of D with n samples at accuracy α it holds
Now recall that we assume that A can learn the median of D with n samples at accuracy α holds with probability at least 1 − β. Hence P (E α,β (D)) ≥ 1 − β. Combined with the last observation of the paragraph above, we conclude
Using that E[N 1 ] = (1 − 2Lr)n and that β ∈ (0, 1 2 ) we have
(1 − 2Lr)n = Ω   log 1 β L 2 α 2 (1 − 2Lr) 2   .
Using that Lr < 1 2 we have n = Ω log 1 β L 2 α 2 (1 − 2Lr) . The proof is complete.
Proof of Proposition 3.8. We argue by contradiction and consider an algorithm A satisfying the negation of our statement. Since R > 2α, for η > 0 sufficiently small it holds 2α+η < R. We consider a D 1 which assigns mass 1 2 − Lr to −r − R, mass 1 2 − Lr to r + R and with probability 2Lr samples from the uniform distribution on [−r, r] and a D 2 which assigns mass 1 2 − Lr to −r − R, mass 1 2 − Lr to r + R and with probability 2Lr samples from the uniform distribution on [−r +2α+η, r +2α+η]. Note that they are both admissible with the desired parameters and it also holds m(D 1 ) = 0, m(D 2 ) = 2α + η.
Using the accuracy guarantee of A and that the medians of the two distribution have distance strictly bigger than 2α, it necessarily holds P X 1 ,X 2 ,...,Xn The two distribution can be coupled in the following way: we first sample from D 1 . If it falls in [−r + 2α + η, r] we keep the sample from D 1 as is, and translate it by +2r if it falls into [−r, −r + 2α + η], to form a sample from D 2 . In particular, notice that by sampling two n-tuples X, X ′ ∈ R n of samples in an i.i.d. sense from D 1 and D 2 respectively, under this coupling the d H (X, X ′ ) follows a Binom (n, (2α + η)L). Hence using the definition of ε-differential privacy E e −εd H (X,X ′ ) P Using the moment generating function of the Binomial distribution we conclude 1 − L(2α + η) 1 − e −ε n ≤ β 1 − β which by basic asymptotics since β < 1/2 translates to n = Ω log 1 β εL(α+η) . Since η > 0 can be taken arbitrarily small, the proof of the proposition is complete.
In this last subsection, for the sake of completeness, we will present how we can simulate a random generator for Categorical, Bernoulli, Uniform, Laplace, (Negative) Exponential Distribution and their truncated versions in an interval I in O(1) time and O(1) random queries of Unif[0, 1] using the standard "inverse-CDF" sampling method.
The general inverse-CDF sampling method works as follows:
//Suppose that we want to simulate a distribution D s.t its cdf F D is invertible.
1. Generate a random number u from the standard uniform distribution in the interval [0, 1], e.g. from U ∼ Unif[0, 1].
2. Find the inverse of the desired CDF, e.g. F −1 D (x). 3. Output X = F −1 D (u).
Indeed, the computed random variable X follows the distribution D, since
Pr(X ≤ x) = Pr(F −1 D (U ) ≤ x) = Pr(U ≤ F D (x)) = F D (x). 
We continue with a k−nary coin, known as Categorical distribution, which is a discrete probability distribution that describes the possible results of a random variable that can take on one of k possible categories, with the probability of each category separately specified.
u ← Sample from U ∼ Unif[0, 1] Compute CDF vector (q 0 , q 1 , q 2 , · · · , q k−1 , q k ) = (0, p 1 , p 1 + p 2 , · · · , k−1 i=1 p i , k i=1 p i = 1) for i ∈ [k] do if q i−1 ≤ s < q i then s ← o i return s Algorithm 9: k−nary coin {o 1 , · · · , o k } with probability p 1 , · · · , p k
Our next probability distibution is the truncated (Positive/Negative) Exponential distribution D TruncExponential ∼ exp (αω + β) ω ∈ I = [left, right].
• If α = 0 then the actual distribution is the uniform.
• If α = 0 we get the CDF of D TruncExponential is F D TruncExponential (x|α, β) = exp (αx + β) − exp (α · left + β) exp (α · right + β) − exp (α · left + β) .
Thus we get that: Thus we get that: 