GATEverse
← GATE CSE 1994

Q7

NATMarks unknown

An array AA contains nn integers in locations A[0],A[1],…A[n−1]A[0], A[1], \dots A[n-1]. It is required to shift the elements of the array cyclically to the left by KK places, where 1≤K≤n−11\leq K \leq 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 variables are suitably declared. min:=n; i=0; while _____ do begin temp:=A[i]; j:=i; while ____ do begin A[j]:=____; j:=(j+K) mod n; if j<min then min:=j; end; A[(n+i-K)mod n]:=____; i:=______; end;

Sign in to save attempts.

Loading…