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 ?


  • A

    Binary Search

  • B

    Nested Loops

  • C

    Two pointer technique

  • D

    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?

  • A

    2n

  • B

    n

  • C

    3n/2 -2

  • D

    n²

Question 3

Which in-place procedure deletes the element at index k from a 1D array of length n (shifting remaining)?

  • A

    Swap A[k] with A[n−1], then reduce length by 1

  • B

    For i from k to n−2, set A[i] = A[i+1]

  • C

    Mark A[k] as null

  • D

    Reverse subarray [k..n−1]

Question 4

In a circular buffer of size n, to advance a write index by one modulo n, compute:

  • A

    (idx + 1) & n

  • B

    (idx + 1) % n

  • C

    idx++

  • D

    (idx − 1 + n) % n

Question 5

Which sequence of reversal operations rotates a 1-D array to the right by k positions in-place?

  • A

    Reverse the entire array, reverse the first k elements, then reverse the remaining n-k elements.

  • B

    Reverse the first k elements, reverse the remaining n-k elements, then reverse the entire array.

  • C

    Swap A[i] and A[i+k] for all valid i.

  • D

    Reverse the array once and then shift all elements right by one position.

Question 6

Reversing a 1D array of length n in place requires how many element swaps?

  • A

    n

  • B

    n / 2

  • C

    n − 1

  • D

    (n + 1) / 2

Question 7

Which in-place procedure deletes the element at index k from a 1D array of length n (shifting remaining)?

  • A

    Swap A[k] with A[n−1], then reduce length by 1

  • B

    For i from k to n−2, set A[i] = A[i+1]

  • C

    Mark A[k] as null

  • D

    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--;
    }
}
  • A

    swapping the elements pairwise

  • B

    sorting the elements

  • C

    Reverse an array

  • D

    None

Question 9

Refer the below diagram and identify the problem.

 
  • A

    Normal traversal of the matrix.

  • B

    Row-wise traversal of the matrix.

  • C

    Column-wise traversal of the matrix.

  • D

    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++;
    }
}
  • A

    p <= d , i < n - 1 , arr[n - 1] = last;

  • B

    p < d, i < n, arr[n] = last;

  • C

    p >=d, i >n , arr[n] =  last

  • D

    None

There are 26 questions to complete.

Take a part in the ongoing discussion