0% found this document useful (0 votes)
22 views27 pages

Linkedlist (Unit3) Ds

Linkedlist

Uploaded by

kulkaraniomkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views27 pages

Linkedlist (Unit3) Ds

Linkedlist

Uploaded by

kulkaraniomkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Unit 3

Singly Linked List

A singly linked list is a linear data structure in which the elements are not stored in contiguous
memory locations and each element is connected only to its next element using a pointer.

o Linked List can be defined as collection of objects called nodes that are randomly
stored in the memory.
o A node contains two fields i.e. data stored at that particular address and the pointer
which contains the address of the next node in the memory.
o The last node of the list contains pointer to the null.

Uses of Linked List


o The list is not required to be contiguously present in the memory. The node can reside any
where in the memory and linked together to make a list. This achieves optimized utilization
of space.
o list size is limited to the memory size and doesn't need to be declared in advance.
o Empty node can not be present in the linked list.
o We can store values of primitive types or objects in the singly linked list.

Why use linked list over array?


Till now, we were using array data structure to organize the group of elements that are to
be stored individually in the memory. However, Array has several advantages and
disadvantages which must be known in order to decide the data structure which will be
used throughout the program.

Array contains following limitations:

1. The size of array must be known in advance before using it in the program.
2. Increasing size of the array is a time taking process. It is almost impossible to expand the
size of the array at run time.
3. All the elements in the array need to be contiguously stored in the memory. Inserting any
element in the array needs shifting of all its predecessors.

Singly linked list or One way chain


Singly linked list can be defined as the collection of ordered set of elements. The number
of elements may vary according to need of the program. A node in the singly linked list
consist of two parts: data part and link part. Data part of the node stores actual
information that is to be represented by the node while the link part of the node stores
the address of its immediate successor.

One way chain or singly linked list can be traversed only in one direction. In other words,
we can say that each node contains only next pointer, therefore we can not traverse the
list in the reverse direction.

Consider an example where the marks obtained by the student in three subjects are stored
in a linked list as shown in the figure.

In
the above figure, the arrow represents the links. The data part of every node
contains the marks obtained by the student in the different subject. The last node
in the list is identified by the null pointer which is present in the address part of the
last node. We can have as many elements we require, in the data part of the list.
Operations on Singly Linked List
There are various operations which can be performed on singly linked list. A list of all such
operations is given below.
Node Creation

1. struct node
2. {
3. int data;
4. struct node *next;
5. };
6. struct node *head, *ptr;
7. ptr = (struct node *)malloc(sizeof(struct node *));

Insertion
The insertion into a singly linked list can be performed at different positions. Based on
the position of the new node being inserted, the insertion is categorized into the following
categories.

Insertion in singly linked list at beginning


Inserting a new element into a singly linked list at beginning is quite simple. We just need
to make a few adjustments in the node links. There are the following steps which need to
be followed in order to inser a new node in the list at beginning.

It involves inserting any element at the front of the list. We just need to a few link
adjustments to make the new node as the head of the list.

o Allocate the space for the new node and store data into the data part of the node. This
will be done by the following statements.

1. ptr = (struct node *) malloc(sizeof(struct node *));


2. ptr → data = item
o Make the link part of the new node pointing to the existing first node of the list. This will
be done by using the following statement.

1. ptr->next = head;
o At the last, we need to make the new node as the first node of the list this will be done by
using the following statement.
1. head = ptr;
Algorithm
o Step 1: IF PTR = NULL

WriteOVERFLOW
GotoStep7
[END OF IF]

o Step 2: SET NEW_NODE = PTR


o Step 3: SET PTR = PTR → NEXT
o Step 4: SET NEW_NODE → DATA = VAL
o Step 5: SET NEW_NODE → NEXT = HEAD
o Step 6: SET HEAD = NEW_NODE
o Step 7: EXIT

Insertion in singly linked list at the end


In order to insert a node at the last, there are two following scenarios which need to be
mentioned.

1. The node is being added to an empty list


2. The node is being added to the end of the linked list

in the first case,


o The condition (head == NULL) gets satisfied. Hence, we just need to allocate the space for
the node by using malloc statement in C. Data and the link part of the node are set up by
using the following statements.

1. ptr->data = item;
2. ptr -> next = NULL;
o Since, ptr is the only node that will be inserted in the list hence, we need to make this
node pointed by the head pointer of the list. This will be done by using the following
Statements.
1. Head = ptr
In the second case,
o The condition Head = NULL would fail, since Head is not null. Now, we need to declare a
temporary pointer temp in order to traverse through the list. temp is made to point the
first node of the list.

1. Temp = head
o Then, traverse through the entire linked list using the statements:

1. while (temp→ next != NULL)


2. temp = temp → next;
o At the end of the loop, the temp will be pointing to the last node of the list. Now, allocate
the space for the new node, and assign the item to its data part. Since, the new node is
going to be the last node of the list hence, the next part of this node needs to be pointing
to the null. We need to make the next part of the temp node (which is currently the last
node of the list) point to the new node (ptr) .

1. temp = head;
2. while (temp -> next != NULL)
3. {
4. temp = temp -> next;
5. }
6. temp->next = ptr;
7. ptr->next = NULL;
Algorithm
o Step1: IFPTR=NULLWriteOVERFLOW
GotoStep1
[END OF IF]
o Step 2: SET NEW_NODE = PTR
o Step 3: SET PTR = PTR - > NEXT
o Step 4: SET NEW_NODE - > DATA = VAL
o Step 5: SET NEW_NODE - > NEXT = NULL
o Step 6: SET PTR = HEAD
o Step 7: Repeat Step 8 while PTR - > NEXT != NULL
o Step8: SETPTR=PTR->NEXT
[END OF LOOP]
o Step 9: SET PTR - > NEXT = NEW_NODE
o Step 10: EXIT

Insertion in singly linked list after specified


Node
o In order to insert an element after the specified number of nodes into the linked list, we
need to skip the desired number of elements in the list to move the pointer at the position
after which the node will be inserted. This will be done by using the following statements.

1. emp=head;
2. for(i=0;i<loc;i++)
3. {
4. temp = temp->next;
5. if(temp == NULL)
6. {
7. return;
8. }
9.
10. }
o Allocate the space for the new node and add the item to the data part of it. This will be
done by using the following statements.

1. ptr = (struct node *) malloc (sizeof(struct node));


2. ptr->data = item;
o Now, we just need to make a few more link adjustments and our node at will be inserted
at the specified position. Since, at the end of the loop, the loop pointer temp would be
pointing to the node after which the new node will be inserted. Therefore, the next part of
the new node ptr must contain the address of the next part of the temp (since, ptr will be
in between temp and the next of the temp). This will be done by using the following
statements.

1. ptr→ next = temp → next

now, we just need to make the next part of the temp, point to the new node ptr. This will
insert the new node ptr, at the specified position.

1. temp ->next = ptr;


Algorithm
o STEP 1: IF PTR = NULL

WRITE OVERFLOW
GOTO STEP 12
END OF IF

o STEP 2: SET NEW_NODE = PTR


o STEP 3: NEW_NODE → DATA = VAL
o STEP 4: SET TEMP = HEAD
o STEP 5: SET I = 0
o STEP 6: REPEAT STEP 5 AND 6 UNTIL I<loc< li=""></loc<>
o STEP 7: TEMP = TEMP → NEXT
o STEP 8: IF TEMP = NULL

WRITE"DESIREDNODENOTPRESENT"
GOTOSTEP12
ENDOFIF
END OF LOOP

o STEP 9: PTR → NEXT = TEMP → NEXT


o STEP 10: TEMP → NEXT = PTR
o STEP 11: SET PTR = NEW_NODE
o STEP 12: EXIT

Deletion and Traversing


The Deletion of a node from a singly linked list can be performed at different positions.
Based on the position of the node being deleted, the operation is categorized into the
following categories.

Deleting a node from the beginning of the list is the simplest operation of all. It just need
a few adjustments in the node pointers. Since the first node of the list is to be deleted,
therefore, we just need to make the head, point to the next of the head. This will be done
by using the following statements.

1. ptr = head;
2. head = ptr->next;

Now, free the pointer ptr which was pointing to the head node of the list. This will be
done by using the following statement.

1. free(ptr)
Algorithm
o Step 1: IF HEAD = NULL
WriteUNDERFLOW
GotoStep5
[END OF IF]

o Step 2: SET PTR = HEAD


o Step 3: SET HEAD = HEAD -> NEXT
o Step 4: FREE PTR
o Step 5: EXIT

Deletion in singly linked list at the end


There are two scenarios in which, a node is deleted from the end of the linked list.

1. There is only one node in the list and that needs to be deleted.
2. There are more than one node in the list and the last node of the list will be deleted.

In the first scenario,


the condition head → next = NULL will survive and therefore, the only node head of the
list will be assigned to null. This will be done by using the following statements.

1. ptr = head
2. head = NULL
3. free(ptr)
In the second scenario,
The condition head → next = NULL would fail and therefore, we have to traverse the node
in order to reach the last node of the list.
For this purpose, just declare a temporary pointer temp and assign it to head of the list.
We also need to keep track of the second last node of the list. For this purpose, two
pointers ptr and ptr1 will be used where ptr will point to the last node and ptr1 will point
to the second last node of the list.

this all will be done by using the following statements.

1. ptr = head;
2. while(ptr->next != NULL)
3. {
4. ptr1 = ptr;
5. ptr = ptr ->next;
6. }

Now, we just need to make the pointer ptr1 point to the NULL and the last node of the
list that is pointed by ptr will become free. It will be done by using the following
statements.

1. ptr1->next = NULL;
2. free(ptr);

Algorithm
o Step 1: IF HEAD = NULL

Write UNDERFLOW
Go to Step 8
[END OF IF]

o Step 2: SET PTR = HEAD


o Step 3: Repeat Steps 4 and 5 while PTR -> NEXT!= NULL
o Step 4: SET PREPTR = PTR
o Step 5: SET PTR = PTR -> NEXT

[END OF LOOP]

o Step 6: SET PREPTR -> NEXT = NULL


o Step 7: FREE PTR
o Step 8: EXIT

Applications of Singly Linked List are as following:


1. It is used to implement stacks and queues which are like fundamental
needs throughout computer science.
2. To prevent the collision between the data in the hash map, we use a singly
linked list.
3. If we ever noticed the functioning of a casual notepad, it also uses a singly
linked list to perform un0do or redo or deleting functions.
4. We can think of its use in a photo viewer for having look at photos
continuously in a slide show.
5. In the system of train, the idea is like a singly linked list, as if you want to
add a Boggie, either you have to take a new boggie to add at last or you
must spot a place in between boggies and add it.

What is Doubly Linked List?

A doubly linked list (DLL) is a special type of linked list in which each node contains a
pointer to the previous node as well as the next node of the linked list. Doubly Linked
List is a Data Structure, which is a variation of the Linked List, in which the
transversal is possible in both the directions, forward and backward easily as
compared to the Singly Linked List, or which is also simply called as a Linked List.
So if a Linked List ⇒ A → B →. C
Then a Doubly Linked List ⇒ A ⇆ B ⇆ C

Representation of Doubly Linked List in Data Structure

If you can recall how the Linked List was represented using 2 parts: Value and the next pointer.
The Doubly Linked List has 3 parts: Value, Next pointer, and the Previous pointer.

The Previous pointer is the fundamental difference between the Doubly Linked List and the
Linked List, which enables one to transverse back also in the Doubly Linked List.

As per the above illustration, following are the important points to be considered.

• Each Doubly Linked List Element contains pointers to next and Previous Elements and
the data field.
• The First Element will have its Previous pointer as Null, to mark the start of the List.
• The Last Element will have its Next pointer as Null, to mark the end of the List

Basic Operations
Following are the basic operations supported by a list.
• Insertion − Adds an element at the beginning of the list.
• Deletion − Deletes an element at the beginning of the list.
• Insert Last − Adds an element at the end of the list.
• Delete Last − Deletes an element from the end of the list.
• Insert After − Adds an element after an item of the list.
• Delete − Deletes an element from the list using the key.
• Display forward − Displays the complete list in a forward manner.
• Display backward − Displays the complete list in a backward manner.

Insertion at the Beginning


In this operation, we create a new node with three compartments, one containing the
data, the others containing the address of its previous and next nodes in the list. This
new node is inserted at the beginning of the list.

Algorithm
1. START
2. Create a new node with three variables: prev, data, next.
3. Store the new data in the data variable
4. If the list is empty, make the new node as head.
5. Otherwise, link the address of the existing first node to the next variable of the new node,
and assign null to the prev variable.
6. Point the head to the new node.
7. END
Deletion at the Beginning
This deletion operation deletes the existing first nodes in the doubly linked list. The head
is shifted to the next node and the link is removed.

Algorithm
1. START
2. Check the status of the doubly linked list
3. If the list is empty, deletion is not possible
4. If the list is not empty, the head pointer is shifted to the next node.
5. END
Insertion at the End
In this insertion operation, the new input node is added at the end of the doubly linked
list; if the list is not empty. The head will be pointed to the new node, if the list is empty.

Algorithm
1. START
2. If the list is empty, add the node to the list and point the head to it.
3. If the list is not empty, find the last node of the list.
4. Create a link between the last node in the list and the new node.
5. The new node will point to NULL as it is the new last node.
6. END

Advantages of Doubly Linked List over the singly linked list:


• A DLL can be traversed in both forward and backward directions.
• The delete operation in DLL is more efficient if a pointer to the node to be deleted is
given.
• We can quickly insert a new node before a given node.
• In a singly linked list, to delete a node, a pointer to the previous node is needed. To get
this previous node, sometimes the list is traversed. In DLL, we can get the previous
node using the previous pointer.
Disadvantages of Doubly Linked List over the singly linked list:
• Every node of DLL Requires extra space for a previous pointer. It is possible to
implement DLL with a single pointer though (See this and this).
• All operations require an extra pointer previous to be maintained. For example, in
insertion, we need to modify previous pointers together with the next pointers. For
example in the following functions for insertions at different positions, we need 1 or 2
extra steps to set the previous pointer.

Applications of Doubly Linked List:

• It is used by web browsers for backward and forward navigation of web pages
• LRU ( Least Recently Used ) / MRU ( Most Recently Used ) Cache are constructed using
Doubly Linked Lists.
• Used by various applications to maintain undo and redo functionalities.
• In Operating Systems, a doubly linked list is maintained by thread scheduler to keep
track of processes that are being executed at that time.0
Circular linked list
In a circular Singly linked list, the last node of the list contains a pointer to the
first node of the list. We can have circular singly linked list as well as circular
doubly linked list.

We traverse a circular singly linked list until we reach the same node where we started.
The circular singly liked list has no beginning and no ending. There is no null value present
in the next part of any of the nodes.

The following image shows a circular singly linked list.

The circular linked list is a linked list where all nodes are connected to form a
circle. In a circular linked list, the first node and the last node are connected to
each other which forms a circle. There is no NULL at the end.
There are generally two types of circular linked lists:
• Circular singly linked list: In a circular Singly linked list, the last node
of the list contains a pointer to the first node of the list. We traverse
the circular singly linked list until we reach the same node where we
started. The circular singly linked list has no beginning or end. No null
value is present in the next part of any of the nodes.

Representation of Circular singly linked list

• Circular Doubly linked list: Circular Doubly Linked List has


properties of both doubly linked list and circular linked list in which
two consecutive elements are linked or connected by the previous
and next pointer and the last node points to the first node by the next
pointer and also the first node points to the last node by the previous
pointer.

Representation of circular doubly linked list

Representation of circular linked list:


Circular linked lists are similar to single Linked Lists with the exception of
connecting the last node to the first node.
Node representation of a Circular Linked List:
struct Node {

int data;

struct Node *next;

};

Memory Representation of circular linked list:


In the following image, memory representation of a circular linked list containing marks
of a student in 4 subjects. However, the image shows a glimpse of how the circular list is
being stored in the memory. The start or head of the list is pointing to the element with
the index 1 and containing 13 marks in the data part and 4 in the next part. Which means
that it is linked with the node that is being stored at 4th index of the list.

However, due to the fact that we are considering circular linked list in the memory
therefore the last node of the list contains the address of the first node of the list.
Insertion into circular singly linked list at
beginning
There are two scenario in which a node can be inserted in circular singly linked list at
beginning. Either the node will be inserted in an empty list or the node is to be inserted
in an already filled list.

Firstly, allocate the memory space for the new node by using the malloc method of C
language.

1. struct node *ptr = (struct node *)malloc(sizeof(struct node));

In the first scenario, the condition head == NULL will be true. Since, the list in which, we
are inserting the node is a circular singly linked list, therefore the only node of the list
(which is just inserted into the list) will point to itself only. We also need to make the head
pointer point to this node. This will be done by using the following statements.

1. if(head == NULL)
2. {
3. head = ptr;
4. ptr -> next = head;
5. }

In the second scenario, the condition head == NULL will become false which means that
the list contains at least one node. In this case, we need to traverse the list in order to
reach the last node of the list. This will be done by using the following statement.

1. temp = head;
2. while(temp->next != head)
3. temp = temp->next;

At the end of the loop, the pointer temp would point to the last node of the list. Since, in
a circular singly linked list, the last node of the list contains a pointer to the first node of
the list. Therefore, we need to make the next pointer of the last node point to the head
node of the list and the new node which is being inserted into the list will be the new
head node of the list therefore the next pointer of temp will point to the new node ptr.

This will be done by using the following statements.


1. temp -> next = ptr;

the next pointer of temp will point to the existing head node of the list.

1. ptr->next = head;

Now, make the new node ptr, the new head node of the circular singly linked list.

1. head = ptr;

in this way, the node ptr has been inserted into the circular singly linked list at beginning.

Algorithm
o Step 1: IF PTR = NULL

WriteOVERFLOW
GotoStep11
[END OF IF]

o Step 2: SET NEW_NODE = PTR


o Step 3: SET PTR = PTR -> NEXT
o Step 4: SET NEW_NODE -> DATA = VAL
o Step 5: SET TEMP = HEAD
o Step 6: Repeat Step 8 while TEMP -> NEXT != HEAD
o Step 7: SET TEMP = TEMP -> NEXT

[END OF LOOP]

o Step 8: SET NEW_NODE -> NEXT = HEAD


o Step 9: SET TEMP → NEXT = NEW_NODE
o Step 10: SET HEAD = NEW_NODE
o Step 11: EXIT
Insertion into circular singly linked list at the
end
There are two scenario in which a node can be inserted in circular singly linked list at
beginning. Either the node will be inserted in an empty list or the node is to be inserted
in an already filled list.

• Firstly, allocate the memory space for the new node by using the malloc method of C language.

1. struct node *ptr = (struct node *)malloc(sizeof(struct node));

In the first scenario, the condition head == NULL will be true. Since, the list in which, we are
inserting the node is a circular singly linked list, therefore the only node of the list (which is just
inserted into the list) will point to itself only. We also need to make the head pointer point to this
node. This will be done by using the following statements.

1. if(head == NULL)
2. {
3. head = ptr;
4. ptr -> next = head;
5. }

In the second scenario, the condition head == NULL will become false which means that the
list contains at least one node. In this case, we need to traverse the list in order to reach the last
node of the list. This will be done by using the following statement.

1. temp = head;
2. while(temp->next != head)
3. temp = temp->next;

At the end of the loop, the pointer temp would point to the last node of the list. Since, the new
node which is being inserted into the list will be the new last node of the list. Therefore the
existing last node i.e. temp must point to the new node ptr. This is done by using the following
statement.

1. temp -> next = ptr;

The new last node of the list i.e. ptr will point to the head node of the list.

1. ptr -> next = head;

In this way, a new node will be inserted in a circular singly linked list at the beginning.

Algorithm
o Step 1: IF PTR = NULL

WriteOVERFLOW
GotoStep1
[END OF IF]

o Step 2: SET NEW_NODE = PTR


o Step 3: SET PTR = PTR -> NEXT
o Step 4: SET NEW_NODE -> DATA = VAL
o Step 5: SET NEW_NODE -> NEXT = HEAD
o Step 6: SET TEMP = HEAD
o Step 7: Repeat Step 8 while TEMP -> NEXT != HEAD
o Step 8: SET TEMP = TEMP -> NEXT

[END OF LOOP]

o Step 9: SET TEMP -> NEXT = NEW_NODE


o Step 10: EXIT
Deletion in circular singly linked list at
beginning
In order to delete a node in circular singly linked list, we need to make a few pointer
adjustments.

There are three scenarios of deleting a node from circular singly linked list at beginning.

Scenario 1: (The list is Empty)


If the list is empty then the condition head == NULL will become true, in this case, we
just need to print underflow on the screen and make exit.

1. if(head == NULL)
2. {
3. printf("\nUNDERFLOW");
4. return;
5. }

Scenario 2: (The list contains single node)


If the list contains single node then, the condition head → next == head will become
true. In this case, we need to delete the entire list and make the head pointer free. This
will be done by using the following statements.
1. if(head->next == head)
2. {
3. head = NULL;
4. free(head);
5. }

Scenario 3: (The list contains more than one node)


If the list contains more than one node then, in that case, we need to traverse the list by
using the pointer ptr to reach the last node of the list. This will be done by using the
following statements.

1. ptr = head;
2. while(ptr -> next != head)
3. ptr = ptr -> next;

At the end of the loop, the pointer ptr point to the last node of the list. Since, the last
node of the list points to the head node of the list. Therefore this will be changed as now,
the last node of the list will point to the next of the head node.

1. ptr->next = head->next;

Now, free the head pointer by using the free() method in C language.

1. free(head);

Make the node pointed by the next of the last node, the new head of the list.

1. head = ptr->next;

In this way, the node will be deleted from the circular singly linked list from the beginning.

Algorithm
o Step 1: IF HEAD = NULL

WriteUNDERFLOW
GotoStep8
[END OF IF]
o Step 2: SET PTR = HEAD
o Step 3: Repeat Step 4 while PTR → NEXT != HEAD
o Step 4: SET PTR = PTR → next

[END OF LOOP]

o Step 5: SET PTR → NEXT = HEAD → NEXT


o Step 6: FREE HEAD
o Step 7: SET HEAD = PTR → NEXT
o Step 8: EXIT

Deletion in Circular singly linked list at the


end
There are three scenarios of deleting a node in circular singly linked list at the end.

Scenario 1 (the list is empty)


If the list is empty then the condition head == NULL will become true, in this case, we
just need to print underflow on the screen and make exit.
1. if(head == NULL)
2. {
3. printf("\nUNDERFLOW");
4. return;
5. }

Scenario 2(the list contains single element)


If the list contains single node then, the condition head → next == head will become
true. In this case, we need to delete the entire list and make the head pointer free. This
will be done by using the following statements.

1. if(head->next == head)
2. {
3. head = NULL;
4. free(head);
5. }

Scenario 3(the list contains more than one element)


If the list contains more than one element, then in order to delete the last element, we
need to reach the last node. We also need to keep track of the second last node of the
list. For this purpose, the two pointers ptr and preptr are defined. The following sequence
of code is used for this purpose.

1. ptr = head;
2. while(ptr ->next != head)
3. {
4. preptr=ptr;
5. ptr = ptr->next;
6. }

now, we need to make just one more pointer adjustment. We need to make the next
pointer of preptr point to the next of ptr (i.e. head) and then make pointer ptr free.

1. preptr->next = ptr -> next;


2. free(ptr);
Algorithm
o Step 1: IF HEAD = NULL

WriteUNDERFLOW
GotoStep8
[END OF IF]

o Step 2: SET PTR = HEAD


o Step 3: Repeat Steps 4 and 5 while PTR -> NEXT != HEAD
o Step 4: SET PREPTR = PTR
o Step 5: SET PTR = PTR -> NEXT

[END OF LOOP]

o Step 6: SET PREPTR -> NEXT = HEAD


o Step 7: FREE PTR
o Step 8: EXIT

Applications of circular linked lists:

• Multiplayer games use this to give each player a chance to play.


• A circular linked list can be used to organize multiple running
applications on an operating system. These applications are iterated
over by the OS.
• Circular linked lists can be used in resource allocation problems.
• Circular linked lists are commonly used to implement circular buffers,
• Circular linked lists can be used in simulation and gaming.

Advantages of Circular Linked Lists:


• Any node can be a starting point. We can traverse the whole list by
starting from any point. We just need to stop when the first visited
node is visited again.
• Useful for implementation of a queue. Unlike this implementation, we
don’t need to maintain two pointers for front and rear if we use a
circular linked list. We can maintain a pointer to the last inserted
node and the front can always be obtained as next of last.

• Circular lists are useful in applications to repeatedly go around the


list. For example, when multiple applications are running on a PC, it is
common for the operating system to put the running applications on a
list and then cycle through them, giving each of them a slice of time
to execute, and then making them wait while the CPU is given to
another application. It is convenient for the operating system to use a
circular list so that when it reaches the end of the list it can cycle
around to the front of the list.
• Circular Doubly Linked Lists are used for the implementation of
advanced data structures like the Fibonacci Heap.
• Implementing a circular linked list can be relatively easy compared to
other more complex data structures like trees or graphs.
Disadvantages of circular linked list:
• Compared to singly linked lists, circular lists are more complex.
• Reversing a circular list is more complicated than singly or doubly
reversing a circular list.
• It is possible for the code to go into an infinite loop if it is not handled
carefully.
• It is harder to find the end of the list and control the loop.
• Although circular linked lists can be efficient in certain applications,
their performance can be slower than other data structures in certain
cases, such as when the list needs to be sorted or searched.
• Circular linked lists don’t provide direct access to individual nodes
Application of Linked List
Linked list is used in a wide variety of applications such as

o Polynomial Manipulation representation


o Addition of long positive integers
o Representation of sparse matrices
o Addition of long positive integers
o Symbol table creation
o Mailing list
o Memory management
o Linked allocation of files
o Multiple precision arithmetic etc

You might also like