Presentation is loading. Please wait.

Presentation is loading. Please wait.

LINKED LIST Dr. T. Kokilavani Assistant Professor

Similar presentations


Presentation on theme: "LINKED LIST Dr. T. Kokilavani Assistant Professor"— Presentation transcript:

1 LINKED LIST Dr. T. Kokilavani Assistant Professor
Department of Computer Science St. Joseph’s College Trichy Data Structures and Algorithms, Dr.T.Kokilavani, SJC

2 Linked List In arrays, block of memory that is required for the array should be allocated before use. Once memory is located it cannot be extended any more. So array is called static data structure. Linked list is called dynamic data structure, because amount of memory required can be varied during its use. In linked list, adjacency between the elements are maintained by means of links or pointers. A link or pointer is the address (memory location) of the subsequent element. An element in a linked list is called node. A node consists of two fields: DATA (to store the actual information) and LINK (to point to the next node). Data Structures and Algorithms, Dr.T.Kokilavani, SJC

3 Definition A linked list is an ordered collection of finite, homogenous data elements called nodes where the linear order is maintained by means of links or pointers. Linked list can be classified into three major groups: single linked list circular linked list double linked list Data Structures and Algorithms, Dr.T.Kokilavani, SJC

4 Single Linked List In a single linked list each node contains only one link which points the subsequent node in the list. This figure shows a linked list with 6 nodes. N1, N2, …., N6 are the constituent nodes in the list. Header is an empty node (data content NULL) and only used to store a pointer to the first node N1. Starting from the first node one can reach to the last node whose link field does not contain any address rather than a null value. In a single linked list one can move from left to right only, that is why it is called one way list. Data Structures and Algorithms, Dr.T.Kokilavani, SJC

5 Representation of a linked list in memory
There are two ways to represent a linked list in memory: Static representation using array Dynamic representation using free pool of storage Static representation of a single linked list maintains two arrays: One array for data and other for links. Data Structures and Algorithms, Dr.T.Kokilavani, SJC

6 Dynamic representation
In this method, there is a memory bank (nothing but a collection of free spaces) and a memory manager ( a program). During the creation of linked list, whenever a node is required the request is placed to the memory manager which will then search the memory bank for the block requested and if found grants a desired block to the caller. Another program called garbage collector returns the unused node to the memory bank, whenever a node is no more in use. This is called dynamic memory management. Dynamic representation of linked list uses the dynamic memory management policy Data Structures and Algorithms, Dr.T.Kokilavani, SJC

7 Dynamic representation
A list of available memory space’s pointer is stored in AVAIL. If there is a request for node, the AVAIL is searched for the block of right size. If AVAIL is null or the block of desired size is not found memory manager will return a message accordingly. If the block is found then let it be XY. Then memory manager will return the pointer of XY to a temporary buffer, NEW. The new node XY then can be inserted at any position in the linked list by changing the pointers of the concerned nodes. Data Structures and Algorithms, Dr.T.Kokilavani, SJC

8 This figure shows how a node is to be returned to the memory bank.
The node XY is inserted at the end and change of pointers are shown by the dotted arrows. This figure shows how a node is to be returned to the memory bank. Data Structures and Algorithms, Dr.T.Kokilavani, SJC


Download ppt "LINKED LIST Dr. T. Kokilavani Assistant Professor"

Similar presentations


Ads by Google