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.

**min = n; i = 0;**

**while (____________){**

** temp = A[i] ; j = i;**

** while(______________){**

**A[j] = ________;**

**j = (j + k)mod n;**

**If(j < k)mod n;**

** min = j;**

**}**

**A[(n + i – k)mod n] = _______;**

**i = ________;**

**}**

This question was previously asked in

ISRO Scientist CS 2018 Official Paper

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

ISRO Scientist CS 2020 Official Paper

741

80 Questions
240 Marks
90 Mins

**Code:**

min = n; i = 0;

while (____________){

temp = A[i] ; j = i;

while(______________){

A[j] = ________;

j = (j + k)mod n;

If(j < k)mod n;

min = j;

}

A[(n + i – k)mod n] = _______;

i = ________;

}

From the code, the last two blanks are to be filled with '**temp**' and '**i+1**'

first, blank should be filled with 'i < min' as if 'i > min' then it will fail immediately when i =0 and min = n.

**A[j] = A[j+k]** as we need to shift by k places

the condition for the inner while loop will be '**j! = (n+i-k)mod n**' as if it would be '(n+i) mod n' then control will never enter to the second while loop as it is necessary to shift array k places.

Therefore the correct answer is Option 4.