# Matrix Data Type

• 02-26-2011, 10:08 PM
fraB3422
Matrix Data Type
I need some help with a programming assignment and I've heard that this forum is pretty good. I have to implement a matrix abstract data type which does not allocate memory for 0 values, using linked lists to implement the matrix class.

If I was storing a matrix, I would use a 2d array, but I'm not familiar with a matrix data type. Any help would be appreciated
• 02-26-2011, 10:16 PM
Fubarable
They're trying to get you to create a sparse array or sparse matrix, a concept that has been discussed quite a bit online. You may wish to Google these terms.
• 02-26-2011, 10:24 PM
fraB3422
Ok, I have done some research before on sparce matrix, and know they are composed of mainly 0 values, so if we wanted a matrix abstract data type that didn't allocate space for 0's, I'm not sure how a linked list comes into the equation
• 02-26-2011, 10:55 PM
fraB3422
So if I had a matrix:

3 4 0 0
1 0 0 4
9 2 2 0
0 0 1 0

would my Linked List be [3,4,1,4,9,2,2,1]?
• 02-26-2011, 11:03 PM
fraB3422
I know how to take a matrix in as an argument in my method, and then add the non 0 elements to a SinglyLinkedList one element at a time, does this seem like the way to go?
• 02-26-2011, 11:06 PM
Fubarable
Your list won't contain simple numbers but objects as you'll need to have some way to retrieve the indices, perhaps storing them with the data. Have a look at this PPT lesson for tips: Sparse Arrays.ppt
• 02-27-2011, 02:15 AM
fraB3422
Thanks for the powerpoint!

In the example that they use this matrix:

0 0 0 0 0 12
0 0 0 0 0 0
0 0 0 0 0 0
0 8 0 0 0 33
0 0 0 17 0 0
0 0 0 0 0 0

It says to represent the matrix as an array of linked lists would be:

Pos 0 in the list has: 5,12 (meaining col 0 row 5 has a 12)
Pol 3 in the lis has: 1,8 linked to 5,33
Pos 4 in the list has: 3,17

Isn't this only 1 list and each 'node' contains an array of nodes (like node 3 has 2 nodes?
• 02-27-2011, 03:08 AM
fraB3422
can anyone show me how to create a linkedListArray?