Re: Find Max of "Concave" List
- To: mathgroup at smc.vnet.net
- Subject: [mg13000] Re: Find Max of "Concave" List
- From: Tobias Oed <tobias at physics.odu.edu>
- Date: Sun, 28 Jun 1998 02:52:21 -0400
- Organization: Old Dominion University
- References: <6mqcvs$3bt@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
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 maybe something like l={1,2,3,4,3,2,1} e=First[l] Catch[Scan[If[#<e,Throw[e],e=#]&,Rest[l]]]