in Algorithms
232 views
2 votes
2 votes

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
in Algorithms
by
232 views

1 Answer

4 votes
4 votes

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

3 Comments

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..
0
0

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 ?

0
0
not getting ??
0
0
Answer:

Related questions