494 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

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.

Answer:

Related questions

2 votes
2 votes
2 answers
2
Bikram asked Oct 4, 2016
363 views
$$T(n) = \begin{cases} 4 & \quad if \: \: n =1 \\ T(n-1) + 4 & \quad otherwise \end{cases}$$Value of $T(1000)$ is ___