Question
a)
public void store(int row_index, int col_index, Object val)
{
if (row_index < 0 || row_index > N)
{
System.out.println("row index out of bounds");
return;
}
if (col_index < 0 || col+index > N)
{
System.out.println("column index out of bounds");
return;
}
sparse_array[row_index].store(col_index, val);
}
b)
public void store(int row_index, int col_index, Object val)
{
if (row_index < 0 || row_index > N)
{
System.out.println("column index out of bounds");
return;
}
if (col_index < 0 || col+index > N)
{
System.out.println("row index out of bounds");
return;
}
sparse_array[row_index].store(col_index, val);
}
c)
public void store(int row_index, int col_index, Object val)
{
if (row_index < 0 && row_index > N)
{
System.out.println("row index out of bounds");
return;
}
if (col_index < 0 && col+index > N)
{
System.out.println("column index out of bounds");
return;
}
sparse_array[row_index].store(col_index, val);
}
d)
public void store(int row_index, int col_index, Object val)
{
if (row_index < 0 && row_index > N)
{
System.out.println("column index out of bounds");
return;
}
if (col_index < 0 && col+index > N)
{
System.out.println("row index out of bounds");
return;
}
sparse_array[row_index].store(col_index, val);
}
a.
a
b.
b
c.
c
d.
d
Posted under Data Structures and Algorithms
Engage with the Community - Add Your Comment
Confused About the Answer? Ask for Details Here.
Know the Explanation? Add it Here.
Q. How would you store an element in a sparse matrix?
Similar Questions
Discover Related MCQs
Q. What are the advantages of sparse matrices over normal matrices?
View solution
Q. What is the order of a matrix?
View solution
Q. Which of the following property does not hold for matrix multiplication?
View solution
Q. How do you allocate a matrix using a single pointer in C?(r and c are the number of rows and columns respectively)
View solution
Q. If row-major order is used, how is the following matrix stored in memory?
a b c
d e f
g h i
View solution
Q. If column-major order is used, how is the following matrix stored in memory?
a b c
d e f
g h i
View solution
Q. Which of the following are the uses of matrices?
View solution
Q. What is the disadvantage of matrices?
View solution
Q. Matrix A when multiplied with Matrix C gives the Identity matrix I, what is C?
View solution
Q. 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 solution
Q. Which of these best describes an array?
View solution
Q. 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 solution
Q. 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 solution
Q. Which of the following operations is not O(1) for an array of sorted data. You may assume that array elements are distinct.
View solution
Q. The smallest element of an array's index is called its
View solution
Q. The extra key inserted at the end of the array is called a
View solution
Suggested Topics
Are you eager to expand your knowledge beyond Data Structures and Algorithms? We've curated a selection of related categories that you might find intriguing.
Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!