Re: How to speed up two arrays compare.

2009-02-12 Thread kevin liu
Hi All: Thank you all for the help you ever gave.

Re: How to speed up two arrays compare.

2009-02-12 Thread Marc Lucksch
kevin liu schrieb: But this algorithm takes a long time to compare, could you please help to improve this piece of code to less the time needed? Thanks in advance. I don't know if it's faster, but you can also use

Re: How to speed up two arrays compare.

2009-02-11 Thread Raymond Wan
Hi Kevin and all, John W. Krahn wrote: As to whether the algorithm Rob presented is the "best" algorithm, that depends on the data being used and how often this operation needs to be preformed. For example, the algorithm I presented above has a best case of O( 1 ) while the one Rob present

Re: How to speed up two arrays compare.

2009-02-11 Thread Chas. Owens
On Wed, Feb 11, 2009 at 11:07, kevin liu wrote: snip >> But this will still take O( n * m ) if all the elements of @nwarray0 are in >> @nwarray1. >> >> If the elements of @nwarray1 are sorted then you could a binary search on >> it and reduce your worst case to O( n * log m ). > > But how coul

Re: How to speed up two arrays compare.

2009-02-11 Thread John W. Krahn
kevin liu wrote: On Wed, Feb 11, 2009 at 11:22 PM, John W. Krahn wrote: The best you can do with two arrays is exit as soon as an element of @nwarray0 is not found in @nwarray1: my $found = 1; SEARCH: foreach my $srctemp ( @nwarray0 ) { foreach my $tgttemp ( @nwarray1 ) { if ( $tgtt

Re: How to speed up two arrays compare.

2009-02-11 Thread kevin liu
On Wed, Feb 11, 2009 at 11:22 PM, John W. Krahn wrote: > kevin liu wrote: > >> Hi everybody: >> > > Hello, > > > I have two arrays(@nwarray0 and @nwarray1) in my program and i want >> to make sure that >> all the elements in @nwarray0 could be found in @nwarray1. >>Here is my implementat

Re: How to speed up two arrays compare.

2009-02-11 Thread kevin liu
:) Rob Thank you very much for your help. Finally, I got this figured out. [?] On Wed, Feb 11, 2009 at 9:47 PM, Rob Dixon wrote: > kevin liu wrote: > > Hi everybody: > > > > I have two arrays(@nwarray0 and @nwarray1) in my program and i > want > > to make sure that > > all the

Re: How to speed up two arrays compare.

2009-02-11 Thread John W. Krahn
kevin liu wrote: Hi everybody: Hello, I have two arrays(@nwarray0 and @nwarray1) in my program and i want to make sure that all the elements in @nwarray0 could be found in @nwarray1. Here is my implementation: --- for

Re: How to speed up two arrays compare.

2009-02-11 Thread Rob Dixon
kevin liu wrote: > Hi everybody: > > I have two arrays(@nwarray0 and @nwarray1) in my program and i want > to make sure that > all the elements in @nwarray0 could be found in @nwarray1. > Here is my implementation: > --- >

Re: How to speed up two arrays compare.

2009-02-11 Thread Telemachus
On Wed Feb 11 2009 @ 4:04, kevin liu wrote: > Hi everybody: > > I have two arrays(@nwarray0 and @nwarray1) in my program and i want > to make sure that all the elements in @nwarray0 could be found in @nwarray1. Check 'perldoc -q array' - two or three of the FAQ answers touch on different

Re: How to speed up two arrays compare.

2009-02-11 Thread Raymond Wan
Hi Kevin, kevin liu wrote: I have two arrays(@nwarray0 and @nwarray1) in my program and i want to make sure that all the elements in @nwarray0 could be found in @nwarray1. Your problem is a common problem that is not specific to Perl. A common solution is to place one of the arra