in reply to finding min and max of array recursivly

I'm sorry, I couldn't let this one go:
my ($Min,$Max)=(sort @A)[0,-1];

Would this be slow ?


*voice in my head* Very slow!, now go away...

Replies are listed 'Best First'.
RE: Re: finding min and max of array recursivly
by merlyn (Sage) on Sep 28, 2000 at 18:31 UTC
    Yes, for larger datasets.

    My first gut-level feel for "speed of algorithms" comes from my "how much entropy did you undo with that calculation?". In this case, besides knowing the minimum and maximum, you also knew (at one point, before you threw it away) the second-smallest, third-smallest, on up to the second-largest. It must have taken time to calculate those, so you've wasted time to calculate things that don't affect the outcome.

    Note that this is just for "back of the thumbnail" calculations. I've been wrong using this method, but I'm not a theoretical mathematician... I'm a hacker. {grin}

    -- Randal L. Schwartz, Perl hacker