Array Data Structure Quiz (original) (raw)
Given a sorted 1D array, which technique finds whether a pair with sum = X exists in O(n) time ?
What is the minimum number of comparisons required to find both the minimum and maximum element in a 1D array of size n?
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]
- Reverse subarray [k..n−1]
In a circular buffer of size n, to advance a write index by one modulo n, compute:
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
Reversing a 1D array of length n in place requires how many element swaps?
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]
- Reverse subarray [k..n−1]
Consider the below program. What is the expected output?
C++ `
void fun(int arr[], int start, int end) { while (start < end) { int temp = arr[start]; arr[start] = arr[end]; arr[end] = temp; start++; end--; } }
`
- swapping the elements pairwise
Refer the below diagram and identify the problem.

- Normal traversal of the matrix.
- Row-wise traversal of the matrix.
- Column-wise traversal of the matrix.
- spiral traversal of the matrix.
Fill in the blanks for completing the program to rotate an array by d elements.
C++ `
/Function to left rotate arr[] of size n by d/ void Rotate(int arr[], int d, int n) { int p = 1; while (_______) { int last = arr[0]; for (int i = 0; ______ i++) { arr[i] = arr[i + 1]; } __________ p++; } }
`
- p <= d , i < n - 1 , arr[n - 1] = last;
- p < d, i < n, arr[n] = last;
- p >=d, i >n , arr[n] = last
There are 26 questions to complete.
Take a part in the ongoing discussion