answersLogoWhite

0

An array offers the most efficient method of implementing a matrix (an n-dimensional array). All arrays implicitly convert to pointers, so a pointer can be treated as an array even when it doesn't actually refer to one (so long as you don't access memory that doesn't actually belong to your program, of course).

If you don't want to use an array, use linked lists instead. Each node is a member of two or more lists, so each node requires at least one node pointer per list. If you require bi-directional traversal, each node requires at least two node pointers per list. For a two-dimensional, bi-directional matrix, each node requires up, down, left and right node pointers. For a three-dimensional, bi-directional matrix, each node requires forward and backward node pointers. For a generalised n-dimensional, bi-directional matrix, each node requires an array of n pairs of pointers, one pair for each dimension.

There are very few reasons to resort to linked lists to implement a matrix. For any given number of dimensions and elements, arrays will use far less memory and are much quicker to navigate than a linked list. One of the few exceptions is when you need to slice the matrix (to insert or extract rows or columns, for instance). In these cases it is generally more efficient to break or create a sequence of links than it is to move elements in order to remove or create gaps in the array, not to mention the reallocation of the entire matrix whenever an insert is required. However, this can be largely alleviated by implementing the matrix as separately allocated arrays. E.g., for a three-dimensional array of type T, use a T*** to refer to an array of type T**, where each pointer in that array refers to separately allocated arrays of type T*, where each pointer in those arrays refers to separately allocated arrays of type T. The pointer arithmetic is exactly the same as it would be if the matrix were allocate contiguously as a single block.

Another reason we might prefer a linked list implementation is when the array is sparse and largely contains no data. In this case, each node pointer refers to the nearest neighbouring node that holds data -- the non-data nodes in between can be omitted completely, thus reducing memory consumption and speeding up traversal.

Note that space and time complexities only give us a general sense of an algorithm's performance. Only a real-world performance test will tell us which algorithm is most suitable for a given task. There is no one-size-fits-all solution, hence C does not provide a built-in matrix type.

User Avatar

Wiki User

8y ago

Still curious? Ask our experts.

Chat with our AI personalities

EzraEzra
Faith is not about having all the answers, but learning to ask the right questions.
Chat with Ezra
DevinDevin
I've poured enough drinks to know that people don't always want advice—they just want to talk.
Chat with Devin
JudyJudy
Simplicity is my specialty.
Chat with Judy

Add your answer:

Earn +20 pts
Q: How do you create c program for matrix using pointer without array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Cannon matrix multiplication program?

maltiplication of matrix for algorithme


How do you Write A program in c language for checking a diagonal matrix?

Write a program in c++ that take input in a integer matrix of size 4*4 and find out if the entered matrix is diagonal or not.


How can you write a program which proves that a multiple of a matrix and its determinant is an identity matrix?

Automated proofs are a complicated subject. If you are not an expert on the subject, all you can hope for is to write a program where you can input a sample matrix (or that randomly generates one), and verifies the proposition for this particular case. If the proposition is confirmed in several cases, this makes the proposition plausible, but is by no means a formal proof.Better try to prove it without writing any program.Note: it is not even true; it is the inverse of the matrix which gives identity when is multiplied with the original matrix.


Write a c program to determine whether a matrix is singular or not?

A c program is also known as a computer program. A singular matrix has no inverse. An equation to determine this would be a/c=f. <<>> The determinant of a singular matix is zero.


What is matrix programming in C programming?

C Examples on Matrix OperationsA matrix is a rectangular array of numbers or symbols arranged in rows and columns. The following section contains a list of C programs which perform the operations of Addition, Subtraction and Multiplication on the 2 matrices. The section also deals with evaluating the transpose of a given matrix. The transpose of a matrix is the interchange of rows and columns.The section also has programs on finding the trace of 2 matrices, calculating the sum and difference of two matrices. It also has a C program which is used to perform multiplication of a matrix using recursion.C Program to Calculate the Addition or Subtraction & Trace of 2 MatricesC Program to Find the Transpose of a given MatrixC Program to Compute the Product of Two MatricesC Program to Calculate the Sum & Difference of the MatricesC Program to Perform Matrix Multiplication using Recursion