Deletion in a Singly Linked List

After insertion and search, you will be tackling the concept of deletion in a linked list.

Introduction

The deletion operation combines principles from both insertion and search. It uses the search functionality to find the value in the list.

Deletion is one of the instances where linked lists are more efficient than arrays. In an array, you have to shift all the elements backward if one element is deleted. Even then, the end of the array is empty and it takes up unnecessary memory.

In the case of linked lists, the node is removed merely in constant time.

Take a look at the different types of deletion operations you can perform in a singly linked list.

Types of deletion

There are three basic delete operations for the linked list:

  1. Deletion at the head
  2. Deletion by value
  3. Deletion at the tail

In this lesson, you will examine the implementation of the deletion at the head algorithm. Deletion by value and deletion at the tail will be covered in the following lessons.

Delete at the head

This operation deletes the first node from a list. If the list is empty, the function does nothing.

Here is an illustration of how this type of deletion works:

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.