repreentstion by: 1] manisha . 2] sanika . 3] payal . 4] ashwini

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

Upload: jemima

Post on 08-Jan-2016

29 views

Category:

Documents


0 download

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

TRANSCRIPT

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

REPREENTSTION BY:

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

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

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.

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

What is link list???

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

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.

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

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.

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

NODE

DATA LINK

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

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…

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

Types of link lists

Circular linked listSingly linked listDoubly linked list

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

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.

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

What are Polynomials?

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

Representation

Link of other node

3 14 2 8 1 0 0

8 14 -3 10 10 6 0

coefficient

exponents link

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

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:

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

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.

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

Program:

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

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

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)

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

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;

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

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;

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

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

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

WHAT IS A SPARSE MATRIX?

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

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.

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

next

down right

down right

row col value

REPRESENTATION OF SPARSE MATRIX

ELEMENT NODE

HEADER NODE

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

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

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

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.

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

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*/

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

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*/}

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

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);}

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

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 ;}

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

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.

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

THANK YOU…!!