I am trying to solve this question. I am making the vector size of Math.ceil(Math.sqrt(arrSize)). I have used the following methods - For constructing sqrt vector
I am taking square root chunks and finding the smallest index in the block and storing them in the vect array.
How can I improve my update query complexity from Sqrt(n).
static void update(int[] arr, int[] vect, int index, int elem) {
arr[index] = elem;
int len = vect.length;
int inIndex = ((index / len) * len);
int finalIndex = inIndex+len;
int min = Integer.MAX_VALUE;
int in = -1;
for(int i = inIndex; i < finalIndex && i < arr.length; ++i) {
if(arr[i] < min) {
min = arr[i];
in = i;
}
}
vect[index/len] = in;
}
used this tutorial -: http://www.geeksforgeeks.org/sqrt-square-root-decomposition-technique-set-1-introduction/