Surely you don't mean linear in k but linear in n? You have to examine at least every item to find the maximum. If it's linear in n then so is /: and /:~ (albeit with a larger factor) for vectors of many datatypes.
----- Original Message ----- From: Henry Rich <[EMAIL PROTECTED]> Date: Thursday, March 20, 2008 12:42 Subject: RE: [Jprogramming] Biggest values from list To: 'Programming forum' <[email protected]> > Agreed, use /: . In a scalar language the way to do > this is > to build a heap and then pull the top k items, which takes > linear time if k is much less than n. I suspect this is not > very efficient in J. > > Henry Rich > > > -----Original Message----- > > From: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] On Behalf Of Roger Hui > > Sent: Thursday, March 20, 2008 11:15 AM > > To: Programming forum > > Subject: Re: [Jprogramming] Biggest values from list > > > > If you just want the largest value (and its position) then > > it can be done conveniently without sorting or grading. > > If you want the largest k values where k>1 then > > the most convenient way is to grade, along the lines > > that Raul Miller has shown. > > > > Why do you want to avoid sorting/grading? In J, for vectors > > of many datatypes, including the integer and floating point > > datatypes, sorting and grading takes linear time. > > > > > > > > ----- Original Message ----- > > From: Nick Kostirya <[EMAIL PROTECTED]> > > Date: Thursday, March 20, 2008 2:25 > > Subject: [Jprogramming] Biggest values from list > > To: [email protected] > > > > > Hello, All > > > > > > Can you please provide me with the most optimal way of > picking > > > out a > > > given number of elements with the biggest values from a huge list? > > > > > > The values and the elements' positions in a list are a > matter of > > > interest. > > > > > > Can we manage this without sorting? ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
