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 \le k \le n-1\). An incomplete algorithm for doing this in linear time, without using another array, is given below. B1 to B5 are the blanks.
min = n; i = 0;
while (B1) {
temp = A[i]; j = i;
while (B2) {
A[j] = B3;
j = (j + k) mod n;
if (j < min) then min = j;
}
A[(n + i - k) mod n] = B4;
i = B5;
}
Complete the algorithm by choosing B1; B2; B3; B4; B5 in that order.
- A\(i \gt \min ; \quad j \ne (n+1) \bmod n ; \quad A[j+k] ; \quad \text{temp} ; \quad i+1\)
- B\(i \lt \min ; \quad j \ne (n+i) \bmod n ; \quad A[j+k] ; \quad \text{temp} ; \quad i+1\)
- C\(i \gt \min ; \quad j \ne (n+i+k) \bmod n ; \quad A[j+k] ; \quad \text{temp} ; \quad i+1\)
- D\(i \lt \min ; \quad j \ne (n+i-k) \bmod n ; \quad A[(j+k) \bmod n] ; \quad \text{temp} ; \quad i+1\)