Categories: Data Structure

Understand Doubly Linked List Data Structure

In a doubly linked list, we define a linked list in which each node keeps an explicit reference to the node before it and a reference to the node after it.

These lists allow a greater variety of O(1)-time update operations, including insertions and deletions.

We continue to use the term “next” for the reference to the node that follows another.

We have a new term “prev” for the reference to the node that precedes it.

Sentinal Node

  • We add special nodes at both ends of the list.
  • a header node at the beginning of the list a trailer node at the end of the list.
  • These “dummy” nodes are known as sentinels (or guards)

Inserting and Deleting

Every insertion into our doubly linked list representation will take place between a pair of existing nodes.

When a new element is inserted at the front of the sequence, we will simply add the new node between the header and the node that is currently after the header.

  • (a) before the operation
  • (b) after creating the new node
  • (c) after linking the neighbors to the new node

Insertion of a Node to Front

  • (a) before the operation
  • (b) after creating the new node
  • (c) after linking the neighbors to the new node

Deletion of a Node

The two neighbors of the node to be deleted are linked directly to each other. As a result, that node will no longer be considered part of the list and it can be reclaimed by the system.

Because of sentinels, the same implementation can be used when deleting the first or the last element of a sequence.

  • (a) before the removal
  • (b) after linking out the old node
  • (c) after the removal

Recommended:

Understand The Singly Linked List and its Operation

Implementation of Singly Linked List in Python

Follow Me ❤😊

If you like my post please follow me to read my latest post on programming and technology.

Instagram

Facebook

Share
Published by
Hassan Raza

Recent Posts

Square Root of Integer

Given an integer A. Compute and return the square root of A. If A is…

9 months ago

Build Array From Permutation

Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…

9 months ago

DSA: Heap

A heap is a specialized tree-based data structure that satisfies the heap property. It is…

11 months ago

DSA: Trie

What is a Trie in DSA? A trie, often known as a prefix tree, is…

11 months ago

Trees: Lowest Common Ancestor

What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…

11 months ago

Binary Search Tree (BST)

A Binary Search Tree (BST) is a type of binary tree that satisfies the following…

11 months ago