Finding the transpose of a very, very large matrix

拟墨画扇 提交于 2019-12-05 22:02:35

Create n empty files (reserve enough space for n elements, if you can). Iterate through your original matrix. Append element (i,j) to file j. Once you are done with that, append the files you just wrote.

You need a Matrix class, such that your whole app accesses a matrix through an instance of the class. Then a transpose can just be setting a flag that reverses the indexes when accessing an element. Instant transpose!

The naïve way is to just read through the file 10000 times and find the corresponding columns for each row. This should be easy to implement but I don't know how much time it will take to run the program.

In your comments you mentioned outputing another file which you then should sort with sort. That's a bad idea since it will take forever to sort such a large file. Sorting is a complex (or at least resource-heavy) problem, so generalizing the transpose into a sort is probably the wrong way to do it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!