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
Graphs are data structures which consist of a set of vertices & a set of edges which connect the vertices. A graph where the edges are directed is called directed graph. Or else, i

W h at are the different ways by which we can represent graph?  Represent the graph drawn below using those ways.     T he d iff e r e nt w a y s by

Polynomials like  5x 4    +  2x 3    +  7x 2     +  10x  -  8  can  be  represented by using arrays. Arithmetic operations such as addition & multiplication of polynomials are com

Q. Illustrate the result of running BFS and DFS on the directed graph given below using vertex 3 as source.  Show the status of the data structure used at each and every stage.

The insertion procedure in a red-black tree is similar to a binary search tree i.e., the insertion proceeds in a similar manner but after insertion of nodes x into the tree T, we c

Question 1 Discuss the advantages of implementation checks preconditions Question 2 Write a ‘C' program to search for an item using binary search Question 3 Show that To

A significant aspect of Abstract Data Types is that they explain the properties of a data structure without specifying the details of its implementation. The properties might be im

The quick sort algorithm exploit design technique Divide and Conquer

I was wanting to know where this web site was created. My second question is,,, are the online tuters accredited teachers? If they are, are they only working for the website or ma

Determine about the push operation A Container may or may not be accessible by keys, so it can't make assumptions about element retrieval methods (for example, it cannot have a