[Tutor] max min value in array

Kent Johnson kent37 at tds.net
Thu Sep 17 19:18:28 CEST 2009


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


More information about the Tutor mailing list