home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.programming
- Path: sparky!uunet!UB.com!pacbell.com!decwrl!concert!gatech!rpi!batcomputer!munnari.oz.au!manuel.anu.edu.au!csc.canberra.edu.au!fir!eyal
- From: eyal@fir.canberra.edu.au (Eyal Lebedinsky)
- Subject: Re: is it possible to find max & next smallest in one pass?
- Message-ID: <eyal.728121809@fir>
- Sender: news@csc.canberra.edu.au
- Organization: Info Sci & Eng, University of Canberra, AUSTRALIA
- References: <1993Jan25.224200.7195@bnlux1.bnl.gov>
- Date: 27 Jan 93 08:03:29 GMT
- Lines: 22
-
- In <1993Jan25.224200.7195@bnlux1.bnl.gov> murphy@sscdaq.phy.bnl.gov (Michael Murphy) writes:
-
-
- >>jos@and.nl (Jos Horsmeier) writes:
-
- >>>In article <asean.727858796@armstrong.ecn.purdue.edu> asean@armstrong.ecn.purdue.edu (Sean Ahern) writes:
- >>>|jagrant@emr1.emr.ca (John Grant) writes:
- >>>|>Given an array of values, is it possible to find the maximum of
- >>>|>the array and the next smallest value in a single pass? The reason
- >>>|>I want it in one pass, is that the array is actually a data file
- >>>|>of a million float values.
-
- Well, the usual way of finding the highest-n in a list is to simply
- create a priority queue. This data structure is cheap to maintain and
- most alg books give a reasonable description of it.
-
- For just the top two (max and next-smallest) it boils down to a simple
- test while keeping the so-far best and next. Insted of just doing 'if
- x[] > max then max = x[]' you also check to see if it second best (if it
- is best then the old best is now second-best).
-
- Then again, I may have missed the point of the question.
-