Types Of Array in Data Structure



Introduction
            An array is a group of related data items that share a common name. This data structure is useful in maintaining table and queue in several applications. Some common examples are,
An array for storing the rainfall of 365 days of a year,
An array of scores of a set of team,
A bit matrix table for computer screen,
A symbol table, etc…
We can define an array name salary to present a set of salaries of a group of employees. Writing a number called index number or subscript in brackets after the array name indicates a particular value. For example,
                                             Salary [10];
Represent the salary of the 10th employee. While the complete set of values is referred to as an ARRAY, the individual values are called elements. Arrays can be of any variable type.
               The ability to use a single name to represent a collection of items and to refer to an item by specifying the item number enables us develops concise in efficient program. For example:à A loop with the subscript as the control variable can be used to read the entire array, perform the calculation and, printout the results.


TYPES OF ARRAYS: 

One-dimensional arrays:
·        A list of items can be given one variable name using only one subscript and such a variable is called single subscripted value or one-dimensional array.
·        Storage structure for one-dimensional array: The memory of computer is linear and one dimensional array is started in continuous memory cells storage of an element a [I+1] will be adjacent to the storage for element a[I],for I=1 to n.
·        The declaration new line (int a [100]) reserves 100 successive memory locations each large enough to contain a single integer. The address of the first of this location is called the base address of the array ‘a’ and is denoted by base (a).
·        If ‘s’ is the size of each individual element of the array then the reference to the element [0] is to the element at location base (a) then reference to a [1]
·        To the element at base (a) + s. a reference to a [2] is the element at base (a)+ 2* s. In general the reference to a [I] is to the element at location base (a)+I*s.


Two-dimensional arrays:
·        Array is used to stored the list of value sometime there will situation where a value in the form of table to be stored.
·        Storage structure for two-dimensional array in a two dimensional array  the data is arranged in rows and column , however the machine memory is arranged as a row of memory all.
·        In a two dimensional array the data is started in cells row by row that is used first started the first row of the array then the second row of the array and then the next the so on. Such a storage scheme is called row major order.
·        The alternative is to store in an array column by column, it is called column major order.
·        Let supposed that a two dimensional array integer array is store in row major sequence and let base (a) be the address of first element at the array a [r1][r2] are the range of first and second dimensional array respectively.
·         Base [a] is the address of a [0][0]. If ‘s’ is the size of each element then the address of any element a[I1][i2] can be calculated as ,  Base (a)+(i1*r1+i2)*s
Where,
ü  a is array name,
ü  if row major then i1 is the row of an array and i2 is column of an array,
ü  if column major then i1 is column of an array and i2 is row of an array;
ü  s is the size of element.
Figure, followed for row major,


Multi dimensional array:
·        The different compiler allows different level or dimensional array.
·        C allows arrays of three or more dimensions. The compiler determines the exact limit.
·        The general form of a multi-dimensional array is  
Type array name [s1][s2][s3]….[sn]; Where sn is the size of the n th dimensional for ex.
                              Int table [5][4][3];
·        In the three-dimensional array the row column and the height must be declared.
·        The above stated statement declares the three dimensions.  The first value shows the row, the second shows column of the array and the third value shows the height of the array.
·        The height of array is known as level. The logical memory the elements are stored as, First value is stored for first level. In the first as row major sequence And so on for each and every level of size.
 

 
Types Of Array in Data Structure Types Of Array in Data Structure Reviewed by Unknown on 7:40:00 AM Rating: 5

No comments:

Powered by Blogger.