Data Structure
Link List
Unit-2
Linked List
• Linked List can be defined as collection of
objects called nodes that are randomly stored
in the memory.
• 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.
• The last node of the list contains pointer to
the null.
Each node holds its own data and the address of
the next node hence forming a chain like structure.
Linked Lists are used to create trees and graphs.
Types of Link List
Following are the types of linked list
• Singly Linked List.
• Doubly Linked List.
• Circular Linked List.
Insertion of node at particular position
Deleting node at Beginning of Link List
Deletion of node at the End of Link List
Deletion of node at the End of Link List
Deleting a particular node from Link List
Reversing the Link List
Reversing the Link List
Copying a Link List into other Link List
Merging Two Link List
Doubly Linked List
• A Doubly Linked List contains an extra memory
to store the address of the previous node,
together with the address of the next node and
data which are there in the singly linked list. So,
here we are storing the address of the next as
well as the previous nodes.
• The following is the structure of the node in the
Doubly Linked List(DLL):
Operations Performed on Two way Link List
• Traversing
• Searching
• Insertion
• Deletion
Traversing Two Way Link List
Two way link list can be traversed in both the directions i.e.
in forward direction as well as backward direction.
Searching Two Way Link List
• Traverse the list until the pointer becomes null. Keep
shifting pointer to its next and increasing by +1.
• Compare each element of the list with the item which
is to be searched.
• If the item matched with any node value then the
location of that value I will be returned from the
function else NULL is returned.
Insertion of node in Two way Link List
There are three cases while inserting node
• Insertion at the Beginning
• Insertion at the End
• Insertion at the Particular position
Inserting the node at the Beginning
Inserting the node at the End
Inserting the node at particular position
Deleting Node at Particular Position Two Way Link List
Deleting Last Node in Two Way Link List
Circular Link List
All Circular linked list is a list in which last node points
back to the first node instead of containing the Null pointer
in the next part of the last node.
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 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.
Operations on circular singly linked list
SN Operation Description
1 Insertion at beginning Adding a node in circular singly
linked list at the beginning.
2 Insertion at end Adding a node in circular singly
linked list at the end.
3 Deletion at beginning Removing a node in circular singly
linked list from beginning.
4 Deletion at end Removing a node in circular singly
linked list at the end.
5
Traversing
Visiting each element of the list at
least once in order to perform some
specific operation.
Circular Doubly Linked List
Circular doubly linked list is a more complexed type of
data structure in which a node contain pointers to its
previous node as well as the next node. Circular doubly
linked list doesn't contain NULL in any of the node. The
last node of the list contains the address of the first node
of the list. The first node of the list also contain address
of the last node in its previous pointer.
Operations on circular doubly linked list
:
SN Operation Description
1 Insertion at beginning Adding a node in circular doubly
linked list at the beginning.
2 Insertion at end Adding a node in circular doubly
linked list at the end.
3 Deletion at beginning Removing a node in circular doubly
linked list from beginning.
4 Deletion at end Removing a node in circular doubly
linked list at the end.
Advantages of a Circular linked list
• The list can be traversed from any node.
• Circular lists are the required data
structure when we want a list to be
accessed in a circle or loop.
• We can easily traverse to its previous
node in a circular linked list, which is not
possible in a singly linked list.
Disadvantages of Circular linked list
• If not traversed carefully, then we could
end up in an infinite loop because here
we don't have any NULL value to stop
the traversal.
• Operations in a circular linked list are
complex as compared to a singly linked
list and doubly linked list.
Link_List.pptx

Link_List.pptx

  • 1.
  • 2.
    Linked List • LinkedList can be defined as collection of objects called nodes that are randomly stored in the memory. • 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. • The last node of the list contains pointer to the null.
  • 3.
    Each node holdsits own data and the address of the next node hence forming a chain like structure. Linked Lists are used to create trees and graphs.
  • 4.
    Types of LinkList Following are the types of linked list • Singly Linked List. • Doubly Linked List. • Circular Linked List.
  • 15.
    Insertion of nodeat particular position
  • 18.
    Deleting node atBeginning of Link List
  • 20.
    Deletion of nodeat the End of Link List
  • 21.
    Deletion of nodeat the End of Link List
  • 23.
    Deleting a particularnode from Link List
  • 25.
  • 26.
  • 27.
    Copying a LinkList into other Link List
  • 28.
  • 29.
    Doubly Linked List •A Doubly Linked List contains an extra memory to store the address of the previous node, together with the address of the next node and data which are there in the singly linked list. So, here we are storing the address of the next as well as the previous nodes. • The following is the structure of the node in the Doubly Linked List(DLL):
  • 32.
    Operations Performed onTwo way Link List • Traversing • Searching • Insertion • Deletion
  • 33.
    Traversing Two WayLink List Two way link list can be traversed in both the directions i.e. in forward direction as well as backward direction.
  • 34.
    Searching Two WayLink List • Traverse the list until the pointer becomes null. Keep shifting pointer to its next and increasing by +1. • Compare each element of the list with the item which is to be searched. • If the item matched with any node value then the location of that value I will be returned from the function else NULL is returned.
  • 35.
    Insertion of nodein Two way Link List There are three cases while inserting node • Insertion at the Beginning • Insertion at the End • Insertion at the Particular position
  • 36.
    Inserting the nodeat the Beginning
  • 37.
  • 38.
    Inserting the nodeat particular position
  • 41.
    Deleting Node atParticular Position Two Way Link List
  • 43.
    Deleting Last Nodein Two Way Link List
  • 45.
    Circular Link List AllCircular linked list is a list in which last node points back to the first node instead of containing the Null pointer in the next part of the last node.
  • 48.
    Circular Singly LinkedList 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.
  • 49.
    Operations on circularsingly linked list SN Operation Description 1 Insertion at beginning Adding a node in circular singly linked list at the beginning. 2 Insertion at end Adding a node in circular singly linked list at the end. 3 Deletion at beginning Removing a node in circular singly linked list from beginning. 4 Deletion at end Removing a node in circular singly linked list at the end. 5 Traversing Visiting each element of the list at least once in order to perform some specific operation.
  • 50.
    Circular Doubly LinkedList Circular doubly linked list is a more complexed type of data structure in which a node contain pointers to its previous node as well as the next node. Circular doubly linked list doesn't contain NULL in any of the node. The last node of the list contains the address of the first node of the list. The first node of the list also contain address of the last node in its previous pointer.
  • 51.
    Operations on circulardoubly linked list : SN Operation Description 1 Insertion at beginning Adding a node in circular doubly linked list at the beginning. 2 Insertion at end Adding a node in circular doubly linked list at the end. 3 Deletion at beginning Removing a node in circular doubly linked list from beginning. 4 Deletion at end Removing a node in circular doubly linked list at the end.
  • 52.
    Advantages of aCircular linked list • The list can be traversed from any node. • Circular lists are the required data structure when we want a list to be accessed in a circle or loop. • We can easily traverse to its previous node in a circular linked list, which is not possible in a singly linked list.
  • 53.
    Disadvantages of Circularlinked list • If not traversed carefully, then we could end up in an infinite loop because here we don't have any NULL value to stop the traversal. • Operations in a circular linked list are complex as compared to a singly linked list and doubly linked list.