We can also use jagged arrays for this purpose
int[][] symmetric_matrix = new int[size][];
for (int i=0; i < size; i++)
...symmetric_matrix[i]=new int[max_diagonal/(size)];
On Wed, Jan 12, 2011 at 9:30 AM, Sathaiah Dontula wrote:
> 1 + 2 + + n ( max diagonal) = n ( n + 1) / 2.
> Max
1 + 2 + + n ( max diagonal) = n ( n + 1) / 2.
Max elements you can store is n ( n + 1) / 2 .
You can take an array of size n (n + 1) / 2 and store them.
Thanks,
Sathaiah
On Wed, Jan 12, 2011 at 9:50 AM, Azhar Hussain wrote:
> I have a symmetric matrix. I am wondering what would be the best
Well, u can use List of Lists. The List would contain head nodes of all the
lists and each list would contain a row. The length of every list will be 1
greater than the next of it's next list.
In this way:
The tail of list would contain a diagonal element which
L
L1 1
L2 4 2
L3 4 3
if the matrix is n x n and n is not huge > 5k
Use int arr[((n * n) - n ) / 2 + n];
One approach:
arr[0] = n;
c = 1;
for (i=n; i >= 0; i--)
for (j=0; j < i ; j++)
arr[c++] = get_element_at(n-i, j);
And u can access any element in O(1).
Programmers should realize their critical importance
Thanks for the help. It may not be symmetric on a diagonal. I have to
consider both situations
-
Azhar.
On Thu, Jan 13, 2011 at 3:37 PM, juver++ wrote:
> One-dimensional array.
> 1 2 4
> 2 3 5
> 4 5 6
> => [1, 2, 3, 4, 5, 6]
> Is your matrix summetric on a diagonal?
>
> --
> You received this m
One-dimensional array.
1 2 4
2 3 5
4 5 6
=> [1, 2, 3, 4, 5, 6]
Is your matrix summetric on a diagonal?
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this
I am wondering what data structure would best suit for this?
-
Azhar.
On Wed, Jan 12, 2011 at 11:11 AM, Abdul Rahman Shariff
wrote:
> i can tell 1 thing tht only
> (((n*n)-n)/2) +n elements are unique and the "(((n*n)-n)/2)" term is the
> one shoes the no of repeated elements and n represents th
i can tell 1 thing tht only
(((n*n)-n)/2) +n elements are unique and the "(((n*n)-n)/2)" term is the one
shoes the no of repeated elements and n represents the
diagonal elements hope this gives some usefull info (i havent gone through
any book nor do i guarantee optimal or best memory usage)
On W