REPREENTSTION BY: 1] Manisha . 2] Sanika . 3] Payal . 4] Ashwini

Preview:

DESCRIPTION

REPREENTSTION BY: 1] Manisha . 2] Sanika . 3] Payal . 4] Ashwini . 5] Ankita. CONTENTS: Defination of link list. Types of Link List. Polynomials. Addition of two polynomials. What is sparse matrix? Insertion of an element in sparse matrix. - PowerPoint PPT Presentation

Citation preview

REPREENTSTION BY:

1] Manisha .2] Sanika .3] Payal .4] Ashwini .5] Ankita .

CONTENTS:

Defination of link list. Types of Link List. Polynomials. Addition of two polynomials. What is sparse matrix? Insertion of an element in sparse matrix. Deletion of an element in sparse matrix. Programme Conclusion.

What is link list???

In the previous chap. We have studied the representation of sequential mapping using an array in C .

This representation had a property that successive nodes of the data object were stored a fixed distance apart.

Linked list is a very common data structure often used to store similar data in memory.

This memory is randomly selected by the compiler.

The order of the elements is maintained by explicit links between them.

NODE

DATA LINK

It is a non sequential list-representation.

The above fig. is of a singly link list which also means a chain.

A chain is a singly link list that is comprised of zero or more nodes.when the number of nodes is empty.

The nodes of the non-zero(empty) chain are ordered so that the first link get connected to second and the second to the third and so on…

Types of link lists

Circular linked listSingly linked listDoubly linked list

ADVANTAGES OF LINKED REPRESENTATION OVER SEQUENTIAL REPRESENTATION:

1)In sequential representation the memory is allocated sequentially whereas in linked representation memory is allocated randomly.2)In sequential representation we does not require address of next element where as in linked representation to access list elements in the correct order,with each element we store the address of the next element in that list…Etc.

What are Polynomials?

Representation

Link of other node

3 14 2 8 1 0 0

8 14 -3 10 10 6 0

coefficient

exponents link

Padd( ) : This function adds the node to the resultant list in the descending order of the components of the polynomial.

When padd( ) is called to add the second node we need to compare the exponent value of the new node with that of the first node.

It consist of mainly three conditions:

1) If exponent of 1st polynomial is greater than 2nd polynomial.

2) If exponent of 1st polynomial is smaller than the 2nd .

3) If exponents of 1st polynomial is equal to 2nd polynomial.

Program:

typedef struct polyNode *polypointer;Typedef struct { int coef; int expon; polypointer link; } polyNode;polypointer a,b;

polypointer padd(polypointer a, polypointer b)

{ /* Return a polynomial which is the sum of a & b */

polypointer c, rear, temp;int sum;malloc(rear,sizeof(*rear));c=rear;while(a && b)

switch(COMPARE(a->expon,b->expon)) { case -1: /*a->expon < b->expon */ attach(b->coef, b->expon ,&rear); b= b->link; break; case 0: /*a->expon = b->expon */ sum= a->coef + b->coef; if (sum) attach(sum, a->expon ,&rear); a= a->link; b= b->link; break;

case 1: /*a->expon > b->expon */ attach(a->coef, a->expon ,&rear); a= a->link; break; }/*copy rest of list a and then list b*/for(; a; a= a->link) attach(a->coef, a->expon ,&rear);for(; b; b= b->link) attach(b->coef, b->expon ,&rear);rear->link =NULL;

/*delete extra initial node */temp=c;c= c ->link;free(temp);return c;}

WHAT IS A SPARSE MATRIX?

Sparse matrix is that matrix which has more number of zero’s or can also be said as that matrix which consist of less number of non-zero numbers.

next

down right

down right

row col value

REPRESENTATION OF SPARSE MATRIX

ELEMENT NODE

HEADER NODE

We devised a sequential scheme in which we represented each non-zero term by a node with three fields: row,col,value.

Linked list allows us to efficiently represent

structures that varies in size, a benefit that also applies to sparse matrix. In the above fig the next field links the

header nodes together. Each node has a tag field to distinguish

between header nodes and entry nodes. Each header node has three additional

fields: 1]down 2]right 3]next

Down field is used to link into column list.

Right field is used to link into row list. Next field is used to link header nodes

together. Whereas every entry field has five

fields:1]row 2]col 3]value 4]down 5]right We use the down field to link to the next

non-zero term in the same column the right field to link to the next non-zero term of row.

void mwrite(matrixpointer node) / *print out the matrix in row major form*/ int i; matrixpointer temp,head=node->right; / *matrix dimensions*/ printf(“\ nnumrows=%d,numcols=%d\ n”,node ->u.entry.row, node->u.entry.col); printf(“the matrix by row,column and

value:\ n\ n”); for(i=0; i< node->u.entry.row; i++) / *print out the entries in each row*/

for(temp=head->right ; temp!=head;temp=temp

->right)printf(“%5d%5d%5d\n”,temp-

>u.entry.row u.entry.col ,u.entry.value);

head=head->u.next;/*next row*/}

Erasing a sparse matrixvoid merase (matrixPointer *node){/* erase the matrix, return the nodes to the heap */ matrixPointer x,y, head =(*node)->right;int i ;/*free the entry and header nodes by row */for( i=0; i<(*node) -> u.entry.row; i++){y = head-> right ;while( y!=head) {x = y; y =y->right; free(x);}

x=head ; head=head -> u.next; free(x);}/*free remaining header nodes */y = head;while( y!=*node) {x = y; y =y->u.next ; free(x);}free(*node) ; *node =NULL ;}

LINK LIST AT A GLANCE: Today we have studied the basics

of linked list with the help of node structure. How to add two polynomials using

linked list with it’s representation. How to insert and delete elements

in a sparse matrix with it’s representation.

THANK YOU…!!