Since I was confused by median.scm which is no longer used (and doesn't conform srfi document),
I tried to send PR for remove it; however, the current repo seems to contain other leftovers
from earlier versions; e.g. srfi-132.sld refers to median.scm but it no longer seems to be kept
in sync with the spec.

Shall I go ahead and make PR removing obsoleted files, or at least move obsoleted files
into subdirectory?



On Tue, Jan 24, 2017 at 5:24 PM, Shiro Kawai <xxxxxx@gmail.com> wrote:
Aha!  I understood.  I looked at select.scm and saw %%vector-select recursed and
blindly assumed input length * recurse depth complexity, but in every iteration
the expected length shrinks in geometric series, so the sum is constant multiples
of input size.
Thanks for enlightenment.


On Tue, Jan 24, 2017 at 5:10 PM, Alex Shinn <xxxxxx@gmail.com> wrote:
On Wed, Jan 25, 2017 at 11:23 AM, Shiro Kawai <xxxxxx@gmail.com> wrote:
Yes, vector-select is O(n + k ln k), so if k is fixed, it's O(n).  However, in median case k = n/2 and you can't fix k, can you?

vector-select is O(n), independent of k, as using the
algorithm I provided in selection.scm.  See

A simple (untested) linear version of vector-find-median is then:

(define (vector-find-median < v knil . o)
  (let ((len (vector-length v)))
    (cond
     ((zero? len) knil)
     ((odd? len) (vector-select! < (vector-copy v) (+ 1 (quotient len 2))))
     (else
      (let ((mid (quotient len 2))
             (v (vector-copy v))
             (mean (if (pair? o) (car o) (lambda (a b) (/ (+ a b) 2)))))
        (mean (vector-select! < v mid) (vector-select! < v (+ mid 1))))))))

-- 
Alex