From: Robert Klemme Date: 2013-06-18T15:01:53+09:00 Subject: Re: Compare and sort one array according to another. --047d7b6d9da40f425004df677372 Content-Type: text/plain; charset=ISO-8859-1 On Mon, Jun 17, 2013 at 11:35 PM, Douglas Seifert wrote: > You have said that the size of your two arrays is small, so the fact that > the find_index based solution is o(n^2) probably doesn't matter. > Yes, that's what I was figuring. Your analysis is spot on. > For kicks, a o(n) solution compared to the o(n^2) solution here: > > https://gist.github.com/seifertd/5800639 > > It involves precomputing a lookup index for the data you need to sort. > Your "gen_lookup:" is exactly what I'd did for larger arrays. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ --047d7b6d9da40f425004df677372 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable



On Mon, Jun 17, 2013 at 11:35 PM, Douglas Seifert <doug@dseifert.n= et> wrote:
You have said that the size= of your two arrays is small, so the fact that the find_index based solutio= n is o(n^2) probably doesn't matter.

Yes, that's what I was figuring.= =A0Your analysis is spot on.
=A0
=A0For kicks, a o(n) solution compared to the o(n^2) solut= ion here:

= https://gist.github.com/seifertd/5800639

It involves= precomputing a lookup index for the data you need to sort.

Your "gen_lookup:" is exactly what I= 9;d did for larger arrays.

Kind regard= s

robert


--
remember.guy do |as, often| as.you_can - without end<= br>http://blog.rubybestpract= ices.com/
--047d7b6d9da40f425004df677372--