× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I may stand corrected. Or maybe not. Needs more investigation, because I
know that doing a test on each pass through the loop is costly. The sort can
be optimized.

If the array needs to remain in the original order, I agree the for loop
would be better. But we were talking about a max function that would either
compare all parms looking for the max or load and load and sort an array
with the parms. If the sort is not desirable, doing a loop for n = 1 to %PARMS
would do just fine. No array, no SORT.


In a message dated 4/24/2009 3:27:37 P.M. Jerusalem Daylight Time,
adamglauser@xxxxxxxxx writes:

CRPence wrote:
Adam Glauser wrote:
Personally I prefer Asher's [sort] solution, which is both
more elegant and more efficient. To each their own.

Just curious. Why would a sort be more efficient than spinning the
array in the /for loop/ as above? Does the sort not require effectively

all the same work?

Erm, I was wrong. I was thinking of quicksort, which is O(n log n).
Somehow my memory had turned that into O(log n), which as you pointed
out is not possible. I think sort, by definition, can not be better
than O(n). The max loop is clearly better.

Your point later about maintaining the order of the original arrays is
also well taken.

Thanks for the corrections.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.