c++ - Algorithm to find min and max in a given set -


a large array array[n] of integers given input. 2 index values given - start,end. desired find quickly - min & max in set [start,end] (inclusive) , max in rest of array (excluding [start,end]).

eg-

array - 3 4 2 2 1 3 12 5 7 9 7 10 1 5 2 3 1 1

start,end - 2,7

min,max in [2,7] -- 1,12

max in rest - 10

i cannot think of better linear. not enough n of order 10^5 , number of such find operations of same order.

any highly appreciated.

you're asking data structure answer min , max queries intervals on array quickly.

you want build 2 segment trees on input array; 1 answering interval minimum queries , 1 answering interval maximum queries. takes linear preprocessing, linear space, , allows queries take logarithmic time.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -