I have a sparse matrix in LIL (List of Lists) format. I want to test whether the matrix is symmetric or not. Let's say I have n non-default elements. What's the best complexity in terms or space and time I can achieve?
The best solution I have came up with so far is to traverse the matrix, looking at each non-default element (consisting of row, col and value) and storing that element in a hash-table and then checking whether two elements Element$(i, j, v_1)$ and $(j, i, v_2)$ have the same value or not. The time complexity for this is $\mathcal{O}(n)$ and space complexity is also $\mathcal{O}(n)$. It looks to me no scope of improvement in time complexity but I wonder whether space complexity could be improved or not without compromising the time complexity.
For sparse matrices we often uses either compressed sparse row format (CSR) or compressed sparse column format (CSC).
In CSR format there are three array, XADJ[n+1], ADJ[nnz] and VAL[nnz]. Information about the nonzero entries on the ith row is stored in at in a contiguous chunk of ADJ and VAL starting at index XADJ[i]. Specifically, ADJ[k] is the column index of the kth nonzero entry of the matrix and VAL[k] is the value of the kth nonzero. Normally, XADJ[n+1]=nnz stores the number of non-zero entries of the matrix. In this manner, CSR format allows convenient access to the rows of matrix. Similar, CSC format allows convenient access to the columns of the matrix
In your case, you can benefit from using a hybrid format. Specifically use CSR format for the strictly upper triangular part of the matrix and CSC format for the strictly lower triangular format, storing the diagonal entries in a separate array. This will allow you to determine that the matrix is symmetric in time proportional to the number of non-zeros and you can do the comparison in place with no extra storage.
You will have to adapt your other routines (sparse matrix vector multiply and LU factorization) to this format and that extra work may not be worth the effort.
Regardless, if you are using pointers and dynamic memory allocation to implement your linked list, then you stand to gain tremendously by switching to the more compact representation afforded by either CSR or CSC.
I hope this helps.