Array and two-dimensional array, Data Structure & Algorithms

Q. Describe the term array.  How do we represent two-dimensional arrays in memory?  Explain how we calculate the address of an element in a two dimensional array.                                                

Ans:

An array is a systematic arrangement of objects generally in rows and columns

Each memory location is defined by an array element. An array element is similar to one variable except it is identified by an index value as a substitute of a name. An index value is a number used to recognize an array element.

Declaration of a two dimensional array- A two dimensional array is declared similarly as we declare a one-dimensional array except that we specify the number of elements in both dimensions. Such as,

int grades[3][4];

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

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

1.  Row major representation: To attain b this linear representation, the first row of the array is stored in the first memory locations reserved for the array, then the second row and this process continues.

2.  Column major representation: In this elements of the column are stored next to one another.

In row major representation, the address is always calculated in a two dimensional array as per the formula written below. The address of a[i][j]=base(a)+(i*m+ j)*size in which base(a) is the address of a[0][0], m is second dimension of array a and size represent size of the data type.

Posted Date: 7/10/2012 3:37:49 AM | Location : United States







Related Discussions:- Array and two-dimensional array, Assignment Help, Ask Question on Array and two-dimensional array, Get Answer, Expert's Help, Array and two-dimensional array Discussions

Write discussion on Array and two-dimensional array
Your posts are moderated
Related Questions
Post order traversal: The children of node are visited before the node itself; the root is visited last. Each node is visited after its descendents are visited. Algorithm fo

A binary search tree is used to locate the number 43. Which of the following probe sequences are possible and which are not? Explain. (a) 61 52 14 17 40 43 (b) 2 3 50 40 60 43 (c)

Problem 1. Explain about the doubly linked list with neat diagram. Diagram Explaining doubly linked list 2. Explain what are the criteria to be used in evaluatin

This is the most extensively used internal sorting algorithm. In its fundamental form, it was invented by C.A.R. Hoare in the year of 1960. Its popularity lies in the easiness of i

how can i delete from deque while deletion is restricted from one end

The following are several operations on a AA-tree: 1. Searching: Searching is done using an algorithm which is similar to the search algorithm of a binary search tree. 2. Ins

A linear collection of data elements where the linear node is given by means of pointer is known as Linked list

Q. Establish the usage of linked lists for polynomial manipulation.                                       Ans. Usag e of Linked List for Polynomial Manipulation. Link

Q. Give the adjacency matrix for the graph drawn below:                                                 Ans: Adjacency matrix for the graph given to us

Sorting is significant application activity. Several sorting algorithms are obtainable. But, each is efficient for a specific situation or a specific kind of data. The choice of a