about max and min in an array

来源: 2008-02-13 07:15:12 [旧帖] [给我悄悄话] 本文已被阅读:

I hate myself very much! I promised that I would reply the posted related to ... However, I cannot help myself after I read the posts under.

For max and min in an array, no comparison needed. Assuming we have two numbers A and B, the min = (A+B)/2-ABS((A-B)/2) and max=(A+B)/2+ABS((A-B)/2). Recursively travel through the array and you would find the min and max.

It is a simple algorithm.