## Data Structure MCQ - Array

This section focuses on the "Array" of the Data Structure. These Multiple Choice Questions (mcq) should be practiced to improve the Data Structure skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

1. A program P reads in 500 integers in the range [0..100] exepresenting the scores of 500 students. It then prints the frequency of each score above 50. What would be the best way for P to store the frequencies?

View Answer

2. Which of these best describes an array?

View Answer

3. 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]);

View Answer

4.What is the output of the following piece of code?

public class array

{

public static void main(String args[])

{

int []arr = {1,2,3,4,5};

System.out.println(arr[2]);

System.out.println(arr[4]);

}

}

View Answer

5. Consider an array A[20, 10], assume 4 words per memory cell and the base address of array A is 100. What is the address of A[11, 5] ? Assume row major storage.

View Answer

6. What is the output of the following piece of code?

public class array

{

public static void main(String args[])

{

int []arr = {1,2,3,4,5};

System.out.println(arr[5]);

}

}

View Answer

7. Which of the following is an illegal array definition?

View Answer

8. Which of the following concepts make extensive use of arrays?

View Answer

9.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 ?

View Answer

10. Which of the following operations is not O(1) for an array of sorted data. You may assume that array elements are distinct.

View Answer

**Also Check : **