I need to implement a sparse matrix as efficiently memory-wise as I can in Java.I receive a matrix with more 0 than other values and I need to save it efficiently.I was thinking of using an array with an Object containing value and position composed of the line*max nr of columns+the column.
Asked
Active
Viewed 673 times
1
-
Would a `Map` not be suitable? – user000001 Feb 28 '13 at 18:09
-
i thought something like that.I want to know the best way memory-wise to save a sparse matrix. – Emil Grigore Feb 28 '13 at 18:12
2 Answers
0
Depends entirely on what operations you are doing on said matrix which implementation will suit your needs.
e.g. if all you are doing is updating values and retrieving them a Map<Point, Value>
will work.
Addition is also easy in this, but multiplication becomes very difficult.

djechlin
- 59,258
- 35
- 162
- 290