Question

Programming pearls Problem 7 is about transposing a 4000 x 4000 matrix stored on a magnetic tape.
My solution was to simply use a temporary variable and swap the contents of a[i][j] and a[j][i].
The solution given by the author confused me a little bit. He says we should:

  1. Prepend the row and column indices to each
  2. sort the records in the matrix by row
  3. remove the appended indices.

Why do you have to go through so much trouble to get this done? Does it have something to do with magnetic tapes?

Was it helpful?

Solution

I think the meaning of this exercise is as follows.

  1. For the computer in that old age, there was no sufficient RAM to hold a matrix with that size. So your proposed swapping method could not be feasible. In order to transpose such a large matrix, the external memory storage, i.e. magnetic tape, should be exploited.

  2. However, the reading and writing tapes back and forth is rather slow. But tapes are serial storage device. So reading and writing in serial can save a lot of time.

  3. Merge sort is very suitable for such serialization storage because of the way it accesses elements, as what is said at this wikipedia page. So I believe the "system tape sort" meant merge sort on tape.

After keeping in mind the three points above, I think you can understand this exercise.

OTHER TIPS

I think magnetic tapes means: to find one certain element, you have to travel from the beginning to that element.

But I have difficulty in understanding "what is system tape sort" and "why it works".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top