/* */ Click to Join Live Class with Shankar sir Call 9798158723

Data Structure MCQ - Sparse Array


Q1.What is the difference between a normal(naive) array and a sparse array?
  1. Sparse array can hold more elements than a normal array
  2. Sparse array is memory efficient
  3. Sparse array is dynamic
  4. A naive array is more efficient

Answer:- (B).
Explanations :A naive implementation allocates space for the entire size of the array, whereas a sparse array(linked list implementation) allocates space only for the non-default values.
Q2.What is a sparse array?
  1. Data structure for representing arrays of records
  2. Data structure that compactly stores bits
  3. An array in which most of the elements have the same value
  4. An array in which memory is allocated in run time

Answer:- (C).
Explanations :They are set to a default value, usually 0 or null.
Q3.When do you use a sparse array?
  1. When there are unique elements in the array
  2. When the array has more occurrence of zero
  3. When the array has more occurrence of zero
  4. In all of the mentioned cases

Answer:- (B).
Explanations :When the array has more occurrence of zero elements
Q4.What is sparsity of a matrix?
  1. The fraction of zero elements over the total number of elements
  2. The fraction of non-zero elements over the total number of elements
  3. The fraction of total number of elements over the zero elements
  4. The fraction of total number of elements over the non-zero elements

Answer:- (A).
Explanations :Sparsity of a matrix is the fraction of number of zero elements over the total number of zero elements.
Q5.The fetch method of Sparse Array class is called , the row specified by row_index makes it an array and the col_index denotes the specified position. What is the worst case time complexity of deleting a node in Singly Linked list?
  1. O (n)
  2. O (n2)
  3. O (nlogn)
  4. O (1)

Answer:- (B).
Explanations :The above problem can be solved by the algorithm i.e. Container loading problem which is a type of greedy approach.
Q6. Which of the following is the disadvantage of sparse matrices over normal matrices?
  1. Size
  2. Speed
  3. Easily compressible
  4. Algorithm complexity

Answer:- (D).
Explanations :As the sparse matrix contains zeroes we will compute operations only on non zero values. This increases the complexity of algorithm as we need to identify index of zero elements first and during computation we should not take those index. It is a disadvantage. Sparse matrix is easily compressible by not storing the zero/null elements, they require less memory space, also only the non zero elements have to be computed, hence computational speed increases.
Q7.What is the output of the following code?
  1. A m*n all zero sparse matrix
  2. A m*n sparse matrix
  3. Error due to syntax
  4. Error in the input

Answer:- (C).
Explanations : There are two errors in the above code. MATLAB would return the syntactical error due to [] since there should be a parenthesis. There is an error in the input since there should be a ‘ , ‘ between m an n.
Q8.The nature of complex input taken by the sparse() command is ______________
  1. Only Imaginary part
  2. Only positive imaginary part
  3. Only negative real part
  4. All of the mentioned

Answer:- (D).
Explanations : The sparse() command takes all kind of complex inputs. It is not biased by default.
Q9. What is the command used to generate a sparse normally generated matrix?
  1. sparserndn
  2. sprandom
  3. sprandn
  4. no such command

Answer:- (C).
Explanations : Clarification: The sprandn command uses the same random number generator as that of the randn command. The rest of the commands don’t exist.
Q10.The size of the sparse matrix will be ___ the original matrix.
  1. equal
  2. greater than
  3. less than
  4. not equal to

Answer:- (A).
Explanations :The sparse matrix stores the non-zero elements in the sparse matrix. The space taken up by the sparse matrix being very less than the original, the size of both the matrix will be same. Hence, only option equal is correct.