[Tutor] max min value in array

Rich Lovely roadierich at googlemail.com
Thu Sep 17 19:39:15 CEST 2009


2009/9/17 Kent Johnson <kent37 at tds.net>:
> On Thu, Sep 17, 2009 at 11:01 AM, steve <steve at lonetwin.net> wrote:
>> On 09/17/2009 06:04 PM, Kent Johnson wrote:
>>>
>>> On Thu, Sep 17, 2009 at 8:06 AM, Rich Lovely<roadierich at googlemail.com>
>>>  wrote:
>>>>
>>>>  2009/9/17 Rayon<evosweet at hotmail.com>:
>>>>>
>>>>>  I need to find the max and min value from some floats in a array:
>>>
>>>>  Depending on the size of the array, there's two methods:  Using the
>>>>  max and min builtin functions, which will be faster for small arrays,
>>>>  or hand-coding a single pass function, which might be faster for
>>>>  arrays above a certain size.
>>>
>>> Why do you expect a hand-coded function to scale better? I would
>>> expect them both to be O(n).
>>>
>> I guess what Rich meant was, a hand-coded function to get /both/ min and max
>> in a single pass would be faster on large arrays (as done in the posted
>> minmax2() function) than calling min() and max() individually (which would
>> imply 2 passes).
>
> Yes, that is my understanding of his statement. My question is, why
> would it be faster only on large arrays? I expect the time of both
> methods to scale linearly with the size of the array. Two fast passes
> might be faster than one slow pass regardless of the size of the
> array.
>
> Kent
>

Hmm... I obviously didn't sprinkle round enough hints of my
uncertainty in the matter.  I did, however, suggest that the OPer
profiles both to check.  I was assuming that would cover all the
bases.  Even if I do provide full, working functions, I'm not going to
spoon feed anyone a "fait accomplis".

I'm still learning too...  hence the 'tutor' mailing list, not the
'expert' mailing list.

Perhaps I was wrong on which would be faster, to be honest, I don't
care that much:  if anyone is really worried about speed, they're
using the wrong language.

Perhaps that's the wrong stance to take, but again, I don't care that much.

I always try to make it clear when I'm not certain about a matter.  If
I have ever misled anyone, I can only apologise.

-- 
Rich "Roadie Rich" Lovely

There are 10 types of people in the world: those who know binary,
those who do not, and those who are off by one.


More information about the Tutor mailing list