Question 2
For a 2D array stored in row-major order, what is the address of A[i][j] in terms of base address B, number of columns N, and assuming each element takes 1 unit of space?
B + i + j
B + i * N + j
B + j * N + i
B + j + i * N
Question 4
Which of the following best distinguishes a subarray from a subsequence of a 1-D array?
Subarrays preserve the original order, subsequences need not.
Subarrays are contiguous slices, subsequences can skip elements.
All subarrays are subsequences, but not all subsequences are subarrays.
Both B and C.
Question 5
You want the maximum sum of a contiguous subarray, but you may delete at most one element. Which technique runs in O(n) time?
Two nested Kadane passes (one forward, one backward) and combine
Brute‐force try deleting each element (O(n²))
Use a segment tree supporting “delete one” updates
Sort the array and pick top sums
Question 6
Reversing a 1D array of length n in place requires how many element swaps?
n
n / 2
n − 1
(n + 1) / 2
Question 7
Which in-place sequence of operations rotates a 1D array right by k positions?
Reverse entire array, reverse first k, then reverse remaining n−k
Reverse first k, reverse remaining, then reverse entire
Swap pairs (i, i+k) for all i
Shift everything right one at a time, k times
Question 8
To mirror a matrix left-to-right in place, you:
Transpose then flip top-to-bottom
Swap columns j and n−1−j for all j < n/2
Reverse each column
Rotate by 180°
Question 9
In a circular buffer of size n, to advance a write index by one modulo n, compute:
(idx + 1) & n
(idx + 1) % n
idx++
(idx − 1 + n) % n
Question 10
Which in-place procedure deletes the element at index k from a 1D array of length n (shifting remaining)?
Swap A[k] with A[n−1], then reduce length by 1
For i from k to n−2, set A[i] = A[i+1]
Mark A[k] as null
Reverse subarray [k..n−1]
There are 10 questions to complete.