home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!haven.umd.edu!darwin.sura.net!spool.mu.edu!agate!nima.berkeley.edu!shein
- From: shein@nima.berkeley.edu (Soren Hein)
- Newsgroups: comp.programming
- Subject: Partial sort/Nearest neighbor
- Date: 13 Nov 1992 13:20:37 GMT
- Organization: U.C. Berkeley -- ERL
- Lines: 21
- Distribution: world
- Message-ID: <1e0a35INN511@agate.berkeley.edu>
- NNTP-Posting-Host: nima.berkeley.edu
-
- I have a small list (9 or 25 elements) of integers between 0 and 255.
- My goal is to find the average of the K elements which are closest in
- absolute value to a given element in the list. K is typically about
- half of the list length. I need the algorithm to be as fast as possible;
- space consumption is no problem.
-
- What I'm doing at the moment is to create another list whose elements
- are the absolute differences between the original elements and the given
- element. Then I sort the new list, keeping track of the permutations.
-
- This is needlessly slow, because I don't need the K elements to be in
- order, and I don't need the remaining elements to be in order either.
-
- [The above problem arises in image processing and is known as
- "nearest neighbor filtering".]
-
- Please e-mail any suggestions to shein@robotics.berkeley.edu, and
- I will summarize if there is interest.
-
- Thanks,
- /Soren
-