linked structures own variable if the element is already zero-entry and the new value is zerono action is required setting the value of matrix element requires (ntime in the worst casewhere is the number of columns in the matrix this value is obtained by observing that the most time-consuming part is the positioning of the two referencescurnode and prednodewhich require complete list traversal in the worst case since linked list contains single rowwe know it will contain at most nodes listing the llistsparse py module implementation of the sparse matrix adt using an array of linked lists from array import array class sparsematrix creates sparse matrix of size numrows numcols initialized to def __init__selfnumrowsnumcols )self _numcols numcols self _listofrows arraynumrows returns the number of rows in the matrix def numrowsself )return lenself _listofrows returns the number of columns in the matrix def numcolsself )return self _numcols returns the value of element ( , ) [ ,jdef __getitem__selfndxtuple )sets the value of element ( ,jto the value sx[ ,js def __setitem__selfndxtuplevalue )prednode none curnode self _listofrows[rowwhile curnode is not none and curnode col !col prednode curnode curnode curnode next see if the element is in the list if curnode is not none and curnode col =col if value = remove the node if curnode =self _listofrows[rowself _listofrows[rowcurnode next else prednode next curnode next else change the node' value curnode value value otherwisethe element is not in the list elif value ! newnode _matrixelementnodecolvalue newnode next =curnode if curnode =self _listofrows[row