An array A consists of n integers in locations A[0], A[1] ....A[n-1]. It is…

ISRO Scientist/Engineer SC · 2018 · Computer Science

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 all 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< min ) then

         min = j;

}

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

i = __________
  1. A.

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

  2. B.

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

  3. C.

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

  4. D.

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

Attempted by 278 students.

Show answer

Correct answer: D

The worked solution is available to enrolled students.

Explore the full course: Iocl Engineers Officers Grade A Paper 2

Loading lesson…