SlideShare a Scribd company logo
1 of 23
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

What's hot (20)

Singly link list
Singly link listSingly link list
Singly link list
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
 
Terminology of tree
Terminology of treeTerminology of tree
Terminology of tree
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 
Tree traversal techniques
Tree traversal techniquesTree traversal techniques
Tree traversal techniques
 
Linked list
Linked listLinked list
Linked list
 
Balanced Tree (AVL Tree & Red-Black Tree)
Balanced Tree (AVL Tree & Red-Black Tree)Balanced Tree (AVL Tree & Red-Black Tree)
Balanced Tree (AVL Tree & Red-Black Tree)
 
Data Structures with C Linked List
Data Structures with C Linked ListData Structures with C Linked List
Data Structures with C Linked List
 
Linked List
Linked ListLinked List
Linked List
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
 
Binary trees
Binary treesBinary trees
Binary trees
 
sorting and its types
sorting and its typessorting and its types
sorting and its types
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
Linked list
Linked listLinked list
Linked list
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Heaps
HeapsHeaps
Heaps
 
linked list
linked list linked list
linked list
 

Viewers also liked

Array 2
Array 2Array 2
Array 2Abbott
 
Array data structure
Array data structureArray data structure
Array data structuremaamir 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
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithmsmultimedia9
 
Data Structures - Searching & sorting
Data Structures - Searching & sortingData Structures - Searching & sorting
Data Structures - Searching & sortingKaushal 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 Patilwidespreadpromotion
 
Circular linked list
Circular linked listCircular linked list
Circular linked listdchuynh
 
List Data Structure
List Data StructureList Data Structure
List Data StructureZidny 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 jyothiSowmya 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
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListManishPrajapati78
 
ds 4Linked lists.ppt
ds 4Linked lists.pptds 4Linked lists.ppt
ds 4Linked lists.pptAlliVinay1
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked listsAbdullah Al-hazmy
 
Linked List Presentation in data structurepptx
Linked List Presentation in data structurepptxLinked List Presentation in data structurepptx
Linked List Presentation in data structurepptxnikhilcse1
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked listSumathi 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.pptxJoannahClaireAlforqu
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)Durga Devi
 
Linked list and its operations - Traversal
Linked list and its operations - TraversalLinked list and its operations - Traversal
Linked list and its operations - Traversalkasthurimukila
 

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
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
 
linked-list.ppt
linked-list.pptlinked-list.ppt
linked-list.ppt
 
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.