Re: Finding a maxima with binary search?
- From: Randy Howard <randyhoward@xxxxxxxxxxxxxxxxx>
- Date: Sat, 21 Jan 2006 16:46:12 GMT
CBFalconer wrote
(in article <43D25E16.6D875145@xxxxxxxxx>):
>> Uh, well. If the numbers are actually strictly increasing and
>> decreasing integers, then the first difference tells which way.
>> Hence first difference tells whether the maximum is to the left
>> or to the right of the midpoint, and so in that case binary search
>> is applicable, finding the maximum in O(log n).
>
> You may want to reconsider that statement. Try the sequence:
>
> 1 2 3 4 2
I suspect you could modify the basic approach of a binary search
to adjust itself when the "right side" gets a lower number and
still beat a linear search (for large sequences), but not
knowing the full details of the homework question, I'm not keen
to guess.
:-)
--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw
How 'bout them Horns?
.
- References:
- Finding a maxima with binary search?
- From: Digital Puer
- Re: Finding a maxima with binary search?
- From: CBFalconer
- Re: Finding a maxima with binary search?
- From: Alf P. Steinbach
- Re: Finding a maxima with binary search?
- From: CBFalconer
- Finding a maxima with binary search?
- Prev by Date: Re: Finding a maxima with binary search?
- Next by Date: Re: Finding a maxima with binary search?
- Previous by thread: Re: Finding a maxima with binary search?
- Next by thread: Re: Finding a maxima with binary search?
- Index(es):
Relevant Pages
|