I read the wikipedia link on Range Minimum Queries, looked at a couple more tutorials (topcoder and other links) but I have a very basic question:
Formal definitino of RMQ is : Given an array of objects taken from a well-ordered set (such as numbers), a Range Minimum Query (or RMQ) from to asks for the position of a minimum element in the sub-array .
What I don't understand is that why can't we solve the problem by linear search? In an array A[0...n], if we need RMQ(i,j)
min = A[i]
index = i
for iter=i; iter <j; iter ++
if A[iter] <= min
min = A[iter]
index = iter;
by the end of the loop, we know the min and the index where the min lies.
I am definitely missing something here...can someone help me understand why we need RMQ?