A linked list is a linear data structure where each node contains a data field and a reference to the next node. There are different types of linked lists including singly linked lists where each node has a pointer to the next node, doubly linked lists where each node has pointers to both the next and previous nodes, and circular linked lists where the last node points back to the first node. Linked lists allow for dynamic memory allocation and easy insertion/deletion of nodes but have slower access times than arrays.
Roadmap to Membership of RICS - Pathways and Routes
Linked list part-1
1. Linked List
A Linear Data Structure
SONI GUPTA
ASSISTANT PROFESSOR (NPIU-TEQIP III )
HBTU KANPUR, UP
TEQIP
-III
2. A linked list consists of nodes where each node contains a data field and a
reference(link/pointer) to the next node in the list.
TEQIP
-III
head
4. Declaring a Linked list
a linked list can be implemented using structure and pointers .
struct Node{
int data;
struct Node *Next;
};
Next is a self-referencing pointer
TEQIP
-III
5. Types of Linked Lists
Singly Linked List
Doubly Linked List
Circular Linked List
TEQIP
-III
6. Singly Linked List
Singly linked lists contain nodes which have a data part as well as an address,
which points to the next node.
TEQIP
-III
7. Doubly Linked List
In a doubly linked list, each node contains a data part and two addresses, one for
the previous node and one for the next node.
TEQIP
-III
9. Circular linked list
In circular linked list the last node of the linked list holds the address of the first
node, forming a circular chain.
Circular Singly linked list
TEQIP
-III
11. Operation on a Linked List
Insert a Node
Insert at first position
Insert at last position
Insert in between the linked list
Delete
Traverse
Copy
TEQIP
-III
12. Advantages
Linked list is dynamic in nature which allocates the memory when required.
Insertion and deletion operations can be easily implemented.
Linked List reduces the access time.
In Linked Lists we don't need to know the size in advance.
TEQIP
-III
13. Disadvantages
The memory is wasted as pointers require extra memory for storage.
No element can be accessed randomly. It has to access each node sequentially.
Reverse Traversing is difficult linked list.
TEQIP
-III
14. Array vs. Linked List
Array
Array supports Random Access.
Accessing elements in an array is fast with a
constant time complexity of O(1)
In an array, elements are stored in contiguous
memory location or consecutive manner in the
memory.
Memory is allocated as soon as the array is
declared, at compile time. It's also known
as Static Memory Allocation.
Size of the array must be specified at time of
array declaration.
Linked List
Linked List supports Sequential Access.
To access nth element of a linked list, time
complexity is O(n).
In a linked list, new elements can be stored
anywhere in the memory.
Memory is allocated at runtime, as and when a
new node is added. It's also known as Dynamic
Memory Allocation.
Size of a Linked list is variable. It grows at
runtime, as more nodes are added to it.
TEQIP
-III