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 order means that the elements of the array are indexed. Homogeneous means that all the elements of the array must be of the same type.

Array Representation:

In the Data Structure, there are two types of array representation exist:

i. One Dimensional Array

ii. Two-Dimensional Array

One Dimensional Array:

Values in a mathematical set are written as shown below:
a={5, 7, 9, 4, 6, 8}
These values are referred to in mathematics as follows:
a0, a1, a2
In Data Structure, these numbers are represented as follows:
a[0], a[1], a[2]
these values are stored in RAM.

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;
}

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;
}

Algorithm for traversing One-dimensional array:

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

Two-Dimensional Array:

Two-Dimensional Array
These values are referred to in mathematical as follows:
A0,0 A0,1 A0,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 the RAM.