Hi Professor,
If we have a matrix A with N rows and N columns, we can compress it into two new matrices, AX and AY, each with N rows and M columns. The problem is, we don’t know what M is when allocating memory for AX and AY. I could go through the original matrix A to find the row with the most non-zero elements and use that number as M. But this isn't very efficient because it means I would need to create the whole matrix A first, which uses a lot of memory, and iterate it twice—once to determine M and once to fill in AX and AY. Additionally, many rows in AX and AY might not use all the space allocated, leading to wasted memory.
To solve this, I’m thinking of using arrays that can grow as needed to store the rows of AX and AY. This way, each row can be as long as necessary, and we don’t need to figure out M ahead of time. It also means we can create the compressed matrices directly without needing to build A first.
Another idea I had is to combine AX and AY into one data structure to make things simpler and more efficient. Instead of storing values and indices separately, I would store them together as pairs in the same array. I think this would improve performance.
Could you please let me know if these approaches are acceptable? If not, could you clarify the required data structure we should use? Thank you for your time.