Doubly Linked Lists and Its Applications

Doubly linked lists have an extra pointer field called the previous field, that stores the reference to the previous node. It occupies more memory than a singly linked list. It is easier to operate such linked lists. The insertion and deletion operations are similar except for the account of the previous field in the linked list. It is useful browser caches, undo functionality in document processors, etc.

Summary

Doubly linked lists have an extra pointer field called the previous field, that stores the reference to the previous node. It occupies more memory than a singly linked list. It is easier to operate such linked lists. The insertion and deletion operations are similar except for the account of the previous field in the linked list. It is useful browser caches, undo functionality in document processors, etc.

Things to Remember

  1. Doubly linked lists have an extra pointer field called the previous field, that stores the reference to the previous node.
  2.  It occupies more memory than a singly linked list. 
  3. It is easier to operate such linked lists. 
  4.  The insertion and deletion operations are similar except for the account of the previous field in the linked list.
  5.  It is useful browser caches, undo functionality in document processors, etc.

MCQs

No MCQs found.

Subjective Questions

Q1:

1. prove that RM algorithm fails even if the DM algorithm produces a feasible schedule.


Type: Short Difficulty: Easy

Q2:

1. Differentiate between fixed-priority algorithm and dynamic-priority algorithm. 


Type: Short Difficulty: Easy

Q3:

  1. What is rate monotonic algorithm? Explain with suitable example. 

Type: Short Difficulty: Easy

Q4:

  1. Differentiate between clock-driven scheduling and priority-driven scheduling.

Type: Short Difficulty: Easy

Videos

No videos found.

Doubly Linked Lists and Its Applications

Doubly Linked Lists and Its Applications

Doubly Linked List

Doubly linked list (also called two-way linked list) has an advantage from a singly linked list that, given a node in the list, we can navigate in both the directions. A node in a singly linked list cannot be removed unless we have the pointer to its predecessor. But in doubly linked list, we can delete a node even if we don't have previous node address (since, each node has left pointer pointing to previous node and can move backward). The primary disadvantages, however, of doubly linked list are:

  • Each node requires an extra pointer, requring more space
  • The insertion or deletion of a node takes a bit longer due to more pointer operations

Structure Implementation

struct doublyNode{

int data;

struct doublyNode *next;

struct doublyNode *prev;

};

Doubly Linked List Insertion

Insertion before the head

In this case, new node is inserted before the head node. Previous and next pointers need to be modified and it can be done in two steps:

  • Update the right pointer of new node to point to the current head node (dotted link in below figure) and also make left pointer ot new node as NULL
1a

  • Update head node's left pointer to point to the new node and make new node as head.
1b

Insertion at the End

In this case, traverse the list till the end and insert the new node.

  • New node right pointer points to NULL and left pointer points to the end of the list
2a

  • Update right of pointer of last node to point to new node
2b

Insertion at the Middle

As discussed in singly linked lists, traverse the list till the position node and insert the new node.

  • New node right pointer points to the next node of the position node where we want to insert the new node. Also, new node left pointer points to the position node.
3a

  • Position node right pointer points to the new node and the next node of position nodes left pointer points to new node
3b

Doubly Linked List Deletion

Deleting the first node

In this case, first node (current node head) is removed from the list. It can be done in two steps:

  • Create a temporary node which will point to same node as that of the head.
4a

  • Now, move the head node's pointer to the next node and change the head's left pointer to NULL. Then, dispose the temporary node.

4b

Deleting the last node

This operation is a bit trickier, because the algorithm has to find a node, which is previous to the tail. This can be done in three steps.

  • Traverse the list and while traversing maintain the previous node address also. Ny the time we reach the end of list, we will have two pointers, one pointing to the NULL (tail) and other pointing to the node before tail node.
5a

  • Update tail node's previous node's next pointer with NULL

5b

  • Dispose the tail node

5c

Deleting an Intermediate Node

In this case, node to be removed is always located between two nodes. Head and tail links are not updated in this case. Such a removal can be done in two steps:

  • As similar to previous case, maintain previous node also while traversing the list. Once we found the node to be deleted, change the previous node's next pointer to the next node of the node to be deleted.6a

  • Dispose the current node to be deleted.6b

Applications of Doubly Linked List

- A great way to represent a deck of cards in a game.
- The browser cache which allows you to hit the BACK button (a linked list of URLs)
- Applications that have a Most Recently Used (MRU) list (a linked list of file names)
- A stack, hash table, and binary tree can be implemented using a doubly linked list.
- Undo functionality in Photoshop or Word (a linked list of state)

References

1. Karumanchi, N. "Data Structures and Algorithms Made Easy"

2.https://www.quora.com/What-is-real-life-use-of-circular-doubly-linked-lists

3. Y. Langsam, M. J. Augenstein and A. M Tenenbaum, “Data Structures using C and C++”

4. R. L. Kruse, B. P. Leung, C. L. Tondo, “Data Structure and Program design in C”

Lesson

Linked lists

Subject

Computer Engineering

Grade

Engineering

Recent Notes

No recent notes.

Related Notes

No related notes.