I'm reading and trying to work through some problems in my book in preparation for up and coming Data Structures finals. I came across this question in my book and I'm sorta scratching my head on it.
Any dare to take a stab at it?
Thanks in advance!
Mike
=======================
The main diagonal of a square matrix consists of the entries for which the row and column indices are equal. A diagonal matrix is a square matrix in which all entries not on the main diagonal are zero.
a) Describe a way to store a diagonal matrix without using space for entries that are zero.
b) Give the corresponding index function.
Here's what I deduce from my reading material.
a)
I’d implement a triangular table in a contiguous array by sliding each row out after the one above it. By placing each piece of data in the beginning of each row I store my data in a diagonal form.
b) (i,j) corresponds to 1/2 i (i+1)+j
----------------------------------------------------
Anyone care to sanity check me?
Thanks in advance,
Mike