wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

Consider the following implementations for rotating an array A[1, ....n] of size n by K positions , where 1 < = K < = n . Note that the procedure reverse (A, i, j) reverses the order of elements in A between positions i and j in A (both inclusive )
which of the above implementation(s) work correctly for all inputs ?
Implementation I:
reverser(A, 1, K);
reverse(A, 1, n) ;
reverse (A, k+1, n) ;
Implementation II:
reverser(a, K+1, n);
reverse(a, 1, K) ;
reverse (a, 1, n) ;
Implementation III:
reverser(a, 1, K);
reverse(a, K+1, n) ;
reverse (a, 1, n) ;


A
III only
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
II and III but not I
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
C
I only
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
I and II but not III
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is B II and III but not I
(b)
III is the standard way of rotating left by K position. So if we swap the first and second lines in 3rd implementation , it will still give correct output.
so II is also correct.
But 3rd line has to be at the end, so I is incorrect
Hence answer is option (b)


flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon