Suppose you are given an array s[1..n] and a procedure reverse(s, i, j) that…

GATE · 2000 · CS · Question 2 subparts

Suppose you are given an array s[1..n] and a procedure reverse(s, i, j) that reverses the order of the elements in s between positions i and j (both inclusive). What does the following sequence do, where 1 ≤ k ≤ n:

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

  1. A.

    Rotates s left by k positions

  2. B.

    Leaves s unchanged

  3. C.

    Reverses all elements of s

  4. D.

    None of the above

Attempted by 886 students.

Show answer

Correct answer: A

The worked solution is available to enrolled students.

Video solution available to enrolled students.

Explore the full course: Iocl Engineers Officers Grade A Paper 2

Loading lesson…