Array Data Structure Quiz

Last Updated :
Discuss
Comments

Question 1

Given a sorted 1D array, which technique finds whether a pair with sum = X exists in O(n) time ?


  • Binary Search

  • Nested Loops

  • Two pointer technique

  • Hashing

Question 2

What is the minimum number of comparisons required to find both the minimum and maximum element in a 1D array of size n?

  • 2n

  • n

  • 3n/2 -2

Question 3

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]

Question 4

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 5

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 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 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]

Question 8

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

  • sorting the elements

  • Reverse an array

  • None

Question 9

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.

Question 10

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

  • None

There are 26 questions to complete.

Take a part in the ongoing discussion