Multidimensional array, Data Structure & Algorithms

Q. The system allocates the memory for any of the multidimensional array from a big single dimensional array. Describe two mapping schemes that help us to store the two dimensional metrics in the one-dimensional array.    

Ans.

A two dimensional array is declared similar in the way we declare the one-dimensional array except that we state the number of elements in both the dimensions. For example,

int grades[3][4];

The first bracket ([3]) tells about the compiler that we are declaring in the 3 pointers, each of which is pointing to an array. Here we are not talking about a pointer variable or the pointer array. Instead, here we are saying that each element of the first dimension of the two dimensional array reference a corresponding second dimension. In the example we have, all the arrays pointed to by the first index are having the same size. The second index can be of the variable size. For example, the earlier statement declares a two- dimensional array in which there are 3 elements in the first dimension and 4 elements are there in the second dimension.

Two-dimensional array can be represented in memory in the following two ways:

1. The Row major representation technique: To attain this linear representation, the first row of the array is stored in the first memory locations or addresses reserved for the array, then the second row and so on.

2. The Column major representation technique: In this all the elements of the column are saved next to one another. In the row major representation, the address is calculated and obtained in a two dimensional array as per the following formula

The address of a[i][j]=base(a)+(i*m+ j)*size, where the base(a) is the address or location of a[0][0], m is second dimension of array a and size represent size of the data type.

Posted Date: 7/12/2012 8:31:29 AM | Location : United States







Related Discussions:- Multidimensional array, Assignment Help, Ask Question on Multidimensional array, Get Answer, Expert's Help, Multidimensional array Discussions

Write discussion on Multidimensional array
Your posts are moderated
Related Questions
draw a flowchart which prints all the even numbers between 1-50

N = number of rows of the graph D[i[j] = C[i][j] For k from 1 to n Do for i = 1 to n Do for j = 1 to n D[i[j]= minimum( d ij (k-1) ,d ik (k-1) +d kj (k-1)

implement multiple stacks in a single dimensional array. write algorithm for various stack operation for them

In internal sorting, all of the data to be sorted is obtainable in the high speed main memory of the computer. We will learn the methods of internal sorting which are following:

Description A heap is an efficient tree-based data structure that can be used as a priority queue. Recall that the abstract data type of a priority queue has the following opera

In the earlier unit, we have discussed about the arrays. Arrays are data structures of fixed size. Insertion & deletion involves reshuffling of array elements. Thus, arraymanipulat

Illustrate Trivariate Colour Models Conventional colour models based on the tristimulus theory all contain three variables and so are called trivariate models. Let us now consi

Q. Can a Queue be represented by circular linked list with only one pointer pointing to the tail of the queue? Substantiate your answer using an example. A n s . Yes a

Q. How can we free the memory by using Boundary tag method in the context of Dynamic memory management?

Ask consider the file name cars.text each line in the file contains information about a car ( year,company,manufacture,model name,type) 1-read the file 2-add each car which is repr