Linked List
Linked List
LINEAR NONLINEAR
ARRAY
TREES&
LINKLIST STACK
GRAPH
QUEUE
Linked list
Linked list is a linear data structure. It contains nodes. Each
node contains two parts, i.e. DATA part and LINK part.
✓The data contains elements and
✓Link contains address of another node.
Node
Data Link/Address
Start
25 10 15 /
10
Cont.
https://www.w3resource.com/c-programming-exercises/linked_list/c-linked_list-exercise-1.php
Linked List Demo
addr Value
Node third = new Node();
C0 -
third.item = "Carol";
third.next = null; C1 -
C7 -
C8 -
C9 -
CA -
CB -
CC -
CD -
CE -
CF -
main memory
1
Operations on Linked Lists
The basic operations on linked lists are
1. Creation
2. Insertion
3. Deletion
4. Traversing
5. Searching
6. Concatenation
7. Display
Cont.
Start
First
First
First
Node A Node B
Cont.
START
Node A Node B
START
(a). Before Insertion
Node A Node B
------------------------
Node N
Node A Node B
AVAIL
Node N
Free-storage list
Node A Node B
------------------------
AVAIL
Node N
....
Free-storage list
Cont.
AVAIL
...
Free-storage list
Cont.
1. The nextpointer field of node A now points to the
new node B, where node N previously pointed.
2. The nextpointer field of node N now points to the
original first node in the free pool, where AVAIL
previously pointed.
3. AVAIL now points to the deleted node N.
https://visualgo.net/en/list
Wastage of Memory
Pointer Requires extra memory for storage.
Suppose we want to store 3 integer data items then we have to allocate
memory –
In case of array –
Memory Required in Array = 3 Integer * Size
= 3 * 2 bytes
= 6 bytes
In case of array –
Memory Required in LL = 3 Integer * Size of Node
= 3 * Size of Node Structure
= 3 * Size(data + address pointer)
= 3 * (2 bytes + x bytes)
= 6 bytes + 3x bytes
Advantages and Disadvantages of
Linked List
Applications of Linked List
Difference Between Array and
Linked List