You are on page 1of 5

#include<stdio.

h>
#include<conio.h>
int add(int, int); /*declaration */
main()
{
int a,b,c; /*declaration*/
printf(“Enter the elememts”); /*statement*/
scanf(“%d%d”,&a,&b); /*input*/
c=add(a,b); /*function call*/
printf(“%d”,c); /*display*/
}
int add(int x, int y) /* definition*/
{ int z;
z=x+y;
return z;
}
structure
struct st
{int a;
float b;
};
Struct st;

Primitive data structures are integers, real numbers, characters and pointers and
their corresponding storage representation. Non primitive data structures can
be classified as arrays, lists and files. An array is ordered set which consists of a
fixed number of objects.
int a[10];
a[0] a[1] A[9]
1000 1002 1004 1006 1008 1010 1012 1014 1016 1018
a[0]……………………………………………………………………………………………………….a[n-1]
for storing n numbers.
…………
int a[100], i, n;
for(i=0;i<n;i++) /*i index */
scanf(“%d”, &a[i]);
for(i=0;i<n;i++)
printf(“%d”, a[i]);
……..


a[0,0] a[0,1] A[0,2]
A[1,0] A[1,1] A[1,2]
A[2,0] A[2,1] A[2,2]

2D-array

a[0,0] a[0,1] A[0,2]
A[1,0] A[1,1] A[1,2]
A[2,0] A[2,1] A[2,2]

A list on the other hand is an ordered set consisting of a variable number of
elements to which insertions and deletions can be made.

A file is typically a large list that is stored in the external memory of a computer.

The simplest data structures that makes use of computed address to locate it’s
elements is the one dimensional array we have called a vector. Normally a
number of memory locations is sequentially allocated to the vector.

A vector size is fixed and therefore requires a fixed number of memory
locations.
In general, a vector with a subscript lower bound of one can be represented
diagrammatically as in figure 1, where L0 is the address of the first word
allocated to the first element of a, and c represents the number of words
allocated to each element.

Lo

.
.
.
A[i]
.
.
.


Fig. 1



The address of Ai is given by the following equation:

lOC( Ai )= L0 + c* (i-1)


Let us consider the more general case of representing a Vector capital A whose
lower bound for its subscript is given by some variable b. The location of capital
Ai is then given by

lOC( Ai )= L0 + c*(i-b)

A programming language which can read a value for n at runtime and declare a
vector of n elements during the execution of the program is said to be able t o
allocate memory dynamically.

A multidimensional array can be represented by an equivalent one
dimensional array.

For example, a two dimensional array consisting of two ro ws and four
columns is stored sequentially by columns as

𝐴[1,1], 𝐴[2,1], 𝐴[1,2], 𝐴[2,2], 𝐴[1,3], A[2,3],A[1,4],A[2,4]

The address of element A[i,j] can be obtained by evaluating the expression
L0+(j-1)*2+i-1

In general, for a two dimensional array consisting of n rows and m columns (
which is stored by column) , the address of element A[ i,j] is given by the linear
expression
L0+(j-1)*n+i-1.

in many programming languages a two dimensional array will be stored row by
row ( row major) instead of column by column ( column major). An array with

subscripts having lower bound of 1 consisting of n rows and m columns will be


stored sequentially as
𝐴 1,1 , 𝐴 1,2 , … , 𝐴[1, m], 𝐴[2,1], 𝐴[2,2], …, A[2,m], …, A[n,1],A[n,2],…A[n,m]

The address of matrix Element A[i,j] is given by the expression

L0+(j-1)*m+(j-1)

The location of Element 𝐴!" is given by

𝑙𝑜𝑐(𝐴!" ) = 𝐿! + (𝑖 − 𝑏! ) ⋅ (𝑢! − 𝑏! + 1) + (𝑗 − 𝑏! )



Question: the location of 𝐴!" , when 𝑏! = −2, 𝑏! = 2 and 𝑢! = 3

A two-dimensional array can be used to represent a polynomial in two variables.
In a programming language that permits subscripts to have zero values, the

coefficient of the term xi yj would be stored in the element identified by row i and
column j of the array. If we restrict the size of an array to a maximum of 5 rows
and 5 columns, then the powers of x and y in any term of the polynomial must not
exceed a value of 4.
The array representation of polynomial 2𝑥 ! + 5𝑥𝑦 + 𝑦 ! is given as
and the array for 𝑥 ! + 3𝑥𝑦 + 𝑦 ! + 𝑦 − 𝑥

0 1 1 0 0
−1 3 0 0 0
1 0 0 0 0
1 0 0 0 0
0 0 0 0 0

A number of disadvantages are evident in using this representation. In the first
case, the to be sparsely filled with non-zero elements. Exponents within each
polynomial charm are restricted in size. In the next chapter a more efficient
representation of such polynomial will be given this can be accomplished by
using a type of storage allocation other than sequential allocation.

In a number of applications involving mattresses, there are instances where only
a part of each Matrix need to be stored. Example of such an application will now
be discussed. Suppose that the solution to the specialised system of equations
which follows is sought:
A11 X1 = b1
A21 X1 + A22 X2 = b2
A31X1+ A32X2 + A33X3 = b3
………………………………………………………….
An1X1+An2X2+.....+AnnXn=bn

This problem can be solved by the usual methods of setting up a two-
dimensional open square Coefficient elements in storage. In so doing coma
common nearly half of the matrix coefficients are not used. We could solve a
large system of equation if you could represent this triangular array by an
equivalent one dimensional array. In the given system, there are
𝑛(𝑛 + 1)

2
coefficient elements. Therefore, a vector representation must contain at least an
equivalent number of elements.

The elements of the triangular array can be stored as a vector in the order
A11A21A22A31 A32 A33 ... Ann
For element aij is given by



(𝑖 − 1)𝑖
+ 𝑗
2

You might also like