Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 01 Sep 2011 06:03:14 -0500 Date: Thu, 01 Sep 2011 04:02:47 -0700 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows NT 5.2; WOW64; rv:6.0) Gecko/20110812 Thunderbird/6.0 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Using Java Classes to Sort a Small Array Quickly References: <86c4a53b-1ca1-48a8-b954-c01bd449278a@s35g2000prm.googlegroups.com> <4e5f4baa$0$2497$db0fefd9@news.zen.co.uk> In-Reply-To: <4e5f4baa$0$2497$db0fefd9@news.zen.co.uk> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Lines: 33 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 70.230.204.158 X-Trace: sv3-3HQJiJ7MHRwh2dL6Wq4Td2PSRuCr+Ufj/hu0xfKLmnZLySrsJqRE2NhJgl2j9yOUqdNAGY7XkF47feU!UQvcbrgzyLGdraSNGNo33sAveCg7/u4DhJNtE1+/hLoMQO6aYnG34RR4hDZgJavctC1sv0cwaL1L!3jCxLfARWvfwmf36lZoJDCTbbTBbI8byjuGF41Cc9PbVSA8= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2644 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7522 On 9/1/2011 2:08 AM, RedGrittyBrick wrote: > On 01/09/2011 03:48, KevinSimonson wrote: >> I have an named that has twelve values. Today I >> added an instance variable to it, a named. >> The engineer I'm working with asked me to write a static method in >> class that returns an array ofs sorted >> alphabetically by this value. >> >> >> is there a way in Java to >> sort an array ofs (or perhaps more to the point to sort an >> array ofs) that runs in O(N) time? Or even that runs in >> O(N^2) time but faster than InsertionSort? I'd appreciate any >> information anyone can give me on this. > > > If I was sorting twelve elements, I would consider myself utterly > deranged if I found myself worrying about the sort algorithm. > > > > If the static method will be called millions of times per second, you > might want to cache the sort results rather than pointlessly repeating > the sort, but only after measuring a performance problem and working out > if this method really needs to be called that often. > The simplest solution to this would be to use Arrays.sort, and forget about it. If anything else, such as caching, is needed, there will be a reminder in the form of Arrays.sort taking a significant fraction of the run time. Patricia