Open In App

Introduction to Multi Linked List

A multi-linked list is a special type of list that contains two or more logical key sequences. Before checking details about multi-linked list, see what is a linked list. A linked list is a data structure that is free from any size restriction until the heap memory is not full. We have seen different types of linked lists, such as Singly Linked List, Circular Linked List, and Doubly Linked List. Here we will see about multi-linked list.

In a multi-linked list, each node can have N number of pointers to other nodes. A multi-linked list is generally used to organize multiple orders of one set of elements.



Properties of Multi-Linked List:

The properties of a multi-linked list are mentioned below.



Structure of Multi-linked list:

The structure of a multi-linked list depends on the structure of a node. A single node generally contains two things:

 Shown below is the structure of a node that contains only one data and a list of pointers.




typedef struct node {
    int data;
    vector<struct node*> pointers;
} Node;
 
// This code is contributed by akashish__




typedef struct node {
    int data;
    vector<struct node*> pointers;
} Node;




/*package whatever //do not write package name here */
 
import java.io.*;
 
class GFG {
    public static void main(String[] args) {}
    public static class Node {
        int data;
        Node[] children;
    };
}
 
// This code is contributed by ishankhandelwal




# Python code
class Node:
    def _init_(self):
        self.data = 0
        self.pointers = []
 
        # This code is contributed by ishankhandelwals.




// C# code to create the structure of a node
 
using System;
 
class GFG
{
    public static void Main() { }
    public class Node
    {
        int data;
        Node[] children;
    };
}
 
// This code is contributed by Saurabh jaiswal




// JS code
class node{
 
    constructor(){
        this.data;
        this.pointers=[];
    }
}
 
// This code is contributed by ishankhandelwals.

Use cases of Multi-Linked Lists:

Some use cases of a multi-linked list are:

Multiple orders of one set of elements:

(ANIMESH, 19), (SUMIT, 17), (HARDIK, 22), (ISHA, 18)

Multiple orders of set

Inserting into this structure is very much like inserting the same node into two separate lists. In multi-linked lists it is quite common to have back-pointers, i.e. inverses of each of the forward links; in the above example, this would mean that each node had 4pointers.

Representation of Sparse Matrix:

Multi Linked Lists are used to store sparse matrices. A sparse matrix is such a matrix that has few non-zero values. If we use a normal array to store such a matrix, it will end up wasting lots of space.

Spare Matrix

The sparse matrix can be represented by using a linked list for every row and column. 

Representation of sparse matrix

List of List:

A multi-linked list can be used to represent a list of lists. For example, we can create a linked list where each node is itself a list and have pointers to other nodes. 
See the structure below:

List of List (multi-level linked list)

Advantages of Multi-Linked List:

The advantages of a multi-linked list are:

Comparison of Multi-Linked List with Doubly Linked List:

Let’s first see the structure of a node of Doubly Linked List:




#include <iostream>
using namespace std;
 
typedef struct node {
    int data;
    struct node* prev;
    struct node* next;
} Node;
 
int main() {
 
    return 0;
}
 
// This code is contributed by akashish__




typedef struct node {
    int data;
    struct node* prev;
    struct node* next;
} Node;




/*package whatever //do not write package name here */
 
import java.io.*;
 
class GFG {
    public static void main(String[] args) {}
    public static class Node {
        int data;
        Node prev;
        Node next;
    };
}
 
// This code is contributed by ishankhandelwal




# Python code
class Node:
  def _init_(self, val = 0, next = None):
    self.val = val
    self.next = next
     
# This code is contributed by lokesh.




using System;
 
public class GFG{
 
   static public void Main (){}
   public class Node {
        int data;
        Node prev;
        Node next;
    };
}
 
// This code is contributed by aadityapburujwale




// JS code for above approach
class Node{
    constructor(){
        this.data;
        this.prev=null;
        this.next=null;
    }
}
 
// This code is contributed by ishankhandelwals.

Comparing Doubly linked list and Multi-linked list:


Article Tags :