Update: The crux of the problem is that in order to achieve the $O(n\log(n))$ time complexity, one needs in the order of $O(n)$ storage.
No, $O(n\log(n))$ is the lower theoretical bound for the time complexity of (see (1)) selecting the $k^{th}$ element among all $\frac{n(n-1)}{2}$ possible $|x_i - x_j|: 1 \leq i \lt j \leq n$.
You can get $O(1)$ space, but only by naively checking all combinations of $x_i-x_j$ in time $O(n^2)$.
The good news is that you can use the $\tau$ estimator of scale (see (2) and (3) for an improved version and some timing comparisons), implemented in the function
scaleTau2()
in the R
package robustbase
. The univariate $\tau$ estimator is a two-step (i.e. re-weighted) estimator of scale. It has 95 percent Gaussian efficiency, 50 percent breakdown point, and complexity of $O(n)$ time and $O(1)$ space (plus it can easily be made 'online', shaving off half the computational costs in repeated use -- although you will have to dig into the R
code to implement this option, it is rather straightforward to do).
- The complexity of selection and ranking in X + Y and matrices with sorted columns
G. N. Frederickson and D. B. Johnson, Journal of Computer and System Sciences
Volume 24, Issue 2, April 1982, Pages 197-208.
- Yohai, V. and Zamar, R. (1988). High breakdown point estimates of regression by means of the minimization of an efficient scale. Journal of the American Statistical Association 83 406–413.
- Maronna, R. and Zamar, R. (2002). Robust estimates of location and dispersion for high-
dimensional data sets. Technometrics 44 307–317
Edit To use this
- Fire up
R
(it's free and can be downloaded from here)
- Install the package by typing:
install.packages("robustbase")
- Load the package by typing:
library("robustbase")
- Load your data file and run the function:
mydatavector <- read.table("address to my file in text format", header=T)
scaleTau2(mydatavector)