Computer

Arrays In Data Structures MCQs

Practice Arrays In Data Structures MCQs for competitive exams.

Arrays In Data Structures MCQs

Practice questions from this topic.

Which of the following form inversion in the array arr = {1,5,4,2}?

  1. A. (5,4), (5,2)
  2. B. (5,4), (5,2), (4,2)
  3. C. (1,5), (1,4), (1,2)
  4. D. (1,5)
Report Error

The time complexity of the code that determines the number of inversions in an array using merge sort is lesser than that of the code that uses loops for the same purpose.

  1. A. true
  2. B. false
Report Error

What will be the output of the following code? #include using namespace std; void func(int a[], int n, int k) { if (k <= n) { for (int i = 0; i < k/2; i++) swap(a[i], a[k-i-1]); } } int main() { int a[] = {1, 2, 3, 4, 5}; int n = sizeof(a) / sizeof(int), k = 3; func(a, n, k); for (int i = 0; i < n; ++i) cout << a[i]<<" "; return 0; }

  1. A. 3 2 1 4 5
  2. B. 5 4 3 2 1
  3. C. 1 2 5 4 3
  4. D. error
Report Error

What will be the minimum number of jumps required to reach the end of the array arr[] = {1,3,6,3,6,8,5}?

  1. A. 1
  2. B. 2
  3. C. 3
  4. D. not possible to reach the end
Report Error

Which class in Java can be used to represent bit array?

  1. A. BitSet
  2. B. BitVector
  3. C. BitArray
  4. D. BitStream
Report Error

What is sparsity of a matrix?

  1. A. The fraction of zero elements over the total number of elements
  2. B. The fraction of non-zero elements over the total number of elements
  3. C. The fraction of total number of elements over the zero elements
  4. D. The fraction of total number of elements over the non-zero elements
Report Error

What will be the minimum number of jumps required to reach the end of the array arr[] ={0,1,3,6,3,6,8,5}?

  1. A. 1
  2. B. 2
  3. C. 3
  4. D. not possible to reach the end
Report Error

In which of the following cases dynamic arrays are not preferred?

  1. A. If the size of the array is unknown
  2. B. If the size of the array changes after few iterations
  3. C. If the memory reallocation takes more time i.e. expensive
  4. D. If the array holds less number of elements
Report Error

Which of the following bitwise operator will you use to invert all the bits in a bit array?

  1. A. OR
  2. B. NOT
  3. C. XOR
  4. D. NAND
Report Error

What will be the output of the following code? #include using namespace std; int main() { int arr[] = {1,2,3,4,5,6}; int n = sizeof(arr)/sizeof(arr[0]); int d=4; int temp[10]; for(int i=0;i<d;i++) temp[i]=arr[i]; int j=0; for(int i=d;i<n;i++,j++) arr[j]=arr[i]; int k=0; for(int i=n-d;i<n;i++,k++) arr[i]=temp[k]; for(int i=0;i<n;i++) cout<<arr[i]<<" "; return 0; }

  1. A. 5 6 1 2 3 4
  2. B. 6 5 4 3 1 2
  3. C. 3 4 5 6 1 2
  4. D. error
Report Error

What will be the resulting array after rotating arr[]={1, 2, 3, 4, 5} by 2?

  1. A. 2, 1, 3, 4, 5
  2. B. 3, 4, 5, 1, 2
  3. C. 4, 5, 1, 2, 3
  4. D. 1, 2, 3, 5, 4
Report Error

Which of the following is a disadvantage of parallel array over the traditional arrays?

  1. A. When a language does not support records, parallel arrays can be used
  2. B. Increased locality of reference
  3. C. Ideal cache behaviour
  4. D. Insertion and Deletion becomes tedious
Report Error