• Data Structure Reference

• Other Reference

# 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?

A. An array of 50 numbers
B. An array of 100 numbers
C. An array of 500 numbers
D. A dynamically allocated array of 550 numbers

2. Which of these best describes an array?

A. A data structure that shows a hierarchical behavior
B. Container of objects of similar types
C. Container of objects of mixed types
D. All of the mentioned

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]);
```

A. The matrix A itself
B. Transpose of matrix A
C. Adding 100 to the upper diagonal elements & subtracting 100 from diagonal elements of A
D. None of the above

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]);
}
}
```

A. 3 and 5
B. 5 and 3
C. 2 and 4
D. 4 and 2

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.

A. 560
B. 565
C. 570
D. 575

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]);
}
}
```

A. 4
B. 5
C. ArrayIndexOutOfBoundsException
D. InavlidInputException

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

A. Type COLONGE : (LIME, PINE, MUSK, MENTHOL); var a : array [COLONGE] of REAL;
B. var a : array [REAL] of REAL;
C. var a : array [‘A’…’Z’] of REAL;
D. var a : array [BOOLEAN] of REAL;

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

A. Binary trees
B. Scheduling of processes
C. Caching
D. Spatial locality

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 ?

A. θ(n)
B. θ(lgn)
C. θ(nlgn)
D. θ(n2)

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

A. Find the ith largest element
B. Delete an element
C. Find the ith smallest element
D. All of the above

11.The smallest element of an array's index is called its

A. lower bound.
B. upper bound.
C. range.
D. extraction.

12. The extra key inserted at the end of the array is called a,

A. End key.
B. Stop key.
C. Sentinel.
D. Transposition.

13. The largest element of an array index is called its

A. lower bound.
B. range.
C. upper bound.
D. All of these.

14. Each array declaration need not give, implicitly or explicitly, the information about

A. the name of array
B. the data type of array
C. the first data from the set to be stored
D. the index set of the array

15. The elements of an array are stored successively in memory cells because

A. by this way computer can keep track only the address of the first element and the addresses of other elements can be calculated
B. the architecture of computer memory does not allow arrays to store other than serially
C. both of above
D. none of above

Also Check :

Discussion