Data Structure MCQ - Sparse Array
Q1.What is the difference between a normal(naive) array and a sparse array?
- Sparse array can hold more elements than a normal array
- Sparse array is memory efficient
- Sparse array is dynamic
- 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.
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.
- Data structure for representing arrays of records
- Data structure that compactly stores bits
- An array in which most of the elements have the same value
- An array in which memory is allocated in run time
Answer:- (C).
Explanations :They are set to a default value, usually 0 or null.
Explanations :They are set to a default value, usually 0 or null.
- When there are unique elements in the array
- When the array has more occurrence of zero
- When the array has more occurrence of zero
- In all of the mentioned cases
Answer:- (B).
Explanations :When the array has more occurrence of zero elements
Explanations :When the array has more occurrence of zero elements
- The fraction of zero elements over the total number of elements
- The fraction of non-zero elements over the total number of elements
- The fraction of total number of elements over the zero elements
- 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.
Explanations :Sparsity of a matrix is the fraction of number of zero elements over the total number of zero elements.
- O (n)
- O (n2)
- O (nlogn)
- 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.
Explanations :The above problem can be solved by the algorithm i.e. Container loading problem which is a type of greedy approach.
- Size
- Speed
- Easily compressible
- 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.
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.
- A m*n all zero sparse matrix
- A m*n sparse matrix
- Error due to syntax
- 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.
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.
- Only Imaginary part
- Only positive imaginary part
- Only negative real part
- All of the mentioned
Answer:- (D).
Explanations : The sparse() command takes all kind of complex inputs. It is not biased by default.
Explanations : The sparse() command takes all kind of complex inputs. It is not biased by default.
- sparserndn
- sprandom
- sprandn
- 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.
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.
- equal
- greater than
- less than
- 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.
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.
Copyright © 2022 Shineskill Software Pvt. Ltd., All rights reserved.