To find a local minimum in a field

AI Thread Summary
The discussion focuses on finding a local minimum in a field of N integers, where A[0] and A[N+1] are defined as infinity. A local minimum is characterized by the condition A[i-1] >= A[i] <= A[i+1]. The initial algorithm presented operates in O(n) time complexity, which is insufficient for the goal of achieving better than O(n). A suggestion is made to improve the algorithm by using a conditional control statement to test every other value, potentially reducing the number of comparisons. However, it is noted that this approach still results in O(n) complexity. The conversation hints at exploring divide-and-conquer strategies to achieve a more efficient solution, emphasizing that there is at least one local minimum in the field.
alejandrito
Messages
7
Reaction score
0
Let A be a field of N integers and A[0] = A[N+1] = infinity. Element A is called a local minimum if A[I-1] >= A <= A[I+1]. Find an alogrithm that will find some local minimum in a time asymptotically better then O(n). Hint: Consider that in each field deffined as before there must exist at least one local minimum.
The best algorithm (or programme in Pascal) I´ve found is the following:
...
while (A[I+1] > A[I+2] and I<N-1) do I:=I+1;
LOCMIN:=A[I+1];
...
which needs maximally N-1 steps to find a local minimum, but this is not enough if we want the asymptotical difficulty better then O(n). Could anybody help me with improving the algorithm? Thanks
 
Technology news on Phys.org
I haven't tried working this out in detail, but with a clever conditional control statement for the loop you should be able to find a local min testing only every other value, rather than every value(using I=I+2). I think. I might be wrong, but it may be worth a try.
 
Hint: does http://en.wikipedia.org/wiki/Divide-and-conquer_algorithm" mean anything to you?


(Sorry, franznietzsche's idea doesn't solve the problem because O(n/2) is still O(n).)
 
Last edited by a moderator:
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top