Professional Documents
Culture Documents
Module II - DSA
Module II - DSA
Array
One Dimensional Array
One Dimensional Character Array
Two Dimensional Array
Two Dimensional Character Array
Two Dimensional Character Array
Two Dimensional Character Array
#include <stdio.h>
int main()
{
char Name[6][10] = {"Mr. Bean","Mr. Bush","Nicole","Kidman","Arnold","Jodie"};
int Count = 0 ,i, j;
for(i = 0; i <= 5; i = i + 1)
{
for(j = 0; Name[i][j] != '\0'; j = j + 1)
{
if(Name[i][j] == 'a' || Name[i][j] == 'A')
Count = Count + 1;
printf("%c", Name[i][j]);
}
printf("\n");
}
printf("The number of a's is %d.\n\n", Count);
return 0;
}
Row Major – Address Calculation
printf("enter the number of row=");
scanf("%d",&r);
printf("enter the number of column=");
scanf("%d",&c);
Matrix Multiplication – C Program
printf("enter the first matrix element=\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("enter the second matrix element=\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&b[i][j]);
}
}
Matrix Multiplication – C Program
printf("multiply of the matrix=\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
mul[i][j]=0;
for(k=0;k<c;k++)
{
mul[i][j]+=a[i][k]*b[k][j];
}
}
}
Matrix Multiplication – C Program
//for printing result
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d\t",mul[i][j]);
}
printf("\n");
}
return 0;
}
Matrix Multiplication – C Program
Sparse Matrix
• A matrix is a two-dimensional data object made of m rows and n columns,
therefore having total m x n values.
• If most of the elements of the matrix have 0 value, then it is called a sparse matrix.
Sparse Matrix
Why to use Sparse Matrix instead of simple matrix ?
• Storage: There are lesser non-zero elements than zeros and thus lesser memory
can be used to store only those elements.
A polynomial p(x) is the expression in variable x which is in the form (ax n + bxn-1 +
…. + jx+ k), where a, b, c …., k fall in the category of real numbers and 'n' is non
negative integer, which is called the degree of polynomial.
10x2 + 26x, here 10 and 26 are coefficients and 2, 1 is its exponential value.
• The sign of each coefficient and exponent is stored within the coefficient and the
exponent itself
• Additional terms having equal exponent is possible one
• The storage allocation for each term in the polynomial must be done in ascending
and descending order of their exponent
Polynomial