In: Computer Science
Describe the types of arrays and operations that can be
performed of them. [10
Array
Generally , Array can be defined as a collection of homogeneous data items referred by a common name. Array is a derived data type.Usually to declare or use several number of (100) variables of same type , we go for arrays.But this same task can also be done by declaring different different variables individually as below
int a, aa, ab......az, b, ba,bb.....bz,.......until 100 items.
But this way of declaring needs large number of variable names and this way has a complexity of remembering variable names ,that is the reason why arrays are preferred while using large number of similar data items.
Example Student [10];
This is a student array which contains 10 variables referred by common name student.if 6 th variable is to referred found , it is done as student[5].The index of variables of an array are indicated within the subscript denoted as "[ ]".The index starts from '0'.
Types of Arrays
1).single dimensional array: it is simply an ordered list of homogenous data items.It involves three steps as below.
(i).declaration of array
datatype [ ] arrayname;
Note : Size of the array must not be given during declaration.
(ii) Allocation of memory location for the array
arrayname = new datatype[size];
It is allocated dynamically with the help of 'new' operator.
(iii) initialization
Inserting values into the array.Initialization is performed with the loops or direct assignment.
2).Multidimensional Arrays : consists of homogeneous data stored in more than one dimension.
subject [2][5];
Operations of arrays
1).Traverse − Employed for accessing the every data item just singly.
2).Insertion − includes a fresh data item for offered index.
3).Deletion − Deleting the element present towards the offered index.
4).Search − Searches the element with the offered index.
5).Update − updates the element on the offered index.
Arrays permit efficient random access , but not the insertion and deletion of elements .Arrays are simple due to predefined methods in java.