Singly Linked List Deletion (Implementation)
This lesson is about deleting an element from the linked list along with its implementation in Java.
We'll cover the following
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 at head merely in constant time.
Let’s take a look at the different types of deletion operations we can perform in singly-linked lists.
Types of Deletion
There are two basic delete operations for linked lists:
- Deletion at head
- Deletion by value
In this lesson, we will look at the implementation of the deletion at the head algorithm.
Deletion at Head
This operation simply deletes a node from the head of the list, which means that it always deletes the first element of the list. This type of deletion is used when your list is ordered, and you want to implement a priority queue–via a linked list-- to keep track of all the elements. Here’s an illustration of how this type of deletion works in a Singly Linked List:
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.