Linked List
A linked list is a linear data structure that does not store elements in contiguous memory locations, the elements in the linked list are linked using pointers. It is a collection of nodes in which each node stores data and a pointer that links to the next node to form a sequence of nodes.
-> Linked List is a linear data structure which is a combination of Nodes.
-> Nodes contain two parts i.e. data & address.
Representation of a Linked List in C:
A linked list is represented as a pointer to the first node where each node contains:
- Data: Here the actual information is stored.
- Next: Pointer that links to the next node.
Advantages of a Linked List:
- Linked list is dynamic data structure it has memory allocation and de-allocation, which means that memory is only used when needed and not earlier in order to avoid waste.
- In linked list items are arranged in a linear fashion, new items can be inserted or removed as and when needed without affecting other items on the list, which makes these processes efficient.
- Memory is utilized effectively since nodes are created on-demand, which means that memory is not pre-allocated when the system has less load.
- Several linear data structures, like stacks and queues, can be implemented with the help of linked lists.
Disadvantages of a Linked List:
- In a linked list whenever we want to find the element with position n, all the other elements must be visited first, and this could take quite a lot of time.
- In a linked list, there is more memory needed than there is with an array because each node contains some pointer information.
- An operation that involves accessing elements of a linked list is not as simple as that in an array since elements of a linked list do not have indices that would help you jump to a given position directly.
- Reversing a linked list involves more than one level of pointer arrows in a singly linked list is not feasible or efficient.
Applications of Linked Lists:
The following are the applications of linked list:
- Linked list are commonly used to implement stacks and queues.
- It can be used to implement graphs, with the adjacent vertices stored in the nodes of the linked list.
- It can be used in dynamic memory allocation.
- It is used for representing sparse matrices.
- It can be used to store and manipulate polynomials.
- Linked list is used in operating systems to manage task scheduling.
- It is also used in compilers to build a symbol table.
Linked List is of 3 types:
i. Singly Linked List.
ii. Doubly Linked List.
iii. Circular Linked List
In Linked List we can perform various operations such of them are listed below:
a. Insertion of Node
b. Deletion of Nodes
c. Traverse
d. Search
e. Reverse etc.
Here are the detail and explanation about all types of linked list.
#Singly Linked List:
-> A singly linked list is a fundamental data structure in computer science and programming, it consists of nodes where each node contains a data field and a reference to the next node in the node. The last node points to null, indicating the end of the list.
Here is the code in C:
Output Will be Like:
Comments
Post a Comment