Efficient (time and space complexity) data structure for dense and sparse matrix

前端 未结 2 1051
日久生厌
日久生厌 2021-01-17 17:44

I have to read a file in which is stored a matrix with cars (1=BlueCar, 2=RedCar, 0=Empty).

I need to write an algorithm to move the cars o

2条回答
  •  伪装坚强ぢ
    2021-01-17 18:03

    In a somewhat similar task, I simply made use of Compressed Row Storage.

    The Compressed Row and Column (in the next section) Storage formats are the most general: they make absolutely no assumptions about the sparsity structure of the matrix, and they don't store any unnecessary elements. On the other hand, they are not very efficient, needing an indirect addressing step for every single scalar operation in a matrix-vector product or preconditioner solve.

    You will need to be a bit more specific about time and space complexity requirements. CSR requires an extra indexing step for simple operations, but that is a minor amount of overhead if you're just doing simple matrix operations.

    There's already an existing C++ implementation available online as well.

提交回复
热议问题