A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations. The elements in a linked list are linked using pointers. In simple words, a linked list consists of nodes where each node contains a data field and a reference(link) to the next node in the list.
Types Of Linked Lists:
1. Singly Linked List
Singly linked list is the simplest type of linked list in which every node contains some data and a pointer to the next node of the same data type.
The node contains a pointer to the next node means that the node stores the address of the next node in the sequence. A single linked list allows the traversal of data only in one way. Below is the image for the same:
Below is the structure of the singly linked list:
C++
// Definition of a Node in a singly linked list
struct Node {
// Data part of the node
int data;
// Pointer to the next node in the list
Node* next;
// Constructor to initialize the node with data
Node(int data) {
this->data = data;
this->next = nullptr;
}
};
C
#include <stdio.h>
#include <stdlib.h>
struct Node {
// Data part of the node
int data;
// Pointer to the next node in the list
struct Node* next;
};
// Function to create a new node with given data
struct Node* newNode(int data) {
struct Node* node =
(struct Node*)malloc(sizeof(struct Node));
node->data = data;
node->next = NULL;
return node;
}
Java
// Definition of a Node in a singly linked list
public class Node {
int data;
Node next;
// Constructor to initialize the node with data
public Node(int data) {
this.data = data;
this.next = null;
}
}
Python
# Definition of a Node in a singly linked list
class Node:
def __init__(self, data):
self.data = data
self.next = None
C#
// Definition of a Node in a singly linked list
public class Node {
int data;
Node next;
// Constructor to initialize the node with data
public Node(int data) {
this.data = data;
this.next = null;
}
}
JavaScript
// Definition of a Node in a singly linked list
class Node {
constructor(data) {
this.data = data;
this.next = null;
}
}
Below is the creation and traversal of Singly Linked List:
C++
// C++ program to illustrate creation
// and traversal of Singly Linked List
#include <bits/stdc++.h>
using namespace std;
class Node {
public:
int data;
Node* next;
Node(int data) {
this->data = data;
this->next = nullptr;
}
};
void printList(Node* curr) {
// Iterate till n reaches NULL
while ( curr != nullptr) {
cout << curr->data << " ";
curr = curr->next;
}
}
int main() {
//Linked List 1 -> 2 -> 3
Node* head = new Node(1);
Node* second = new Node(2);
Node* third = new Node(3);
head->next = second;
second->next = third;
printList(head);
return 0;
}
C
// C program to illustrate creation
// and traversal of Singly Linked List
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
struct Node* createNode(int data) {
struct Node* node =
(struct Node*)malloc(sizeof(struct Node));
node->data = data;
node->next = NULL;
return node;
}
void printList(struct Node* n) {
// Iterate till n reaches NULL
while (n != NULL) {
printf("%d ", n->data);
n = n->next;
}
}
int main() {
struct Node* head = NULL;
struct Node* second = NULL;
struct Node* third = NULL;
//Linked List 1 -> 2 -> 3
head = createNode(1);
second = createNode(2);
third = createNode(3);
head->next = second;
second->next = third;
printList(head);
return 0;
}
Java
// Java program to illustrate creation
// and traversal of Singly Linked List
class Node {
int data;
Node next;
public Node(int data) {
this.data = data;
this.next = null;
}
}
public class GfG {
public static void printList(Node n) {
// Iterate till n reaches null
while (n != null) {
// Print the data
System.out.print(n.data + " ");
n = n.next;
}
}
public static void main(String[] args) {
//Linked List 1 -> 2 -> 3
Node head = new Node(1);
Node second = new Node(2);
Node third = new Node(3);
head.next = second;
second.next = third;
printList(head);
}
}
Python
# Python program to illustrate creation
# and traversal of Singly Linked List
class Node:
def __init__(self, data):
self.data = data
self.next = None
def print_list(node):
# Iterate till node reaches None
while node is not None:
# Print the data
print(node.data, end=" ")
node = node.next
if __name__ == "__main__":
#Linked List 1 -> 2 -> 3
head = Node(1)
second = Node(2)
third = Node(3)
head.next = second
second.next = third
print_list(head)
C#
// C# program to illustrate creation
// and traversal of Singly Linked List
using System;
class Node {
public int data;
public Node next;
public Node(int data) {
this.data = data;
this.next = null;
}
}
class GfG {
static void PrintList(Node node) {
// Iterate till node reaches null
while (node != null) {
Console.Write(node.data + " ");
node = node.next;
}
}
static void Main() {
//Linked List 1 -> 2 -> 3
Node head = new Node(1);
Node second = new Node(2);
Node third = new Node(3);
head.next = second;
second.next = third;
PrintList(head);
}
}
JavaScript
// Javascript program to illustrate creation
// and traversal of Singly Linked List
class Node {
constructor(data) {
this.data = data;
this.next = null;
}
}
function printList(n) {
// Iterate till n reaches null
while (n != null) {
// Print the data
console.log(n.data);
n = n.next;
}
}
//Linked List 1 -> 2 -> 3
let head = new Node(1);
let second = new Node(2);
let third = new Node(3);
head.next = second;
second.next = third;
printList(head);
Time Complexity: O(n), where n is the number of nodes.
Auxiliary Space: O(1)
2. Doubly Linked List
A doubly linked list or a two-way linked list is a more complex type of linked list that contains a pointer to the next as well as the previous node in sequence.
Therefore, it contains three parts of data, a pointer to the next node, and a pointer to the previous node. This would enable us to traverse the list in the backward direction as well.
Below is the structure of the doubly linked list :
C++
// Define the Node structure
struct Node {
int data;
Node* next;
Node* prev;
Node(int x) {
data = x;
next = nullptr;
prev = nullptr;
}
};
C
// Define the Node structure
struct Node {
int data;
struct Node* next;
struct Node* prev;
};
struct Node* createNode(int data) {
struct Node* newNode =
(struct Node*)malloc(sizeof(struct Node));
newNode->data = data;
newNode->next = NULL;
newNode->prev = NULL;
return newNode;
}
Java
// Define the Node class
class Node {
int data;
Node next;
Node prev;
public Node(int data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
Python
# Define the Node class
class Node:
def __init__(self, data):
self.data = data
self.prev = None
self.next = None
C#
// Define the Node class
class Node {
public int Data;
public Node Next;
public Node Prev;
public Node(int data) {
Data = data;
Next = null;
Prev = null;
}
}
JavaScript
// Define the Node class
class Node {
constructor(data) {
this.data = data;
this.prev = null;
this.next = null;
}
}
Below is the creation and traversal of doubly linked list:
C++
// C++ program to illustrate creation
// and traversal of doubly Linked List
#include <iostream>
using namespace std;
struct Node {
int data;
Node* next;
Node* prev;
Node(int x) {
data = x;
next = nullptr;
prev = nullptr;
}
};
void forwardTraversal(Node* head) {
Node* curr = head;
while (curr != nullptr) {
cout << curr->data << " ";
curr = curr->next;
}
cout << endl;
}
void backwardTraversal(Node* tail) {
Node* curr = tail;
while (curr != nullptr) {
cout << curr->data << " ";
curr = curr->prev;
}
cout << endl;
}
int main() {
//Linked List 1 <-> 2 <-> 3
Node* head = new Node(1);
Node* second = new Node(2);
Node* third = new Node(3);
head->next = second;
second->prev = head;
second->next = third;
third->prev = second;
cout << "Forward Traversal:" << endl;
forwardTraversal(head);
cout << "Backward Traversal:" << endl;
backwardTraversal(third);
return 0;
}
C
// C program to illustrate creation
// and traversal of doubly Linked List
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
struct Node* prev;
};
void forwardTraversal(struct Node* head) {
struct Node* curr = head;
while (curr != NULL) {
printf("%d ", curr->data);
curr = curr->next;
}
printf("\n");
}
void backwardTraversal(struct Node* tail) {
struct Node* curr = tail;
while (curr != NULL) {
printf("%d ", curr->data);
curr = curr->prev;
}
printf("\n");
}
struct Node* createNode(int data) {
struct Node* newNode =
(struct Node*)malloc(sizeof(struct Node));
newNode->data = data;
newNode->next = NULL;
newNode->prev = NULL;
return newNode;
}
int main() {
//Linked List 1 <-> 2 <-> 3
struct Node* head = createNode(1);
struct Node* second = createNode(2);
struct Node* third = createNode(3);
head->next = second;
second->prev = head;
second->next = third;
third->prev = second;
printf("Forward Traversal:\n");
forwardTraversal(head);
printf("Backward Traversal:\n");
backwardTraversal(third);
return 0;
}
Java
// Java program to illustrate creation
// and traversal of doubly Linked List
class Node {
int data;
Node next;
Node prev;
public Node(int data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
class GfG {
static void forwardTraversal(Node head) {
Node curr = head;
while (curr != null) {
System.out.print(curr.data + " ");
curr = curr.next;
}
System.out.println();
}
static void backwardTraversal(Node tail) {
Node curr = tail;
while (curr != null) {
System.out.print(curr.data + " ");
curr = curr.prev;
}
System.out.println();
}
public static void main(String[] args) {
//Linked List 1 <-> 2 <-> 3
Node head = new Node(1);
Node second = new Node(2);
Node third = new Node(3);
head.next = second;
second.prev = head;
second.next = third;
third.prev = second;
System.out.println("Forward Traversal:");
forwardTraversal(head);
System.out.println("Backward Traversal:");
backwardTraversal(third);
}
}
Python
# Python program to illustrate creation
# and traversal of doubly Linked List
class Node:
def __init__(self, data):
self.data = data
self.prev = None
self.next = None
def forward_traversal(head):
curr = head
while curr is not None:
print(curr.data, end=" ")
curr = curr.next
print()
def backward_traversal(tail):
curr = tail
while curr is not None:
print(curr.data, end=" ")
curr = curr.prev
print()
if __name__ == "__main__":
#Linked List 1 <-> 2 <-> 3
head = Node(1)
second = Node(2)
third = Node(3)
head.next = second
second.prev = head
second.next = third
third.prev = second
print("Forward Traversal:")
forward_traversal(head)
print("Backward Traversal:")
backward_traversal(third)
C#
// C# program to illustrate creation
// and traversal of doubly Linked List
using System;
class Node {
public int Data;
public Node next;
public Node prev;
public Node(int data) {
Data = data;
next = null;
prev = null;
}
}
class GfG {
static void ForwardTraversal(Node head) {
Node curr = head;
while (curr != null) {
Console.Write(curr.Data + " ");
curr = curr.next;
}
Console.WriteLine();
}
static void BackwardTraversal(Node tail) {
Node curr = tail;
while (curr != null) {
Console.Write(curr.Data + " ");
curr = curr.prev;
}
Console.WriteLine();
}
static void Main() {
//Linked List 1 <-> 2 <-> 3
Node head = new Node(1);
Node second = new Node(2);
Node third = new Node(3);
head.next = second;
second.prev = head;
second.next = third;
third.prev = second;
Console.WriteLine("Forward Traversal:");
ForwardTraversal(head);
Console.WriteLine("Backward Traversal:");
BackwardTraversal(third);
}
}
JavaScript
// Javascript program to illustrate creation
// and traversal of doubly Linked List
class Node {
constructor(data) {
this.data = data;
this.prev = null;
this.next = null;
}
}
function forwardTraversal(head) {
let curr = head;
while (curr !== null) {
console.log(curr.data + " ");
curr = curr.next;
}
console.log();
}
function backwardTraversal(tail) {
let curr = tail;
while (curr !== null) {
console.log(curr.data + " ");
curr = curr.prev;
}
console.log();
}
//Linked List 1 <-> 2 <-> 3
const head = new Node(1);
const second = new Node(2);
const third = new Node(3);
head.next = second;
second.prev = head;
second.next = third;
third.prev = second;
console.log("Forward Traversal:");
forwardTraversal(head);
console.log("Backward Traversal:");
backwardTraversal(third);
OutputForward Traversal:
1 2 3
Backward Traversal:
3 2 1
Time Complexity: O(n), where n is the number of nodes.
Auxiliary Space: O(1)
3. Circular Linked List
A circular linked list is a type of linked list in which the last node's next pointer points back to the first node of the list, creating a circular structure. This design allows for continuous traversal of the list, as there is no null to end the list.
While traversing a circular linked list, we can begin at any node and traverse the list in any direction forward and backward until we reach the same node we started. Thus, a circular linked list has no beginning and no end. Below is the image for the same:
Below is the structure of the circular linked list :
C++
// Define the Node structure
struct Node {
int data;
Node* next;
Node(int value) {
data = value;
next = nullptr;
}
};
C
// Define the Node structure
struct Node {
int data;
struct Node *next;
};
struct Node *createNode(int value) {
struct Node *newNode =
(struct Node *)malloc(sizeof(struct Node));
newNode->data = value;
newNode->next = NULL;
return newNode;
}
Java
// Define the Node structure
class Node {
int data;
Node next;
Node(int value){
data = value;
next = null;
}
}
Python
# Define the Node structure
class Node:
def __init__(self, data):
self.data = data
self.next = None
C#
// Define the Node structure
class Node {
public int data;
public Node next;
public Node(int value) {
data = value;
next = null;
}
}
JavaScript
// Define the Node structure
class Node {
constructor(data) {
this.data = data;
this.next = null;
}
}
Below is the creation and traversal of circular linked list:
C++
// C++ program to illustrate creation
// and traversal of Circular Linked List
#include <iostream>
using namespace std;
struct Node {
int data;
Node* next;
Node(int value) {
data = value;
next = nullptr;
}
};
void printList(Node* last){
if(last == NULL) return;
// Start from the head node
Node* head = last->next;
while (true) {
cout << head->data << " ";
head = head->next;
if (head == last->next)
break;
}
cout << endl;
}
int main(){
// Create circular linked list: 2, 3, 4
Node* first = new Node(2);
first->next = new Node(3);
first->next->next = new Node(4);
Node* last = first->next->next;
last->next = first;
printList(last);
return 0;
}
C
// C program to illustrate creation
// and traversal of Circular Linked List
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node *next;
};
void printList(struct Node *last) {
if (last == NULL) return;
struct Node *head = last->next;
while (1){
printf("%d ", head->data);
head = head->next;
if (head == last->next)
break;
}
printf("\n");
}
struct Node *createNode(int value) {
struct Node *newNode =
(struct Node *)malloc(sizeof(struct Node));
newNode->data = value;
newNode->next = NULL;
return newNode;
}
int main() {
// Create circular linked list: 2, 3, 4
struct Node *first = createNode(2);
first->next = createNode(3);
first->next->next = createNode(4);
struct Node *last = first->next->next;
last->next = first;
printList(last);
return 0;
}
Java
// Java program to illustrate creation
// and traversal of Circular Linked List
class Node {
int data;
Node next;
Node(int value){
data = value;
next = null;
}
}
class GFG {
static void printList(Node last){
if (last == null)
return;
Node head = last.next;
while (true) {
System.out.print(head.data + " ");
head = head.next;
if (head == last.next) break;
}
System.out.println();
}
public static void main(String[] args){
// Create circular linked list: 2, 3, 4
Node first = new Node(2);
first.next = new Node(3);
first.next.next = new Node(4);
Node last = first.next.next;
last.next = first;
printList(last);
}
}
Python
# Python program to illustrate creation
# and traversal of Circular Linked List
class Node:
def __init__(self, data):
self.data = data
self.next = None
def print_list(last):
if last is None:
return
head = last.next
while True:
print(head.data, end=" ")
head = head.next
if head == last.next:
break
print()
# Create circular linked list: 2, 3, 4
first = Node(2)
first.next = Node(3)
first.next.next = Node(4)
last = first.next.next
last.next = first
print_list(last)
C#
// C# program to illustrate creation
// and traversal of Circular Linked List
using System;
class Node {
public int data;
public Node next;
public Node(int value) {
data = value;
next = null;
}
}
class GfG {
static void PrintList(Node last) {
if (last == null)
return;
Node head = last.next;
while (true) {
Console.Write(head.data + " ");
head = head.next;
if (head == last.next)
break;
}
Console.WriteLine();
}
static void Main(string[] args) {
// Create circular linked list: 2, 3, 4
Node first = new Node(2);
first.next = new Node(3);
first.next.next = new Node(4);
Node last = first.next.next;
last.next = first;
PrintList(last);
}
}
JavaScript
// Javascript program to illustrate creation
// and traversal of Circular Linked List
class Node {
constructor(data) {
this.data = data;
this.next = null;
}
}
function printList(last) {
if (last === null)
return;
let head = last.next;
while (true) {
console.log(head.data + " ");
head = head.next;
if (head === last.next)
break;
}
console.log();
}
// Create circular linked list: 2, 3, 4
const first = new Node(2);
first.next = new Node(3);
first.next.next = new Node(4);
let last = first.next.next;
last.next = first;
printList(last);
Time Complexity: O(n), where n is the number of nodes.
Auxiliary Space: O(1)
4. Doubly Circular linked list
Doubly Circular linked list or a circular two-way linked list is a complex type of linked list that contains a pointer to the next as well as the previous node in the sequence. The difference between the doubly linked and circular doubly list is the same as that between a singly linked list and a circular linked list. The circular doubly linked list does not contain null in the previous field of the first node.
Below is the structure of the Doubly Circular Linked List:
C++
// Structure of a Node
struct Node {
int data;
struct Node* next;
struct Node* prev;
};
Java
// Node class for Circular Doubly Linked List
class Node {
int data;
Node next;
Node prev;
Node(int data) {
this.data = data;
this.next = this;
this.prev = this;
}
}
Python
# structure of Node
class Node:
def __init__(self, data):
self.previous = None
self.data = data
self.next = None
C#
// Define the Node class
class Node {
public int Data;
public Node Next;
public Node Prev;
public Node(int data) {
Data = data;
Next = null;
Prev = null;
}
}
JavaScript
// Structure of a Node
class Node {
constructor(data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
Below is the creation and traversal of doubly circular linked list:
C++
// C++ program to illustrate creation
// and traversal of doubly circular Linked List
#include <iostream>
using namespace std;
struct Node {
int data;
Node* next;
Node* prev;
Node(int x) {
data = x;
next = nullptr;
prev = nullptr;
}
};
void forwardTraversal(Node* head) {
Node* curr = head;
do {
cout << curr->data << " ";
curr = curr->next;
} while (curr != head);
cout << endl;
}
void backwardTraversal(Node* head) {
Node* curr = head->prev;
do {
cout << curr->data << " ";
curr = curr->prev;
} while (curr->next != head);
cout << endl;
}
int main() {
// Create a doubly circular linked list
// 1 <-> 2 <-> 3 <-> 1
Node* head = new Node(1);
Node* second = new Node(2);
Node* third = new Node(3);
head->next = second;
second->prev = head;
second->next = third;
third->prev = second;
third->next = head;
head->prev = third;
cout << "Forward Traversal:" << endl;
forwardTraversal(head);
cout << "Backward Traversal:" << endl;
backwardTraversal(head);
return 0;
}
C
// C program to illustrate creation
// and traversal of doubly circular Linked List
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
struct Node* prev;
};
void forwardTraversal(struct Node* head) {
struct Node* curr = head;
if (head != NULL) {
do {
printf("%d ", curr->data);
curr = curr->next;
} while (curr != head);
}
printf("\n");
}
void backwardTraversal(struct Node* head) {
struct Node* curr = head->prev;
if (head != NULL) {
do {
printf("%d ", curr->data);
curr = curr->prev;
} while (curr->next != head);
}
printf("\n");
}
struct Node* createNode(int data) {
struct Node* newNode =
(struct Node*)malloc(sizeof(struct Node));
newNode->data = data;
newNode->next = NULL;
newNode->prev = NULL;
return newNode;
}
int main() {
// Create a doubly circular linked list
// 1 <-> 2 <-> 3 <-> 1
struct Node* head = createNode(1);
struct Node* second = createNode(2);
struct Node* third = createNode(3);
head->next = second;
second->prev = head;
second->next = third;
third->prev = second;
// Make it circular
third->next = head;
head->prev = third;
printf("Forward Traversal:\n");
forwardTraversal(head);
printf("Backward Traversal:\n");
backwardTraversal(head);
return 0;
}
Java
// Java program to illustrate creation
// and traversal of doubly circular Linked List
class Node {
int data;
Node next;
Node prev;
public Node(int data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
class GfG {
static void forwardTraversal(Node head) {
Node curr = head;
if (head != null) {
do {
System.out.print(curr.data + " ");
curr = curr.next;
} while (curr != head);
}
System.out.println();
}
static void backwardTraversal(Node head) {
Node curr = head.prev;
if (head != null) {
do {
System.out.print(curr.data + " ");
curr = curr.prev;
} while (curr.next != head);
}
System.out.println();
}
public static void main(String[] args) {
// Create a doubly circular linked list
// 1 <-> 2 <-> 3 <-> 1
Node head = new Node(1);
Node second = new Node(2);
Node third = new Node(3);
head.next = second;
second.prev = head;
second.next = third;
third.prev = second;
third.next = head;
head.prev = third;
System.out.println("Forward Traversal:");
forwardTraversal(head);
System.out.println("Backward Traversal:");
backwardTraversal(head);
}
}
Python
# Python program to illustrate creation
# and traversal of doubly circular Linked List
class Node:
def __init__(self, data):
self.data = data
self.prev = None
self.next = None
def forward_traversal(head):
curr = head
if head is not None:
while True:
print(curr.data, end=" ")
curr = curr.next
if curr == head:
break
print()
def backward_traversal(head):
curr = head.prev
if head is not None:
while True:
print(curr.data, end=" ")
curr = curr.prev
if curr.next == head:
break
print()
if __name__ == "__main__":
# Create a doubly circular linked list
# 1 <-> 2 <-> 3 <-> 1
head = Node(1)
second = Node(2)
third = Node(3)
head.next = second
second.prev = head
second.next = third
third.prev = second
third.next = head
head.prev = third
print("Forward Traversal:")
forward_traversal(head)
print("Backward Traversal:")
backward_traversal(head)
C#
// C# program to illustrate creation
// and traversal of doubly circular Linked List
using System;
class Node {
public int Data;
public Node next;
public Node prev;
public Node(int data) {
Data = data;
next = null;
prev = null;
}
}
class GfG {
static void ForwardTraversal(Node head) {
if (head == null) return;
Node curr = head;
do {
Console.Write(curr.Data + " ");
curr = curr.next;
} while (curr != head);
Console.WriteLine();
}
static void BackwardTraversal(Node head) {
if (head == null) return;
Node curr = head.prev;
do {
Console.Write(curr.Data + " ");
curr = curr.prev;
} while (curr.next != head);
Console.WriteLine();
}
static void Main() {
// Create a doubly circular linked list
// 1 <-> 2 <-> 3 <-> 1
Node head = new Node(1);
Node second = new Node(2);
Node third = new Node(3);
head.next = second;
second.prev = head;
second.next = third;
third.prev = second;
third.next = head;
head.prev = third;
Console.WriteLine("Forward Traversal:");
ForwardTraversal(head);
Console.WriteLine("Backward Traversal:");
BackwardTraversal(head);
}
}
JavaScript
// Javascript program to illustrate creation
// and traversal of doubly circular Linked List
class Node {
constructor(data) {
this.data = data;
this.prev = null;
this.next = null;
}
}
function forwardTraversal(head) {
if (head === null) return;
let curr = head;
do {
console.log(curr.data + " ");
curr = curr.next;
} while (curr !== head);
console.log();
}
function backwardTraversal(head) {
if (head === null) return;
let curr = head.prev;
do {
console.log(curr.data + " ");
curr = curr.prev;
} while (curr.next !== head);
console.log();
}
// Create a doubly circular linked list
// 1 <-> 2 <-> 3 <-> 1
const head = new Node(1);
const second = new Node(2);
const third = new Node(3);
head.next = second;
second.prev = head;
second.next = third;
third.prev = second;
third.next = head;
head.prev = third;
console.log("Forward Traversal:");
forwardTraversal(head);
console.log("Backward Traversal:");
backwardTraversal(head);
OutputForward Traversal:
1 2 3
Backward Traversal:
3 2 1
Time Complexity: O(n), where n is the number of Nodes.
Auxiliary space: O(1)
5. Multilevel Linked List :
A multilevel linked list is an advanced data structure designed to represent hierarchical relationships among elements. Each node in this structure contains three main components: data, a next pointer, and a child pointer. The next pointer links to the next node in the same level of the list, allowing for linear traversal within that level. The child pointer, on the other hand, points to a sub-list or nested linked list, creating a hierarchical or tree-like structure. This enables each node to have its own sub-list of nodes, allowing for complex nested relationships. Please refer to Multi Linked List for Implementation.
6. Skip-List :
A skip list is a data structure that allows for efficient search, insertion and deletion of elements in a sorted list. It is a probabilistic data structure, meaning that its average time complexity is determined through a probabilistic analysis. Skip lists are implemented using a technique called “coin flipping.” In this technique, a random number is generated for each insertion to determine the number of layers the new element will occupy. This means that, on average, each element will be in log(n) layers, where n is the number of elements in the bottom layer. Please refer to Introduction of Skip List.
Note: Header Linked Lists are not a distinct type of linked list but rather a technique used within existing linked list structures, such as singly or doubly linked lists. This technique involves using a dummy node, also known as a header node, to simplify operations like insertion, deletion, and traversal. Please refer to Header Linked Lists for implementation.
Similar Reads
Basics & Prerequisites
Data Structures
Array Data StructureIn this article, we introduce array, implementation in different popular languages, its basic operations and commonly seen problems / interview questions. An array stores items (in case of C/C++ and Java Primitive Arrays) or their references (in case of Python, JS, Java Non-Primitive) at contiguous
3 min read
String in Data StructureA string is a sequence of characters. The following facts make string an interesting data structure.Small set of elements. Unlike normal array, strings typically have smaller set of items. For example, lowercase English alphabet has only 26 characters. ASCII has only 256 characters.Strings are immut
2 min read
Hashing in Data StructureHashing is a technique used in data structures that efficiently stores and retrieves data in a way that allows for quick access. Hashing involves mapping data to a specific index in a hash table (an array of items) using a hash function. It enables fast retrieval of information based on its key. The
2 min read
Linked List Data StructureA linked list is a fundamental data structure in computer science. It mainly allows efficient insertion and deletion operations compared to arrays. Like arrays, it is also used to implement other data structures like stack, queue and deque. Hereâs the comparison of Linked List vs Arrays Linked List:
2 min read
Stack Data StructureA Stack is a linear data structure that follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out). LIFO implies that the element that is inserted last, comes out first and FILO implies that the element that is inserted first
2 min read
Queue Data StructureA Queue Data Structure is a fundamental concept in computer science used for storing and managing data in a specific order. It follows the principle of "First in, First out" (FIFO), where the first element added to the queue is the first one to be removed. It is used as a buffer in computer systems
2 min read
Tree Data StructureTree Data Structure is a non-linear data structure in which a collection of elements known as nodes are connected to each other via edges such that there exists exactly one path between any two nodes. Types of TreeBinary Tree : Every node has at most two childrenTernary Tree : Every node has at most
4 min read
Graph Data StructureGraph Data Structure is a collection of nodes connected by edges. It's used to represent relationships between different entities. If you are looking for topic-wise list of problems on different topics like DFS, BFS, Topological Sort, Shortest Path, etc., please refer to Graph Algorithms. Basics of
3 min read
Trie Data StructureThe Trie data structure is a tree-like structure used for storing a dynamic set of strings. It allows for efficient retrieval and storage of keys, making it highly effective in handling large datasets. Trie supports operations such as insertion, search, deletion of keys, and prefix searches. In this
15+ min read
Algorithms
Searching AlgorithmsSearching algorithms are essential tools in computer science used to locate specific items within a collection of data. In this tutorial, we are mainly going to focus upon searching in an array. When we search an item in an array, there are two most common algorithms used based on the type of input
2 min read
Sorting AlgorithmsA Sorting Algorithm is used to rearrange a given array or list of elements in an order. For example, a given array [10, 20, 5, 2] becomes [2, 5, 10, 20] after sorting in increasing order and becomes [20, 10, 5, 2] after sorting in decreasing order. There exist different sorting algorithms for differ
3 min read
Introduction to RecursionThe process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called a recursive function. A recursive algorithm takes one step toward solution and then recursively call itself to further move. The algorithm stops once we reach the solution
14 min read
Greedy AlgorithmsGreedy algorithms are a class of algorithms that make locally optimal choices at each step with the hope of finding a global optimum solution. At every step of the algorithm, we make a choice that looks the best at the moment. To make the choice, we sometimes sort the array so that we can always get
3 min read
Graph AlgorithmsGraph is a non-linear data structure like tree data structure. The limitation of tree is, it can only represent hierarchical data. For situations where nodes or vertices are randomly connected with each other other, we use Graph. Example situations where we use graph data structure are, a social net
3 min read
Dynamic Programming or DPDynamic Programming is an algorithmic technique with the following properties.It is mainly an optimization over plain recursion. Wherever we see a recursive solution that has repeated calls for the same inputs, we can optimize it using Dynamic Programming. The idea is to simply store the results of
3 min read
Bitwise AlgorithmsBitwise algorithms in Data Structures and Algorithms (DSA) involve manipulating individual bits of binary representations of numbers to perform operations efficiently. These algorithms utilize bitwise operators like AND, OR, XOR, NOT, Left Shift, and Right Shift.BasicsIntroduction to Bitwise Algorit
4 min read
Advanced
Segment TreeSegment Tree is a data structure that allows efficient querying and updating of intervals or segments of an array. It is particularly useful for problems involving range queries, such as finding the sum, minimum, maximum, or any other operation over a specific range of elements in an array. The tree
3 min read
Pattern SearchingPattern searching algorithms are essential tools in computer science and data processing. These algorithms are designed to efficiently find a particular pattern within a larger set of data. Patten SearchingImportant Pattern Searching Algorithms:Naive String Matching : A Simple Algorithm that works i
2 min read
GeometryGeometry is a branch of mathematics that studies the properties, measurements, and relationships of points, lines, angles, surfaces, and solids. From basic lines and angles to complex structures, it helps us understand the world around us.Geometry for Students and BeginnersThis section covers key br
2 min read
Interview Preparation
Practice Problem