Given a sequence S
of n
integer elements, I need a function min(i,j)
that finds the minimum element of the sequence between index i and index j (both inclusive) such that:
O(n)
;O(n)
;min(i,j)
takes O(log(n))
.Please suggest an algorithm for this.
Segmenttree is that what you need because it fulfils all your requirements.
Beside this, the tree is dynamic and can support updating in O(log n). This means one can modify the element of some element i in O(log n) and still retrieve the minimum.