01
6 Marks Question
What is Linked List? Explain Singly Linked List in Detail
Introduction to Linked List
A linked list is a linear data structure in which elements are stored in the form of nodes connected through links (pointers). It allows dynamic memory allocation and efficient insertion and deletion.
Definition: A linked list is a sequence of nodes where each node contains data and a reference (link) to the next node in the sequence.
Basic Components of a Linked List
Node (Link)
The basic unit — stores the actual data value.
Next Pointer
Points to the address of the next node in the sequence.
Head (First)
A special pointer that points to the first node of the list.
Last Node
Points to
NULL to indicate the end of the list.Singly Linked List
A singly linked list is a type of linked list where each node contains a data field and one pointer (next) pointing to the next node. Traversal is possible only in the forward direction.
Structure of a Singly Linked List
Visual Representation
HEAD
↓
10data
●→next
→
20data
●→next
→
30data
●→next
→
NULL
- Each node has the form:
[data | next] - The first node is accessed using
head. - The last node points to
NULLindicating end of list.
Basic Operations
Insertion
Add a new node at the beginning, middle, or end of the list.
Deletion
Remove an existing node from the list.
Traversal (Display)
Visit each node from head to NULL to display all elements.
Search
Find a specific element by traversing through the nodes.
Example — Java Representation
Java Codeclass Node {
int data;
Node next;
}
class LinkedList {
Node head;
void insert(int data) {
Node newNode = new Node();
newNode.data = data;
newNode.next = head;
head = newNode;
}
}
Explanation
Nodeclass holds thedatavalue and anextreference to the next node.LinkedListclass maintains theheadpointer to the first node.insert()adds a new node at the beginning by pointing the new node'snextto the currenthead, then updatinghead.
Advantages & Disadvantages
✓ Advantages
- Dynamic size — no fixed size limit
- Efficient insertion and deletion
- No memory wastage
✗ Disadvantages
- No random access — sequential only
- If head is lost, entire list is lost
- Extra memory required for pointer
Conclusion
A singly linked list is a dynamic linear data structure where nodes are connected sequentially using pointers. It is widely used where frequent insertion and deletion operations are required.