1

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.

Emil Grigore
  • 929
  • 3
  • 13
  • 28

2 Answers2

1

A Guava Table can be sparse.

The Colt library also has sparse matrices.

lbalazscs
  • 17,474
  • 7
  • 42
  • 50
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