Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     




What are the advantages & disadvantages of Doubly linked list over singly linked list.Justify with an example

Doubly linked list offers easy implementation of many operations, whereas singly linked list requires more info for the same operation.. For example, the deletion of a node in a singly linked list. we need the pointer to node previous to it.. But in case of doubly linked list, we just need the pointer(ptr) to the node being deleted as shown below.

ptr->right->left=ptr->left;
ptr->left->right=ptr->right;
free(ptr);

In Disadvantages Doubly linked list occupy more space and often more operations are required for the similar tasks as compared to singly linked lists. a doubly linked list needs more operations while inserting or deleting and it needs more space (to store the extra pointer).

A doubly linked list can be traversed in both directions (forward and backward). A singly linked list can only be traversed in one direction.

A node on a doubly linked list may be deleted with little trouble, since we have pointers to the previous and next nodes. A node on a singly linked list cannot be removed unless we have the pointer to its predecessor.

In single link list, if the list is storing strings, where the strings are lines in a text file (e.g., a text editor). One might store the ``current line'' that the user is on with a pointer to the appropriate node; if the user moves the cursor to the next or previous line, a single pointer operation can restore the current line to its proper value. Or, if the user moves back 10 lines, for example, one can perform 10 pointer operations (follow the chain) to get to the right line.

For more information on doubly link list: click on http://xpode.com/ShowArticle.aspx?Articleid=295

Share this article   |    Print    |    Article read by 8488 times
Author:
mishad sourav
I'm a cse student
Related Articles: No related article
Related Interview Questions: No related interview question