Array · Data Structures
17 questions · asked in 12 of 27 years (2000–2026)
MCQ 15 · NAT 21-mark 13 · 2-mark 4
2000Questions per year2026
Questions 16–17 of 17
Suppose you are given an array s[1....n] and a procedure reverse (s, i, j) which reverses the order of elements in s between positions i and j (both inclusive). What does the following sequence do, where 1 n:
reverse (s, 1, k);
reverse (s, k+1, n);
reverse (s, 1, n); Answer: (A)
Split into two parts: , the first elements, and , the remaining elements. So .
- turns it into .
- turns it into .
- reverses the whole array, giving .
is rotated left by places, for any from 1 to .
Example with and :
- gives
- gives
- gives
The array is rotated left by 2 places.
Answer: (A)
- turns it into .
- turns it into .
- reverses the whole array, giving .
is rotated left by places, for any from 1 to .
Example with and :
- gives
- gives
- gives
The array is rotated left by 2 places.
Answer: (A)
An array is defined as follows:
for all
The sum of the elements of the array is
for all
The sum of the elements of the array is
Answer: (A)
Every entry is , so the sum is .
Split it: and . Both are the same number, , so the difference is .
Another way to see it: , so each entry cancels its mirror entry across the diagonal, and the diagonal entries are all . The table below shows this for .
Answer: (A)
Split it: and . Both are the same number, , so the difference is .
Another way to see it: , so each entry cancels its mirror entry across the diagonal, and the diagonal entries are all . The table below shows this for .
Answer: (A)
Keep practising