SlideShare a Scribd company logo
PRESENTAION ON
     LINKED LIST
LINKED LIST
   DEFINITION
   ARRAY Vs LINKED LIST
   TYPES
   OPERATIONS
Introduction
 Linear data structure
 Dynamic data structure
 A linked list is a series of connected
  nodes
 Each node contains at least
    ◦ A piece of data (any type)
    ◦ Pointer to the next node in the list


        NODE :     Info    link


                  Data    Pointer
                  item
REPRESENTATION OF A LINKED
   LIST WITH 3 NODES
Start




        Data item       Data item     Data item   X




    Head: pointer to the first node
    The last node points to NULL
REPRESENTATION OF AN
EMPTY LINKED LIST


         START


          X
VARIATIONS OF LINKED LIST
 Header linked list
 Circular linked list
 Two-way list(doubly linked list)
Variations of Linked Lists
   header linked lists
    ◦ A linked list with a special node called header
      node in the beginning of the list

                A           B           C   X

       Head   header node

    ◦ Header node doesn’t contain the actual data.
Variations of Linked Lists
   Circular linked lists
    ◦ The last node points to the first node of the list



                  A             B            C

       Head


    ◦ How do we know when we have finished
      traversing the list? (Tip: check if the pointer of
      the current node is equal to the head.)
Variations of Linked Lists
   Doubly linked lists
    ◦ Each node points to not only successor but the
      predecessor
    ◦ There are two NULL: at the first and last nodes
      in the list
    ◦ Advantage: given a node, it is easy to visit its
      predecessor. Convenient to traverse lists
      backwards
         A                 B               C

                     Back info
                     forw


        Head                              Tail
Operations on singly linked
list
  Creation
 Traversing(visiting)
 Counting
 Insertion
 Deletion
 Searching
 Merging(concatenating two lists)
 Reversing the list
 Updating
 Copying
Algorithm to traverse and count
one-way list

Set PTR=HEAD.

Set count =0.

Repeat step while PTR!=NULL
• Apply process to INFO[PTR].
• Set COUNT=COUNT+1
• Set PTR=LINK[PTR].
Write : COUNT

EXIT
Algorithm to search an element
ITEM in an unsorted one-way
list HEAD=NULL, then
Set
• Write: “list is empty”
• Set LOC= NULL
• And exit

Set PTR=HEAD

Repeat while PTR=!NULL
                           • If ITEM=INFO[PTR]
                                • Set LOC=PTR
                                   • And exit
                                    • Else
                            • Set PTR=LINK[PTR]
Set LOC= NULL

Write:”search is unsuccessful”


Exit
Algorithm to search an element
ITEM in an unsorted one-way list
Set HEAD=NULL, then
 • Write: “list is empty”
 • Set LOC= NULL
 • And exit
Set PTR=HEAD

Repeat while PTR=!NULL
 • If ITEM=INFO[PTR]
   • Set LOC=PTR
   • Write:”search is successful”
   • And exit
 • Else if ITEM>INFO[PTR]
   • Set PTR=LINK[PTR]
 • Else[ITEM<INFO[PTR]]
   • Set LOC=NULL
   • Write:”search is unsuccessful”
   • And exit
Set LOC= NULL
Write:”search is unsuccessful”
Exit
Algorithm to insert an element
ITEM at the begnning one-way
list
If AVAIL=NULL, then
• Write:”overflow”
• And exit
Set NEW=AVAIL
• Set AVAIL=LINK[AVAIL]

Set INFO[NEW]=ITEM

Set LINK[NEW]=HEAD
• Set HEAD= NEW

EXIT
Algorithm to insert an node after
a node with location LOC in
one-way list
If AVAIL=NULL, then
• Write:”overflow”
• And exit
Set NEW=AVAIL
• Set AVAIL=LINK[AVAIL]

Set INFO[NEW]=ITEM

If LOC =NULL, then
• Set LINK[NEW]=HEAD
• Set HEAD =NEW
ELSE
• Set LINK[NEW]=LINK[LOC]
• Set LINK[LOC]=NEW
Exit
Algorithm to delete first node of
one-way list
If HEAD=NULL, then
• Write:”underflow”
• And exit
Set NEW=HEAD
• Set HEAD=LINK[HEAD]

Set LINK[NEW]=AVAIL
• Set AVAIL=NEW

EXIT
Algorithm to delete a node with
location LOC from one-way list
If HEAD=NULL, then
• Write:”underflow”
• And exit
If LOC=NULL, THEN
• Write:”node not found in the list
• And exit
If LOCP=NULL, then
• Set HEAD=LINK[HEAD]

Else
• Set LINK[LOCP]=LINK[LOC]
Set LINK[LOC]=AVAIL
• Set AVAIL=LOC

exit
ARRAY VERSUS LINKED
LISTS
   Linked lists are more complex to code and manage
    than arrays, but they have some distinct
    advantages.
    ◦ Dynamic: a linked list can easily grow and shrink in size.
       We don’t need to know how many nodes will be in the list. They
        are created in memory as needed.
       In contrast, the size of a C++ array is fixed at compilation time.
    ◦ Easy and fast insertions and deletions
       In array, Insertion and deleltion are more time consuming as
        large no. of elements need to be shifted to make space for
        inserting a new element or to cover the space created by
        deleting an existing element.
       With a linked list, no need to move other nodes. Only need to
        reset some pointers.
ANY
QUERY

More Related Content

What's hot

Tree
TreeTree
Singly link list
Singly link listSingly link list
Singly link list
Rojin Khadka
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stackvaibhav2910
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
Gurukul Kangri Vishwavidyalaya - Faculty of Engineering and Technology
 
Linear and Binary search
Linear and Binary searchLinear and Binary search
Linear and Binary search
Nisha Soms
 
Linked list
Linked listLinked list
Linked list
Md. Afif Al Mamun
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
Zidny Nafan
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
Dharita Chokshi
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structureSajid Marwat
 
B and B+ tree
B and B+ treeB and B+ tree
B and B+ tree
Ashish Arun
 
Linked list
Linked listLinked list
Linked list
MahammadAdil
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
Meghaj Mallick
 
Types of Tree in Data Structure in C++
Types of Tree in Data Structure in C++Types of Tree in Data Structure in C++
Types of Tree in Data Structure in C++
Himanshu Choudhary
 
Linked List
Linked ListLinked List
Linked List
Ashim Lamichhane
 
Insertion in singly linked list
Insertion in singly linked listInsertion in singly linked list
Insertion in singly linked list
Keval Bhogayata
 
Linked list
Linked listLinked list
Linked list
RahulGandhi110
 
Linked list implementation of Queue
Linked list implementation of QueueLinked list implementation of Queue
Linked list implementation of Queue
Dr. Sindhia Lingaswamy
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)
Elavarasi K
 

What's hot (20)

Tree
TreeTree
Tree
 
Singly link list
Singly link listSingly link list
Singly link list
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
 
Linear and Binary search
Linear and Binary searchLinear and Binary search
Linear and Binary search
 
Linked list
Linked listLinked list
Linked list
 
single linked list
single linked listsingle linked list
single linked list
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structure
 
B and B+ tree
B and B+ treeB and B+ tree
B and B+ tree
 
Linked list
Linked listLinked list
Linked list
 
Linked list
Linked listLinked list
Linked list
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
 
Types of Tree in Data Structure in C++
Types of Tree in Data Structure in C++Types of Tree in Data Structure in C++
Types of Tree in Data Structure in C++
 
Linked List
Linked ListLinked List
Linked List
 
Insertion in singly linked list
Insertion in singly linked listInsertion in singly linked list
Insertion in singly linked list
 
Linked list
Linked listLinked list
Linked list
 
Linked list implementation of Queue
Linked list implementation of QueueLinked list implementation of Queue
Linked list implementation of Queue
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)
 

Viewers also liked

Linked lists
Linked listsLinked lists
Link List
Link ListLink List
Link List
umiekalsum
 
Array 2
Array 2Array 2
Array 2
Abbott
 
Array data structure
Array data structureArray data structure
Array data structure
maamir farooq
 
Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)
mailmerk
 
Array implementation and linked list as datat structure
Array implementation and linked list as datat structureArray implementation and linked list as datat structure
Array implementation and linked list as datat structureTushar Aneyrao
 
Single linked list
Single linked listSingle linked list
Single linked list
jasbirsingh chauhan
 
Linked list
Linked listLinked list
Linked list
Trupti Agrawal
 
Arrays
ArraysArrays
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithmsmultimedia9
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
Mohammed Hussein
 
Data Structures - Searching & sorting
Data Structures - Searching & sortingData Structures - Searching & sorting
Data Structures - Searching & sorting
Kaushal Shah
 
9. Searching & Sorting - Data Structures using C++ by Varsha Patil
9. Searching & Sorting - Data Structures using C++ by Varsha Patil9. Searching & Sorting - Data Structures using C++ by Varsha Patil
9. Searching & Sorting - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
Circular linked list
Circular linked listCircular linked list
Circular linked listdchuynh
 
List Data Structure
List Data StructureList Data Structure
List Data Structure
Zidny Nafan
 

Viewers also liked (16)

Linked lists
Linked listsLinked lists
Linked lists
 
Link List
Link ListLink List
Link List
 
Array 2
Array 2Array 2
Array 2
 
Array data structure
Array data structureArray data structure
Array data structure
 
Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)
 
Array implementation and linked list as datat structure
Array implementation and linked list as datat structureArray implementation and linked list as datat structure
Array implementation and linked list as datat structure
 
Single linked list
Single linked listSingle linked list
Single linked list
 
Sorting
SortingSorting
Sorting
 
Linked list
Linked listLinked list
Linked list
 
Arrays
ArraysArrays
Arrays
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Data Structures - Searching & sorting
Data Structures - Searching & sortingData Structures - Searching & sorting
Data Structures - Searching & sorting
 
9. Searching & Sorting - Data Structures using C++ by Varsha Patil
9. Searching & Sorting - Data Structures using C++ by Varsha Patil9. Searching & Sorting - Data Structures using C++ by Varsha Patil
9. Searching & Sorting - Data Structures using C++ by Varsha Patil
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
List Data Structure
List Data StructureList Data Structure
List Data Structure
 

Similar to Linked list

Data structure lecture 5
Data structure lecture 5Data structure lecture 5
Data structure lecture 5Kumar
 
Bca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothiBca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothi
Sowmya Jyothi
 
4.linked list(contd.)
4.linked list(contd.)4.linked list(contd.)
4.linked list(contd.)
Chandan Singh
 
Lecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsLecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsAakash deep Singhal
 
linked-list.ppt
linked-list.pptlinked-list.ppt
linked-list.ppt
DikkySuryadiSKomMKom
 
Linked list
Linked listLinked list
Linked list
KalaivaniKS1
 
ds 4Linked lists.ppt
ds 4Linked lists.pptds 4Linked lists.ppt
ds 4Linked lists.ppt
AlliVinay1
 
Dounly linked list
Dounly linked listDounly linked list
Dounly linked list
NirmalPandey23
 
Linked lists a
Linked lists aLinked lists a
Linked lists a
Khuram Shahzad
 
Linklist
LinklistLinklist
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked lists
Abdullah Al-hazmy
 
Linked List Presentation in data structurepptx
Linked List Presentation in data structurepptxLinked List Presentation in data structurepptx
Linked List Presentation in data structurepptx
nikhilcse1
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
Sumathi Kv
 
Data Structure and Algorithm Lesson 2.pptx
Data Structure and Algorithm Lesson 2.pptxData Structure and Algorithm Lesson 2.pptx
Data Structure and Algorithm Lesson 2.pptx
JoannahClaireAlforqu
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
Durga Devi
 
unit 2- PPT.pdf
unit 2- PPT.pdfunit 2- PPT.pdf
unit 2- PPT.pdf
PranavMakwana6
 
Linked list and its operations - Traversal
Linked list and its operations - TraversalLinked list and its operations - Traversal
Linked list and its operations - Traversal
kasthurimukila
 
Linked List.pptx
Linked List.pptxLinked List.pptx
Linked List.pptx
SherinRappai
 
Data Structure
Data StructureData Structure
Data Structure
HarshGupta663
 

Similar to Linked list (20)

Data structure lecture 5
Data structure lecture 5Data structure lecture 5
Data structure lecture 5
 
Bca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothiBca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothi
 
4.linked list(contd.)
4.linked list(contd.)4.linked list(contd.)
4.linked list(contd.)
 
Lecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsLecture 5 data structures and algorithms
Lecture 5 data structures and algorithms
 
linked-list.ppt
linked-list.pptlinked-list.ppt
linked-list.ppt
 
Linked list
Linked listLinked list
Linked list
 
ds 4Linked lists.ppt
ds 4Linked lists.pptds 4Linked lists.ppt
ds 4Linked lists.ppt
 
Dounly linked list
Dounly linked listDounly linked list
Dounly linked list
 
Linked lists a
Linked lists aLinked lists a
Linked lists a
 
Data structures2
Data structures2Data structures2
Data structures2
 
Linklist
LinklistLinklist
Linklist
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked lists
 
Linked List Presentation in data structurepptx
Linked List Presentation in data structurepptxLinked List Presentation in data structurepptx
Linked List Presentation in data structurepptx
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
 
Data Structure and Algorithm Lesson 2.pptx
Data Structure and Algorithm Lesson 2.pptxData Structure and Algorithm Lesson 2.pptx
Data Structure and Algorithm Lesson 2.pptx
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
 
unit 2- PPT.pdf
unit 2- PPT.pdfunit 2- PPT.pdf
unit 2- PPT.pdf
 
Linked list and its operations - Traversal
Linked list and its operations - TraversalLinked list and its operations - Traversal
Linked list and its operations - Traversal
 
Linked List.pptx
Linked List.pptxLinked List.pptx
Linked List.pptx
 
Data Structure
Data StructureData Structure
Data Structure
 

Linked list

  • 1. PRESENTAION ON LINKED LIST
  • 2. LINKED LIST  DEFINITION  ARRAY Vs LINKED LIST  TYPES  OPERATIONS
  • 3. Introduction  Linear data structure  Dynamic data structure  A linked list is a series of connected nodes  Each node contains at least ◦ A piece of data (any type) ◦ Pointer to the next node in the list NODE : Info link Data Pointer item
  • 4. REPRESENTATION OF A LINKED LIST WITH 3 NODES Start Data item Data item Data item X Head: pointer to the first node The last node points to NULL
  • 5. REPRESENTATION OF AN EMPTY LINKED LIST START X
  • 6. VARIATIONS OF LINKED LIST  Header linked list  Circular linked list  Two-way list(doubly linked list)
  • 7. Variations of Linked Lists  header linked lists ◦ A linked list with a special node called header node in the beginning of the list A B C X Head header node ◦ Header node doesn’t contain the actual data.
  • 8. Variations of Linked Lists  Circular linked lists ◦ The last node points to the first node of the list A B C Head ◦ How do we know when we have finished traversing the list? (Tip: check if the pointer of the current node is equal to the head.)
  • 9. Variations of Linked Lists  Doubly linked lists ◦ Each node points to not only successor but the predecessor ◦ There are two NULL: at the first and last nodes in the list ◦ Advantage: given a node, it is easy to visit its predecessor. Convenient to traverse lists backwards A B C Back info forw Head Tail
  • 10. Operations on singly linked list  Creation  Traversing(visiting)  Counting  Insertion  Deletion  Searching  Merging(concatenating two lists)  Reversing the list  Updating  Copying
  • 11. Algorithm to traverse and count one-way list Set PTR=HEAD. Set count =0. Repeat step while PTR!=NULL • Apply process to INFO[PTR]. • Set COUNT=COUNT+1 • Set PTR=LINK[PTR]. Write : COUNT EXIT
  • 12. Algorithm to search an element ITEM in an unsorted one-way list HEAD=NULL, then Set • Write: “list is empty” • Set LOC= NULL • And exit Set PTR=HEAD Repeat while PTR=!NULL • If ITEM=INFO[PTR] • Set LOC=PTR • And exit • Else • Set PTR=LINK[PTR]
  • 13. Set LOC= NULL Write:”search is unsuccessful” Exit
  • 14. Algorithm to search an element ITEM in an unsorted one-way list Set HEAD=NULL, then • Write: “list is empty” • Set LOC= NULL • And exit Set PTR=HEAD Repeat while PTR=!NULL • If ITEM=INFO[PTR] • Set LOC=PTR • Write:”search is successful” • And exit • Else if ITEM>INFO[PTR] • Set PTR=LINK[PTR] • Else[ITEM<INFO[PTR]] • Set LOC=NULL • Write:”search is unsuccessful” • And exit
  • 15. Set LOC= NULL Write:”search is unsuccessful” Exit
  • 16. Algorithm to insert an element ITEM at the begnning one-way list If AVAIL=NULL, then • Write:”overflow” • And exit Set NEW=AVAIL • Set AVAIL=LINK[AVAIL] Set INFO[NEW]=ITEM Set LINK[NEW]=HEAD • Set HEAD= NEW EXIT
  • 17. Algorithm to insert an node after a node with location LOC in one-way list If AVAIL=NULL, then • Write:”overflow” • And exit Set NEW=AVAIL • Set AVAIL=LINK[AVAIL] Set INFO[NEW]=ITEM If LOC =NULL, then • Set LINK[NEW]=HEAD • Set HEAD =NEW
  • 18. ELSE • Set LINK[NEW]=LINK[LOC] • Set LINK[LOC]=NEW Exit
  • 19. Algorithm to delete first node of one-way list If HEAD=NULL, then • Write:”underflow” • And exit Set NEW=HEAD • Set HEAD=LINK[HEAD] Set LINK[NEW]=AVAIL • Set AVAIL=NEW EXIT
  • 20. Algorithm to delete a node with location LOC from one-way list If HEAD=NULL, then • Write:”underflow” • And exit If LOC=NULL, THEN • Write:”node not found in the list • And exit If LOCP=NULL, then • Set HEAD=LINK[HEAD] Else • Set LINK[LOCP]=LINK[LOC]
  • 21. Set LINK[LOC]=AVAIL • Set AVAIL=LOC exit
  • 22. ARRAY VERSUS LINKED LISTS  Linked lists are more complex to code and manage than arrays, but they have some distinct advantages. ◦ Dynamic: a linked list can easily grow and shrink in size.  We don’t need to know how many nodes will be in the list. They are created in memory as needed.  In contrast, the size of a C++ array is fixed at compilation time. ◦ Easy and fast insertions and deletions  In array, Insertion and deleltion are more time consuming as large no. of elements need to be shifted to make space for inserting a new element or to cover the space created by deleting an existing element.  With a linked list, no need to move other nodes. Only need to reset some pointers.