On Wed, 2002-03-27 at 07:25, Sudarsan Raghavan wrote:
> Robert Graham wrote:
> 
> > Hi Ozgur
> >
> > You can use the following:
> >
> > @data = (10,45,2,439);
> > ($min,$max) = (sort {$a <=> $b} @data)[0,$#data];
> 
>     IMHO sorting a list to find the max and min element is not a good idea.
> The sort is of O(nlgn) and the usual
>     run through the list to find the max element is O(n). This is not of
> significance when n is small, at the same
>     time this is not a method that should be followed for this task.

Sorting would not be a good idea if you were to write the sort yourself;
however, sort is implemented in C which is much faster than Perl.  This
thread was discussed at length earlier.  If you look in the archives you
can see that using sort takes about half the time a foreach loop takes
even though the using foreach loop is a more efficient algorithm.  

The lesson to learn from this is that you should use builtin functions
over your own.  Or possibly, when you care about efficiency use
Inline::C and a good algorithm.

> 
> >
> >
> > Regards
> > Robert
> >
> > -----Original Message-----
> > From: OZGUR GENC [mailto:[EMAIL PROTECTED]]
> > Sent: 27 March 2002 13:06
> > To: [EMAIL PROTECTED]
> > Subject: Maximum ,Minumum
> >
> > Hi All,
> > Does anyone help me about how I can find the maximum and minumum element
> > of an array?
> > Ozgur
> >
> > ***************************************************************************
> >
> > This e-mail and any files transmitted with it are confidential and intended
> > solely for the use of the individual or entity to whom they are addressed.
> > If you are not the intended recipient you are hereby notified that any
> > dissemination, forwarding, copying or use of any of the information is
> > prohibited.
> >
> > The opinions expressed in this message belong to sender alone. There is no
> > implied endorsement by TURKCELL.
> >
> > This e-mail has been scanned for all known computer viruses.
> >
> > ***************************************************************************
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
-- 
Today is Sweetmorn the 13rd day of Discord in the YOLD 3168
Umlaut Zebra über alles!

Missile Address: 33:48:3.521N  84:23:34.786W


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to