MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Find Max of "Concave" List


Chris Farr wrote:
> 
> I have a one-dimensional list which is concave.  That is, if you did a
> ListPlot on the list you would have a concave curve.
> 
> Given the concavity, when finding the max, it is inefficient to use
> Max[] which does a comparison on all elements of the list.
> 
> Is there an elegant way to exploit the concavity when performing a
> Max[]?  That is, the algorithm should stop when the next element in the
>  list is lower then the previous element.  This would limit the number
> of  comparisons.
> 
> Thanks,
> 
> Chris Farr

You can use Return, Catch, Throw and Break to control the flow of
programs.  If you had a loop of some kind, you could Break whenever the
condition was met or you could wrap your loop in a Catch and Throw
whenever a condition was met.  You could also just use a while loop and
put the "abort early" criteria into the While loop.


  • Prev by Date: Re: Problems with mathlink (and TWJ_ExtendGraphics)
  • Next by Date: RE: Strange behavior of Sort
  • Previous by thread: Find Max of "Concave" List
  • Next by thread: Re: Find Max of "Concave" List