On Tue, 2002-07-16 at 12:58, George Schlossnagle wrote: > > On Tuesday, July 16, 2002, at 12:48 PM, Shishir K. Singh wrote: > > > Why not use sort on the array and get the last element which would be > > the highest?? > > > > my @sorted = sort @list; > > my $max = $sort[$#sorted]; > > > > Wouldn't this work ? I a not sure about the speed though!! > > sorting has a best expected runtime of O(nlog(n)), finding the max item > via a linear search is O(n).
This should really be in the FAQ, but here we go again. This is why big O notation only tells you half the story. Sort is implemented in C and is one operation as far as Perl is concerned, whereas the loop method contains many Perl operands that must be interpreted. For all but the largest data sets the C code beats the Perl code hands down (IIRC it takes half the time). If you do not believe me check out other threads in this mailing list or run the benchmarks yourself. -- Today is Boomtime the 51st day of Confusion in the YOLD 3168 Kallisti! Missile Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]