# Array Representation in Data Structure

## Array:

An array is defined as a finite ordered set of homogeneous elements. Finite means that there is a specific number of elements and ordered means that the elements of the array are indexed. Homogeneous means that all the elements of the array must be of the same type.

There are two types of array exists:

### One Dimensional Array:

Values in a mathematical set are written as shown below :

**a={5, 7, 9, 4, 6, 8}**

These values are referred in mathematics as follows :

**a _{0}, a_{1}, a_{2}**

In Data Structure, these numbers are represented as follows :

**a[0], a[1], a[2]**

these values are stored in RAM as follows :

#### Algorithm for insertion into One-dimensional array:

Algorithm fnInsertion_1D_Array(arrData, n, k, item) { for(i=n-1;i>=k-1;i--) arrData[i+1]=arrData[i]; arrData[k-1]=item; n=n-1; } // End of Algorithm

#### Algorithm for deletion from One-dimensional array:

Algorithm fnDeletion_1D_Array(arrData, n, k) { item=arrData[k-1]; for(i=k-1;i<n-1;i++) arrData[i]=arrData[i+1]; n=n-1; return item; } // End of Algorithm

#### Algorithm for traversing One-dimensional array:

Algorithm fnTraverse_1D_Array(arrData, n) { for(i=0;i<n;i++) print arrData[i]; } //End of Algorithm

### Two Dimensional Array:

These values are referred in mathematical as follows :

**A _{0,0} A_{0,1} A_{0,2}**

In Data Structure, they are represented as follows :

**a[0][0] a[0][1] a[0][2]**and so on

It may be imagined that these values are stored in RAM as follows :