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
Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g. (define stack1 (make-stack))  (define stack2 (make-stack)) W

How to measure the algorithm's efficiency? It is logical to examine the algorithm's efficiency as a function of some parameter n showing the algorithm's input size. Instance

1) preorder, postorder and inorder 2) The main feature of a Binary Search Tree is that all of the elements whose values is less than the root reside into the nodes of left subtr

How do collisions happen during hashing? Usually the key space is much larger than the address space, thus, many keys are mapped to the same address. Assume that two keys K1 an

Threaded Binary Tree : If a node in a binary tree is not having left or right child or it is a leaf node then that absence of child node is shown by the null pointers. The spac

A B-tree of minimum degree t can maximum pointers in a node T pointers in a node.

The Ruby Programming Language Although data structures and algorithms we study aren't tied to any program or programming language, we need to write particular programs in speci

an electrical student designed a circuit in which the impedence in one part of a series circuit is 2+j8 ohms and the impedent is another part of the circuit is 4-j60 ohm mm program

Explain Floyd's algorithm It is convenient to record the lengths of shortest paths in an n by n matrix D known as the  distance matrix: the element d ij   in the i th   row an

extra key inserted at end of array is called