ISRO | ISRO CS 2018 | Question 24

Last Updated :
Discuss
Comments

An array A consists of n integers in locations A[0], A[1] ....A[n-1]. It is required to shift the elements of the array cyclically to the left by k places, where 1 <= k <= (n-1). An incomplete algorithm for doing this in linear time, without using another array is given below. Complete the algorithm by filling in the blanks. Assume alt the variables are suitably declared.

C++
min = n; i = 0;

while (___________) {	

     temp = A[i]; j = i;

     while (________) {

     A[j] = ________	

     j= (j + k) mod n ;

     If ( j< min ) then

         min = j;

}

A[(n + i  k) mod n] = _________

i = __________

i > min; j!= (n+i)mod n; A[j + k]; temp; i + 1 ;

i < min; j!= (n+i)mod n; A[j + k]; temp; i + 1;

i > min; j!= (n+i+k)mod n; A[(j + k)]; temp; i + 1;

i < min; j!= (n+i-k)mod n; A[(j + k)mod n]; temp; i + 1;

Share your thoughts in the comments