Linked List Introduction and it's Implementation - The Coding Shala
Home >> Data Structures >> Linked List Introduction and its Implementation
In this post, we will learn what is linked list data structure and will implement a singly linked list in Java.
Linked List Data Structure
A linked list is a linear data structure. The linked list is a chain of Nodes that are connected using pointers. One Node contains the data/element and a pointer called next that points to the next node. Unlike arrays, linked list elements are not stored in a contiguous location. There are different types of the linked lists like a singly linked list, doubly linked list, and circular linked list. Here we will cover a singly linked list.
The following are main terms used in a linked list:
- head: front node of a linked list
- next: pointer to the next node
- node: contains data/value and the next pointer
We can create a linked list of different data types like integer, string, etc.
Advantages and Disadvantages of linked lists
The following are some advantages and disadvantages of the linked list:
- The size of linked lists is not fixed. We can add or remove nodes as per our requirements.
- Addition and deletion are easy in the linked list. We can do it in O(1) time.
- Like arrays, random access is not possible in the linked list. We need to traverse the linked list to reach the node.
Implementation of singly linked list
The following is the structure of a linked list in Java:
Refer to the below full Java program to create and traverse a linked list:
Linked List Time Complexity
Other Posts You May Like
- How to Find the length of a linked list
- How to Find the length of a linked list using Recursion
- Design Linked List
- Reverse a Linked List
- Rotate a Linked List