question on Max and Min

Discussion in 'Mathematica' started by Arkadiusz.Majka, Sep 6, 2007.

  1. Hi all,
    Please take o while and think if

    Max[longList]-Min[longList]

    is the fastest way of calculating the difference of maximal and
    minimal values of (very) long list.

    Arek
     
    Arkadiusz.Majka, Sep 6, 2007
    #1
    1. Advertisements

  2. I would say yea for a one-dimensional list made of homogeneous atomic
    elements (i.e. all element have the same basis type such as machine-size
    floating-point numbers or integers).

    The following example tests a vector of 100 million floating-point
    numbers (occupying about 800 Mo in RAM) in less than 0.9 second. To me,
    I would say the list is very large and the test fast enough. Of course,
    you may have a different opinion. Also, sorting the list before talking
    the first and last elements is much slower even when using Ordering. (I
    believe that Max and Min have been optimized to work fast on large list.)

    In[1]:= longList = RandomReal[{-10000, 10000}, {10^8}];
    ByteCount[longList]
    Max[longList] - Min[longList] // Timing

    Out[2]= 800000076

    Out[3]= {0.875, 20000.}
     
    Jean-Marc Gulliet, Sep 7, 2007
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.