Storing sparse matrix in linked list representation


Question1)a) Consider the function defined below

Int Compute( int X[ ], int n)
{
        If (n==1)
               return X[0];
          else
                return X[n-1] + Compute(X, n-1);
}

If this function is called in the main program by the statement p = Compute(A, 5) ; where A is any array of integers, explain the process of execution. Finally what will be contained in p ?

b) How will you store the following sparse matrix in vector and linked list representation so that only nonzero elements are stored?

2321_Sparse matrix.jpg

c) Write a statement or a set of statements to accomplish each of the following. Assume that all the manipulations occur in main and assume the following definitions

struct TTwenty
{

char Name[15];
Int Total _Runs;
struct TTwenty  *Next;
};
typedef struct TTwenty T20;
typedef T20 *ptr_T20;

i) Create a pointer to the start of the list called start_ptr . The list is empty.

ii) Create a node of type T 20 that is pointed to by pointer new_ptr of type ptr_T20. Assign the string“ Sachin ” to member Name and the value 96 to the member Total_Runs. Provide any  necessary declarations and statements.

iii) Write a while loop that prints the data in each node of the list.1

Question2)a) Write a program that computes the sum of the squares of the digits of an integer.

b) Consider the following declaration
typedef struct node
{ char Course_Grade;
Struct node *Next;
} Student;

For the above declaration, the following function displays the grades of a student in different courses.

Void Display_Grades(Student *S)
{ if (Is_Empty(S))
printf("The Stack is Empty!");
else
{
 printf("Printing the grades of courses..\n");
while(S->Next!=NULL)
{     printf("%c\n",S->Course_Grade);
S = S->Next;
}
printf("%c\n",S->Course_Grade);
}
}

Does it display all the grades? If not, do the necessary modifications so that it displays all the grades. Also write the definition of the function Is_Empty ( ). Also write down the corresponding Push( ) and Pop( ) functions.

c) Manually provide the inorder, preorder and postorder traversals of the following binary search tree

456_Binary search tre.jpg

d) Draw a binary tree for the expression A*B-(C+D)*(P/Q)

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Storing sparse matrix in linked list representation
Reference No:- TGS02593

Now Priced at $100 (50% Discount)

Recommended (91%)

Rated (4.3/5)