Representing sparse matrix in memory using array, Data Structure & Algorithms

Assignment Help:

Q. What do you understand by the term sparse matrix? How sparse matrix is stored in the memory of a computer? Write down the function to find out the transpose of a sparse matrix using this particular representation.                                                                                                             

Ans.

Sparse Matrix is described below

A m x n matrix A would be a sparse if most of its elements are zero. A matrix that is not sparse is known as dense matrix.

Representing Sparse Matrix in Memory Using Array is described below

In an array representation an array of triplets of type < row, col, element> is used to store non-zero elements, where 1st field of the triplet is used to trace row position second to record column and the 3rd to record the non zero elements of  sparse matrix.

In addition, we are required to record the size of the matrix ( i.e. number of rows and the number of columns) and non zero elements of array of triplets are used for this purpose where the 1st filed saves the number of rows and the 2nd field saves the number of columns and the third field saves the number of non zero elements. The remaining elements of the array saves matrix on row major order. The array representation will be

[2 * (n+1) * size of (int) + n*size of(T)] bytes of memory where n is the number of non-zero elements and T is the data type of the element.

Ex: consider a 5*6 sparse matrix which is written below

1713_sparse matrix2.png 

Array Representation of Sparse Matrix is given below

1754_sparse matrix3.png

Here n = 5 but the size of array is 6 as first row saves the order of array along with a number non-zero elements.

Memory declaration will be as followsas shown below

# define Max 50 struct triplet

{   int row;

int col;

float element;

}

struct triplet sparse_mat [MAX];

sparse matrix represented as above

[n is the number of non zero elements in array]

for I= 1,2,...n+1 temp = a[I].row a[I].row= a[I].col a[I].col = temp endfor.


Related Discussions:- Representing sparse matrix in memory using array

Array implementation of a queue, Since the stack is list of elements, the q...

Since the stack is list of elements, the queue is also a list of elements. The stack & the queue differ just in the position where the elements may be added or deleted. Similar to

Mcs-021, #questWrite an algorithm for multiplication of two sparse matrices...

#questWrite an algorithm for multiplication of two sparse matrices using Linked Lists.ion..

Time converstion, how to convert 12 hour format into 24 hour format using c...

how to convert 12 hour format into 24 hour format using c program

Preorder - postorder and inorder, 1) preorder, postorder and inorder 2) ...

1) preorder, postorder and inorder 2) The main feature of a Binary Search Tree is that all of the elements whose values is less than the root reside into the nodes of left subtr

Delete a given node from a doubly linked list, Algorithm to Delete a given ...

Algorithm to Delete a given node from a doubly linked list Delete a Node from Double Linked List DELETEDBL(INFO, FORW, BACK, START, AVAIL,LOC) 1. [Delete Node] Set FOR

Explain how the shuttle sort algorithm works, Question 1 Explain how th...

Question 1 Explain how the shuttle sort algorithm works by making use of the following list of integers:11, 4, 2, 8, 5, 33, 7, 3, 1, 6. Show all the steps. Question 2

Define strictly binary tree, Define Strictly Binary Tree Strictly Bina...

Define Strictly Binary Tree Strictly Binary Tree: - If each non leaf node in binary tree has non empty left and right sub-trees , then the tree is known as a strictly binary t

COBOL, write a COBOL program to find the biggest of two numbers

write a COBOL program to find the biggest of two numbers

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd