232 views

Let you have an array $S[1 \dots n]$ and a function $reverse(s,i,j)$ which  reverse the order of elements in $s$ between $i,j$-th positions. What does the following sequence do where $1\leq k\leq n$ ;

reverse(s,1,k)
reverse (s,1,n)
reverse(s,k+1,n)

1. rotate s by k position to left
2. leaves s unchanged
3. rotate s by k position to right
4. none

Consider the array 2 3 4 8 5 and $k = 2$.

1.  3 2 4 8 5
2. 5 8 4 2 3
3. 5 8 3 2 4

So none.

by

sir reverse(s,1,n) reverse first and last position???? after applying the 1st code on 2,3,4,8,5 we get 3,2,4,8,5. then for execution of 2nd code we use orignal array or 3,2,4,8,5. ??

for 2nd code this array 5,2,4,8,3 is correct???

plz explain it..

Sir,

The Question says - reverse the order of elements in s between i and j-th positions.So for swap do we include  i and j positions as well or only the ones between them ?

not getting ??