Open In App

Generalized Linked List

A Generalized Linked List L, is defined as a finite sequence of n>=0 elements, l1, l2, l3, l4, …, ln, such that li are either item or the list of items. Thus L = (l1, l2, l3, l4, …, ln) where n is total number of nodes in the list.  

To represent a list of items there are certain assumptions about the node structure.



Why Generalized Linked List? Generalized linked lists are used because although the efficiency of polynomial operations using linked list is good but still, the disadvantage is that the linked list is unable to use multiple variable polynomial equation efficiently. It helps us to represent multi-variable polynomial along with the list of elements. 

Typical ‘C’ structure of Generalized Linked List 






typedef struct node {
    char c;                    //Data
    int index;                 //Flag
    struct node *next, *down;   //Next & Down pointer
}GLL;

Example of GLL {List representation} ( a, (b, c), d)  

When first field is 0, it indicates that the second field is variable. If first field is 1 means the second field is a down pointer, means some list is starting. 

Polynomial Representation using Generalized Linked List 

The typical node structure will be:

Example: 9x5 + 7x4y + 10xz In the above example the head node is of variable x. The temp node shows the first field as 2 means coefficient and exponent are present.

  

Since temp node is attached to head node and head node is having variable x, temp node having coefficient = 9 and exponent = 5. The above two nodes can be read as 9x5. Similarly, in the above figure, the node temp1 can be read as x4.

Article Tags :