4/26 Is it possible to find the median value of a group of numbers in O(N)?
\_ Yes, but in practice people use an O(n log n) solution. -op
\_ Yes; there is a fairly simple randomized algorithm which does this
with high probability, and a non-trivial deterministic algorithm
that people don't usually bother with. If N is really large, it's
probably worth your time to look into the former (see section
3.3 of Motwani&Raghavan, where it's called "LazySelect"; the
original paper is Floyd&Rivest, CACM 18:165-172, 1975, but it may
well be rather unreadable; M&R also gives refs for the deterministic
algorithms). -alexf
\_ you can sort numbers in O(n) with radix sort and counting sort.
\_ sorting is normally assumed to be O(n lg n)
\_ and your point is...? |