IGNOU MCA MCS-21 Solved Assignments 2011
IGNOU MCA MCS-21 Solved Assignments 2011
This assignment has three questions, which carry 80 marks. Answer all the
questions. Viva-voca carries 20 marks. You may use illustrations and
diagrams to enhance the explanations. Please go through the guidelines
regarding assignments given in the programme Guide. Ensure that you don’t
copy the program from course material or any other source. All the
implementations should be in C language.
Question 1:
(a )Write any 5 x 8 Matrix that has exactly nine nonzero terms such that at
least one nonzero term appears in each row and each columns. For this
sparse matrix, draw the linked representation.
Ans. Matrixes with good number of zero entries are called sparse matrixes.
A triangular matrix is a square matrix in which all the elements either
above or below the main diagonal are zero.
Now we will consider the sparse matrix from storage point of view.
Suppose that the entire sparse matrix is stored. Then, a considerable
amount of memory which stores the matrix consists of zeroes. This is
nothing but wastage may count to mega bytes. So, an efficient method
of storing sparse matrixes has to be looked into.
0 1 2 3 4 5 6 7
0 0 0 0 0 0 5 0 0
1 0 4 0 0 0 0 0 0
2 0 0 0 0 0 0 9 0
1
3 0 0 3 0 0 0 0 0
4 0 0 0 8 0 0 0 0
7 7 9
0 3 5
1 1 4
2 4 9
3 1 3
4 0 1
5 2 8
# include <stdio.h>
#include <conio.h>
Void main()
2
{
{
If(a[i] [j] != 0)
Getch( );
The Output :- Enter the order of the matrix. The order should be less
than 5 x 5
33
1 2 3
0 1 0
0 0 4
1 1 1
1 2 2
1 3 3
3
2 2 1
3 3 4
Ans.
(b) Design a suitable external (i.e one that can be used for input and
output) representation for a sparse matrix. Your representation should
not require explicit input of the zero terms.
Ans. In the array implementation of lists, we will use array to hold the
entries and a separate counter to keep track of the number of positions
are occupies. A structure will be declared which consist of array and
counter.
Count 1 2 3 4 5 6 7 8
11 22 33 44 55 66 77
INSERTION
Position and this will continue until the (r)th element to (r+1)th
position, where ‘r’ is the position of insertion.
4
For doing this, the count will be incremented
Before Insertion
Count 1 2 3 4 5 6 7 8
11 22 33 44 55 66 77
Step 1
Count
11 22 33 44 55 66 77 77
Step 2 Count
11 22 33 44 55 66 66 77
Step 3 Count
11 22 33 44 55 55 66 77
Step 4 Count
11 22 33 44 55 66 66 77
Step 5 Count
11 22 33 35 44 55 66 66 77
#include <stdio.h>
#include <conio.h>
5
Void main
Type of struct
Int count;
} list;
/ * prototypes of functions * /
If(element !=0)
Temp - -;
6
}
While (test)
fflush (stdin);
Test = 0;
Else
i++;
Getch ( );
Int i;
7
{
Start _>data[i]);
/*main function*/
Void main( )
List |;
Fflush(stdin);
Traverse(&|);
Fflush(stdin);
Fflush(stdin);
Traverse (&|);
Question 2:
Draw two binary trees whose preorder listing is abcdefgh and whose
postorder listing is dcbgfhea. Also, list the nodes of binary trees
inorder and level order.
8
Ans. There are three types of tree traversals, namely, preorder, post
order and inorder.
Preorder Traversal:-
Each node is visited before its children are visited, the root is visited
first.
Algorithm For Pre Order Traversal:-
9
BOOK
PREFACE
CHAPTER SUMMARY
CHAPTER 8
1
SECTION 1
SECTION 1 SECTION 4
SECTION
SECTION SECTION
1.1
4.1 4.2
SECTION
4.1.1
10
1. Traversal left sub-tree in post order
/
ROOT
The given post order listing is “dcbgfhea”. So, the binary tree for
post order is on the next page:-
h e
b g
d c
11
Algorithm For Inorder Traversal
2. Visit node
For eg.
+
* -
/ 7
3 1
4
2
“Inorder-Traversal”
Now let us consider the above expression tree. The preorder, postorder
and inorder traversal are given below:
Preorder : +*/427 – 31
Postorder : 42 / 7 *31 - +
So, given preorder and postorder are silved by given the inorder to both
as follow:-
12
The given preorder’s inorder is :-
And level order is the order where all the nodes of the same level are
travelled first travelled first starting from the root.
Question 3:
1 2
3 4
13
Adj [1] = {2, 3, 5}
such that
1 2 3 4 5
1 0 1 1 0 1
2 1 0 0 1 1
3 1 0 0 1 1
4 0 1 1 0 1
5 1 0 1 1 0
Consider a graph G= (V,E). We wish to find out the shortest path from a
single source vertex vEV, to every vertex vEV.
And we can solve the path (shortest) algorithm which starts with a single
source and finds shortest path to all vertices in the graph. This problem is
helpful in finding distance between all pairs problem is mother of all shortest
paths problems.
14
The weight of an edge (ij in an adjacency array representation as follow
o if i=j
Weight of the undirected edges from i to j i.e. (i,j)
E= i, j If i-j and (i,j) belongs to
In this section we shall use a recursive solution to the pairs (edges) problem
known as Floyd-warshall algorithm, which runs in O(n) time.
This algorithm is based on the following principle for the graph G let V={1, 2,
3, ------n}. Let us consider a sub set of the vertices {1, 2, 3, k). For any pair
opf vertices are from {1, 2, 3, -------k}. This algorithm will exploit the
relationship between path P and shortest path from i to j whose intermediate
vertices are from {1, 2, 3, ------k-1} with the following two possibilities.
For k from 1 to n
Do for i=1 to n
Do for j= 1 to n
Enddo
15
Enddo
Enddo
Programme:-
#include <stdio.h>
#include <conio.h>
Void main ( )
{
All pairs shortest paths (int N, matrix C, matrix P, matrix D)
{
Int i, j, k;
If (i=j then C[i] [j]=0)
{
For (i=0; i<N; i++)
{
For (j=0; j<N; J++)
{
D[i] [j]= C[i] [j];
P[i] [j] = -1;
}
D[i] [j]=0;
}
For (k=0; k<N; k++)
{
For (i=0; i<N; i++)
{
For (j=0; j<N; j++)
{
If (D [i] [k] + D [k] [j] < D [i] [j])
{
D [i] [j] = D[i] [k] +D[k] [j]
P [i] [j] = k;
}
}
16
}
}
}
}
Getch( );
}
17