Linked Lists

  • Here are different operations that are commonly performed on Singly, Doubly, and Circular Linked Lists
  • Code and Step-by-Step diagrams/Notes are provided

Singly Linked Lists:

inserting an Image

A new Class “Node” is required to create the data structure:

class Node:

    def __init__ (self,data):
        self.data = data
        self.next = None

Once we have created a Node Class we can Create a Linked List Class:

class linkedList():

    def __init__(self):
        self.head = None

From here we can add functionality like insertion and deletion of Nodes, the following links on this page show the step-by-step processes of different functionality of a Singly Linked List.

Time Complexity for Singly-Linked List:

Operation Running Time (Average) Running Time (Worst)
Access O (n) O (n)
Search O (n) O (n)
Insertion O (1) O (1)
Deletion O (1) O (1)

Linked Lists Insertion

Linked Lists Deletion

Find the Nth-to-Last Node

Find the Occerences of a Node

Length of Singly Linked List

Rotate Around Pivot

Reverse Linked List

Node Swap Singly Linked Lists

Remove Duplicates of Singly Linked Lists

Move Tail to head

Merge Two Sorted Lists

Coming Soon:

  • Check if Linked list is a Palindrome
  • Sum two Lists

Doubly Linked Lists:

inserting an Image

For a Doubly Linked List we need to adjust the Node Class to include Previous

class Node:

    def __init__(self, data):
        self.data = data 
        self.next = None
        self.prev = None

From here we can add functionality like we did in Single Linked List

Time Complexity for Doubly-Linked List:

Operation Running Time (Average) Running Time (Worst)
Access O (n) O (n)
Search O (n) O (n)
Insertion O (1) O (1)
Deletion O (1) O (1)

Doubly Linked Lists Add Node Before and After

Doubly Linked Lists Append and Prepend

Doubly Linked Lists Delete Node

Coming Soon:

  • Pairs with Sum
  • Remove Duplicates
  • Reverse list

Circular Linked Lists:

inserting an Image

For a Circular Linked List we can use the same Node Class that we used in Single Linked List

Circular Linked Lists Insertion

Circular Linked Lists Remove Node

Circular Linked List Split

Circular Linked List Josephus Problem