×

Linked List Data Structure

Linked list in DS: The linked list is a non-primitive and linear data structure. It is a list of a particular type of data element that is connected to each other, as shown in the figure.

Linked List Data Structure

The linked list represents the group of nodes in which each node has two parts. The first part represents the data, and the second part represents the pointer. The pointer part of the linked list holds the address of the next node. A linked list is a data structure whose length can be increased or decreased dynamically (in run-time). The linked list is used to create a tree and graph.

Operations of Linked list

There are following types of operations in the linked list:

  1. Creation operation: It is used to create a new node in the linked list.

Node creation function:

struct node   {      int data;       struct node *next;  };  struct node *head, *ptr;   ptr = (struct node *)malloc(sizeof(struct node *));     
  • Insertion operation: It is used to add a new node to a particular location in a specific situation. A new node can be inserted at the following locations.
  • At the beginning of the linked list
  • At the middle of the linked list
  • At the end of the linked list
  • Deletion operation: It is used to delete a node in a specific situation. A node can be deleted from the following locations.
  • At the beginning of the linked list
  • At the middle of the linked list
  • At the end of the linked list
  • Traversing Operation: This operation is used to print the values ??from a node point to another node point. In other words, traversing operations is a process in which all the nodes of a linked list are checked end-to-end. If traversing from the first node to the last node, it is called forward traversing.

The following code represents the traversing of a node in the linked list:

  void traverse(node   *head){if(head != NULL){traverse (head ->   next);printf(“%d”, head   -> data);}}
  • Display Operation: The display operation is used to print the information of each node. This operation displays the complete list of nodes.
  • Search Operation: The search operation is used to search a particular node in a linked list. A sequential search is most commonly used to search the nodes in a linked list.
  • Concatenation Operation: This operation is used to connect a node to another node in the linked list.

Representation of Linked List in the Memory

The linked list is stored in different locations in the memory. The memory is allocated dynamically for each node. Dynamic means that it is allocated when it is needed. Due to the dynamical allocation, the user can increase and decrease the size of the linked list whenever he wants. An example of a memory representation in a linked list is shown in the figure below.

Linked List Data Structure

Related Topics

Remove duplicates from an unsorted Linked List

Remove duplicates from an unsorted Linked List This article will explain how we can remove duplicates from unsorted linked lists. Here we have given an unsorted singly linked list and will...

3 minutes read.

Binary Tree Uses

A binary tree is a tree data structure containing hubs with at most two children for instance a right and left child. The node at the top is insinuated as the...

3 minutes read.

Assembly Line Scheduling

If we take an example of a car factory, there are two assembly lines. In an assembly line, we can assemble and repair the parts of a car. Now, suppose...

5 minutes read.

A Full Binary Tree with n Nodes

Implementation // Writing the implementation of the above approach in C++ #include <bits/stdc++.h> using namespace std; // We are creating a class that will create a node and its left and right children.  struct __nod...

12 minutes read.

Timsort

TimSort Time Complexity Timsort is a sorting algorithm that is quite efficient for real-world data. Timsort is created in 2001 by Tim Peters for the python programming language. Timsort is a...

3 minutes read.

Symmetric binary tree

Implementation // writing a C++ program to check whether a given binary tree is symmetric or not. #include <bits/stdc++.h> using namespace std; // creating a binary tree node. struct __Nod { int ky; struct __Nod *Lft, *Rt; }; //...

4 minutes read.

Binary search tree traversal in-order pre-order post-order examples

A binary search tree is a type of non-linear tree in which the tree contains at least two nods. It is called binary because of its nature that states bi...

8 minutes read.

Delete a Node without head pointer from the linked list

Delete a Node without head pointer from the linked list This article will explain how to delete a node without a head pointer from the linked list. We have given a...

2 minutes read.

What is B tree?

What do you mean by B Tree in Data Structures? In the technological world, a B tree is simply a well-managed and coordinated tree and an integral part of the data...

6 minutes read.

Stack vs Queue: Data Structure

 Difference Between Stack and Queue What is Stack? The LIFO principle applies on insertion and deletion operations of the stack which means last inserted element to the stack will remove first....

3 minutes read.

Linear vs Circular Queue: Data Structure

Difference Between Linear and Circular Queue What is Linear Queue? A linear queue is linear data structure which works on first in first out principle. We can say a linear queue is...

3 minutes read.

Top view of binary tree

We know that a binary tree is a kind of tree that helps us organize our tree and that it is a kind of non-linear info structure that at least...

4 minutes read.

AVL Tree

AVL Tree AVL Tree is referred to as self-balanced or height-balanced binary search tree where the difference between heights of its left subtree and right subtree (Balance Factor) can't more than...

25 minutes read.

Traversal of binary tree

Traversal of binary tree: A node is visited only once in the traversal of the binary tree. There are three main types of traversal methods in the binary tree. In-order traversalPre-order...

3 minutes read.

What is a full Binary Tree?

A full binary tree is considered to be a special kind of binary tree in which every single node or leaf node present either contains two children or no children...

4 minutes read.

Complete Binary tree

In this article, we will discuss the complete binary tree. But before start discussing the complete binary tree, we should first see a brief description of a binary tree. What is...

7 minutes read.

Inorder Successor in Binary Trees

The next node in the Inorder traversal of a binary tree is known as Inorder successor of that particular node. In a Binary Search Tree, the definition of Inorder successor can...

9 minutes read.

Big O Notations

What is Big O Notation, and why is it important? "Big O notation is a mathematical notation that depicts a function's limiting behaviour when the input tends towards a certain value...

10 minutes read.

Splay Tree

Splay Tree A splay tree is a self-balanced or self-adjusted binary search tree. We can say, Splay Tree is used in some cases where some elements or data are accessed more...

8 minutes read.

Sorting Algorithms in Data Structures

A sorting algorithm is used to organize the elements of an array or list. Sorting an array, for example. Unsorted array 572941 Sorted array 124579 We're sorting the array in ascending order right now. This procedure...

4 minutes read.