• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Top MCQs on Array Data Structure with Answers

Question 1

What will the output of the below code?

C++
#include <iostream>
using namespace std;

int main()
{

    int arr[2] = { 1, 2 };
    cout << 0 [arr] << ", " << 1 [arr] << endl;
    return 0;
}
Java
public class Main {
    public static void main(String[] args) {
        int[] arr = {1, 2};
        System.out.println(arr[0] + ", " + arr[1]);
    }
}
  • 1, 2

  • Syntax error

  • Run time error

  • None

Question 2

The minimum number of comparisons required to determine if an integer appears more than n/2 times in a sorted array of n integers is

  • Θ(n)

  • Θ(logn)

  • Θ(n*logn)

  • Θ(1)

Question 3

An algorithm performs (logN)

1/2

find operations, N insert operations, (logN)

1/2

delete operations, and (logN)

1/2

decrease-key operations on a set of data items with keys drawn from a linearly ordered set. For a delete operation, a pointer is provided to the record that must be deleted. For the decrease-key operation, a pointer is provided to the record that has its key decreased. Which one of the following data structures is the most suited for the algorithm to use, if the goal is to achieve the best total asymptotic complexity considering all the operations?

  • Unsorted array

  • Min-heap

  • Sorted array

  • Sorted doubly linked list

Question 4

Consider an array consisting of –ve and +ve numbers. What would be the worst case time complexity of an algorithm to segregate the numbers having same sign altogether i.e all +ve on one side and then all -ve on the other ?

  • O(N)

  • O(N Log N)

  • O(N * N)

  • O(N Log Log N)

Question 5

Let A[1...n] be an array of n distinct numbers. If i < j and A[i] > A[j], then the pair (i, j) is called an inversion of A. What is the expected number of inversions in any permutation on n elements ?

  • n(n-1)/2

  • n(n-1)/4

  • n(n+1)/4

  • 2n[logn]

Question 6

Consider a two dimensional array A[20][10]. Assume 4 words per memory cell, the base address of array A is 100, elements are stored in row-major order and first element is A[0][0]. What is the address of A[11][5] ?

  • 560

  • 460

  • 570

  • 575

Question 7

An array A consists of n integers in locations A[0], A[1] ....A[n-1]. It is required to shift the elements of the array cyclically to the left by k places, where 1 <= k <= (n-1). An incomplete algorithm for doing this in linear time, without using another array is given below. Complete the algorithm by filling in the blanks. Assume alt the variables are suitably declared.

C++
min = n; i = 0;

while (___________) {	

     temp = A[i]; j = i;

     while (________) {

     A[j] = ________	

     j= (j + k) mod n ;

     If ( j< min ) then

         min = j;

}

A[(n + i  k) mod n] = _________

i = __________
  • i > min; j!= (n+i)mod n; A[j + k]; temp; i + 1 ;

  • i < min; j!= (n+i)mod n; A[j + k]; temp; i + 1;

  • i > min; j!= (n+i+k)mod n; A[(j + k)]; temp; i + 1;

  • i < min; j!= (n+i-k)mod n; A[(j + k)mod n]; temp; i + 1;

Question 8

Which of the following correctly declares an array?

  • int geeks[20];

  • int geeks;

  • geeks{20};

  • array geeks[20];

Question 9

A three dimensional array in ‘C++’ is declared as int A[x][y][z]. Consider that array elements are stored in row major order and indexing begins from 0. Here, the address of an item at the location A[p][q][r] can be computed as follows (where w is the word length of an integer):

  • &A[0][0][0] + w(y * z * q + z * p + r)

  • &A[0][0][0] + w(y * z * p + z*q + r)

  • &A[0][0][0] + w(x * y * p + z * q+ r)

  • &A[0][0][0] + w(x * y * q + z * p + r)

Question 10

Let A be a square matrix of size n x n. Consider the following program. What is the expected output? 

C = 100
for i = 1 to n do
for j = 1 to n do
{
Temp = A[i][j] + C
A[i][j] = A[j][i]
A[j][i] = Temp - C
}
for i = 1 to n do
for j = 1 to n do
Output(A[i][j]);
  • The matrix A itself

  • Transpose of matrix A

  • Adding 100 to the upper diagonal elements and subtracting 100 from diagonal elements of A

  • None of the above

There are 20 questions to complete.

Last Updated :
Take a part in the ongoing discussion