Single Linked List
Single Linked List
(CS-303)
Single Linked List
LINKED LIST
Drawbacks:
1) Random access is not allowed. We have to access elements
sequentially starting from the first node. So we cannot do binary
search with linked lists efficiently with its default implementation.
Read about it here.
2) Extra memory space for a pointer is required with each element of
the list.
3) Not cache friendly. Since array elements are contiguous locations,
there is locality of reference which is not there in case of linked lists.
Representation:
A linked list is represented by a pointer to the first node of the
linked list. The first node is called the head. If the linked list is
empty, then the value of the head is NULL.
Each node in a list consists of at least two parts:
1) data
2) Pointer (Or Reference) to the next node
class Node {
public:
int data;
Node* next;
};
Data Address
Data Address
Data Address
Data Address
Data NULL
1
2
3 O 6
START 9
4 T 0
5
6 11
7 X 10
8
9 N 3
10 I 4
11 E 7
12
Prepared by: Dr. Jagdish Makhijani 15
TRAVERSAL IN LINKED LIST
AVAIL LIST
GARBAGE COLLECTION
OVERFLOW
UNDERFLOW