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
  • 909
  • 3
  • 12
  • 27

2 Answers2

1

A Guava Table can be sparse.

The Colt library also has sparse matrices.

lbalazscs
  • 16,984
  • 7
  • 41
  • 48
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
  • 57,408
  • 33
  • 153
  • 271