SlideShare a Scribd company logo
List ADT
   List is an ordered collection of items. Items in the
    collection may be integers, Strings, characters or
    any kind of objects.

   Basic operations are
       Adding an item to the collection
       Deleting an item from the collection
       Testing if list is empty
       Testing if list is full
       Getting an item on specified location
       Getting an item with specified key value
Linked List
   Collection of links with reference to the first.

   Each link has
       part to store data
       link that refers to the next link in the list.


   Data part of the link can be an integer, a character, a
    String or an object of any kind.
Linked Lists
   A linked list is a linear collection of data elements called nodes
    where linear order is given by means of pointers.
   Each node has two parts
    1) Data Field – Stores data of the node
    2) Link Field – Store address of the next node
                         ( i.e. Link to the next node)



                                          LINK



             NODE    :

                            DATA
Linked Lists
         -START is List pointer contains address of the first node in
         the List
         -   All nodes are connected to each other through Link fields
         -   Link of the last node is NULL pointer denoted by ‘X’ sign
         -   Null pointer indicated end of the list
start




                data link     datalink      datalink   Data link
                                                                  

                                                                     x




                  A              B              C            D
Algorithms


     Lets consider,

•   START is the 1st position in Linked List
•   NewNode is the new node to be created
•   DATA is the element to be inserted in new node
•   POS is the position where the new node to be inserted
•   TEMP and HOLD are temporary pointers to hold the
    node address
Algorithm to Insert a Node at the beginning


   1.      Input DATA to be inserted
   2.      Create NewNode
   3.      NewNode -> DATA = DATA
   4.      If START is equal to NULL
           a) NewNode -> LINK = NULL
   5.      Else
           a) NewNode -> LINK = START
   6.      START = NewNode
   7.      Exit
Insert a Node at the beginning



start




                    datalink    datalink   data link
                                                   

     NewNode
                                                     x
Algorithm to Insert a Node at the end
1.   Input DATA to be inserted
2.   Create NewNode
3.   NewNode -> DATA = DATA
4.   NewNode -> LINK = NULL
5.   If START is equal to NULL
                   a) START = NewNode
    6.      Else
                   a) TEMP = START
                   b) while (TEMP -> LINK not equal to
     NULL)
                          i) TEMP = TEMP -> LINK
    7.      TEMP -> Link = NewNode
    8. Exit
Insert a Node at the end

start




         data link   datalink   datalink   NewNode

                                                       X




           A           B           C           P
Algorithm to Insert a Node at any specified position

1.   Input DATA to be inserted and POS, the position to be
     inserted.
2.   Initialize TEMP = START and K=1
3.   Repeat step 3 while ( K is less than POS)
               a) TEMP = TEMP -> LINK
               b) If TEMP -> LINK = NULL
                       i) Exit
               c) K = K + 1
    4. Create a Newnode
    5. Newnode -> DATA = DATA
    6. Newnode -> LINK = TEMP -> LINK
    7. TEMP -> LINK = NewNode
    8. Exit
Insert a Node at middle position
start          Lets   consider, POS = 3


          1              2                    3          4

     data link    datalink              datalink   data link
                                                             

                                                                 x


                                                C

         A             B                                D
                                 NewNode




                                    P
Algorithm to Delete a Node

   1. Input DATA to be deleted
   2. If START is equal to DATA
                  a) TEMP = START
                  b) START = START -> LINK
                  c) Set free node TEMP - which is
    deleted
                  d) Exit
   3. HOLD = START
   4. While ((HOLD -> LINK ->LINK) not equal to NULL)
    a) If(HOLD -> LINK ->DATA) equal to DATA
                  i) TEMP = HOLD -> LINK
                  ii) HOLD -> LINK = TEMP -> LINK
                  iii) Set free node TEMP - which is
    deleted
                  iv) Exit
    b) HOLD = HOLD -> NEXT
Algorithm to Delete a Node

   5. If(HOLD -> LINK ->DATA) equal to DATA
    i) TEMP = HOLD -> LINK
    ii) Set free node TEMP - which is deleted
    iii) HOLD -> LINK = NULL
    iv) Exit
   6. Display DATA not found
   7. Exit
Algorithm to Delete a Node


                       Node  to be
start                   deleted



         data link   datalink     datalink   data link
                                                       

                                                         x




          A            B             C           D
Algorithm for Searching a Node

    Suppose START is the address of the first node in the linked list and DATA
     is the informSation to be searched.
1.   Input the DATA to be searched.
2.   Initialize TEMP = START and Pos =1
3.   Repeat the step 4,5 and 6 until (TEMP is equal to NULL)
4.   If (TEMP -> DATA is equal to DATA)
           (a) Display “The DATA found at POS “
           (b) Exit
    5. TEMP = TEMP -> LINK
    6. POS = POS + 1
    7. If (TEMP is equal to NULL)
         (a) Display “ The DATA is not found in the list”
    8. Exit.
Algorithm for Displaying all Nodes

    Suppose List is the address of the first node in the linked list.
1.   If ( START is equal to NULL)
           ( a ) Display “The List is Empty”
           ( b ) Exit
2.   Initialize TEMP = START
3.   Repeat the Step 4 and 5 until (TEMP == NULL)
4.   Display TEMP -> DATA
5.   TEMP = TEMP -> LINK
6.   Exit
Singly Linked Lists and Arrays


         Singly linked list                   Array
  Elements are stored in linear   Elements are stored in linear
  order, accessible with links.   order, accessible with an
                                  index.

  Do not have a fixed size.       Have a fixed size.

  Cannot access the previous      Can access the previous
  element directly.               element easily.
Doubly Linked List

    A doubly linked list is often more     prev           next
     convenient!
    Nodes store:
        element
        link to the previous node
                                                    elem    node
        link to the next node
    Special trailer and header nodes

header                                   nodes/positionstrailer




                                                elements
Insertion

    We visualize operation insertAfter(p, X), which returns position q
                              p


                  A            B            C

                              p


                  A            B                 q       C

                                              X
                              p            q


                  A            B            X            C
Deletion

    We visualize remove(p), where p == last()
                                                 p



                A         B         C          D



                A         B         C         p



                                                  D



                A         B         C

More Related Content

What's hot

10 Linked Lists Sacks and Queues
10 Linked Lists Sacks and Queues10 Linked Lists Sacks and Queues
10 Linked Lists Sacks and Queues
Praveen M Jigajinni
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
DurgaDeviCbit
 
Lecture 6: linked list
Lecture 6:  linked listLecture 6:  linked list
Lecture 6: linked list
Vivek Bhargav
 
Ch03
Ch03Ch03
Ch03
Hankyo
 
Ch06
Ch06Ch06
Ch06
Hankyo
 
linked list
linked listlinked list
linked list
Abbott
 
Rana Junaid Rasheed
Rana Junaid RasheedRana Junaid Rasheed
Rana Junaid Rasheed
Rana junaid Rasheed
 
Stacks & Queues
Stacks & QueuesStacks & Queues
Stacks & Queues
tech4us
 
Data structure lecture7
Data structure lecture7Data structure lecture7
Data structure lecture7
Kumar
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
bca2010
 
Stacks and queues
Stacks and queuesStacks and queues
Stacks and queues
Trupti Agrawal
 
Csc1100 lecture07 ch07_pt1-1
Csc1100 lecture07 ch07_pt1-1Csc1100 lecture07 ch07_pt1-1
Csc1100 lecture07 ch07_pt1-1
IIUM
 
LISP: Introduction to lisp
LISP: Introduction to lispLISP: Introduction to lisp
LISP: Introduction to lisp
DataminingTools Inc
 
Heaps & priority queues
Heaps & priority queuesHeaps & priority queues
Heaps & priority queues
Pedro Hugo Valencia Morales
 
LR Parsing
LR ParsingLR Parsing
LR Parsing
Eelco Visser
 
Ch04
Ch04Ch04
Ch04
Hankyo
 
Lec3
Lec3Lec3
Python lecture 07
Python lecture 07Python lecture 07
Python lecture 07
Tanwir Zaman
 
Lisp tutorial
Lisp tutorialLisp tutorial
Lisp tutorial
Nilt1234
 
Csc1100 lecture12 ch08_pt2
Csc1100 lecture12 ch08_pt2Csc1100 lecture12 ch08_pt2
Csc1100 lecture12 ch08_pt2
IIUM
 

What's hot (20)

10 Linked Lists Sacks and Queues
10 Linked Lists Sacks and Queues10 Linked Lists Sacks and Queues
10 Linked Lists Sacks and Queues
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
Lecture 6: linked list
Lecture 6:  linked listLecture 6:  linked list
Lecture 6: linked list
 
Ch03
Ch03Ch03
Ch03
 
Ch06
Ch06Ch06
Ch06
 
linked list
linked listlinked list
linked list
 
Rana Junaid Rasheed
Rana Junaid RasheedRana Junaid Rasheed
Rana Junaid Rasheed
 
Stacks & Queues
Stacks & QueuesStacks & Queues
Stacks & Queues
 
Data structure lecture7
Data structure lecture7Data structure lecture7
Data structure lecture7
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 
Stacks and queues
Stacks and queuesStacks and queues
Stacks and queues
 
Csc1100 lecture07 ch07_pt1-1
Csc1100 lecture07 ch07_pt1-1Csc1100 lecture07 ch07_pt1-1
Csc1100 lecture07 ch07_pt1-1
 
LISP: Introduction to lisp
LISP: Introduction to lispLISP: Introduction to lisp
LISP: Introduction to lisp
 
Heaps & priority queues
Heaps & priority queuesHeaps & priority queues
Heaps & priority queues
 
LR Parsing
LR ParsingLR Parsing
LR Parsing
 
Ch04
Ch04Ch04
Ch04
 
Lec3
Lec3Lec3
Lec3
 
Python lecture 07
Python lecture 07Python lecture 07
Python lecture 07
 
Lisp tutorial
Lisp tutorialLisp tutorial
Lisp tutorial
 
Csc1100 lecture12 ch08_pt2
Csc1100 lecture12 ch08_pt2Csc1100 lecture12 ch08_pt2
Csc1100 lecture12 ch08_pt2
 

Similar to U2.linked list

Singly link list
Singly link listSingly link list
Singly link list
Rojin Khadka
 
Linked lists a
Linked lists aLinked lists a
Linked lists a
Khuram Shahzad
 
Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queue
ssuser7319f8
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
Afaq Mansoor Khan
 
DSModule2.pptx
DSModule2.pptxDSModule2.pptx
DSModule2.pptx
ChrisSosaJacob
 
linkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxlinkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptx
MeghaKulkarni27
 
Linked List.pptx
Linked List.pptxLinked List.pptx
Linked List.pptx
PoonamPatil120
 
Stack - PPT Slides.pptx-data sturutures and algorithanms
Stack - PPT Slides.pptx-data sturutures and algorithanmsStack - PPT Slides.pptx-data sturutures and algorithanms
Stack - PPT Slides.pptx-data sturutures and algorithanms
AdithaBuwaneka
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
JAGDEEPKUMAR23
 
DS Unit 2.ppt
DS Unit 2.pptDS Unit 2.ppt
DS Unit 2.ppt
JITTAYASHWANTHREDDY
 
Algo>ADT list & linked list
Algo>ADT list & linked listAlgo>ADT list & linked list
Algo>ADT list & linked list
Ain-ul-Moiz Khawaja
 
Linear data structure concepts
Linear data structure conceptsLinear data structure concepts
Linear data structure concepts
Akila Krishnamoorthy
 
Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)
Adam Mukharil Bachtiar
 
Data structures linked list introduction.pptx
Data structures linked list introduction.pptxData structures linked list introduction.pptx
Data structures linked list introduction.pptx
Kalpana Mohan
 
Chap 4 List of Data Structure.ppt
Chap 4 List of Data Structure.pptChap 4 List of Data Structure.ppt
Chap 4 List of Data Structure.ppt
shashankbhadouria4
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
Sumathi Kv
 
03-Lists.ppt
03-Lists.ppt03-Lists.ppt
03-Lists.ppt
huynguyen556776
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
Dabbal Singh Mahara
 
Unit - 2.pdf
Unit - 2.pdfUnit - 2.pdf
Unit - 2.pdf
AravindAnand21
 
Data structure
Data structureData structure
Data structure
Nida Ahmed
 

Similar to U2.linked list (20)

Singly link list
Singly link listSingly link list
Singly link list
 
Linked lists a
Linked lists aLinked lists a
Linked lists a
 
Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queue
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
 
DSModule2.pptx
DSModule2.pptxDSModule2.pptx
DSModule2.pptx
 
linkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxlinkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptx
 
Linked List.pptx
Linked List.pptxLinked List.pptx
Linked List.pptx
 
Stack - PPT Slides.pptx-data sturutures and algorithanms
Stack - PPT Slides.pptx-data sturutures and algorithanmsStack - PPT Slides.pptx-data sturutures and algorithanms
Stack - PPT Slides.pptx-data sturutures and algorithanms
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
DS Unit 2.ppt
DS Unit 2.pptDS Unit 2.ppt
DS Unit 2.ppt
 
Algo>ADT list & linked list
Algo>ADT list & linked listAlgo>ADT list & linked list
Algo>ADT list & linked list
 
Linear data structure concepts
Linear data structure conceptsLinear data structure concepts
Linear data structure concepts
 
Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)
 
Data structures linked list introduction.pptx
Data structures linked list introduction.pptxData structures linked list introduction.pptx
Data structures linked list introduction.pptx
 
Chap 4 List of Data Structure.ppt
Chap 4 List of Data Structure.pptChap 4 List of Data Structure.ppt
Chap 4 List of Data Structure.ppt
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
 
03-Lists.ppt
03-Lists.ppt03-Lists.ppt
03-Lists.ppt
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
 
Unit - 2.pdf
Unit - 2.pdfUnit - 2.pdf
Unit - 2.pdf
 
Data structure
Data structureData structure
Data structure
 

More from Ssankett Negi

Binary tree
Binary treeBinary tree
Binary tree
Ssankett Negi
 
Multi way&btree
Multi way&btreeMulti way&btree
Multi way&btree
Ssankett Negi
 
Heapsort
HeapsortHeapsort
Heapsort
Ssankett Negi
 
Binary trees
Binary treesBinary trees
Binary trees
Ssankett Negi
 
Threaded binarytree&heapsort
Threaded binarytree&heapsortThreaded binarytree&heapsort
Threaded binarytree&heapsort
Ssankett Negi
 
U3.stack queue
U3.stack queueU3.stack queue
U3.stack queue
Ssankett Negi
 
Stack prgs
Stack prgsStack prgs
Stack prgs
Ssankett Negi
 
Recursion
RecursionRecursion
Recursion
Ssankett Negi
 
Qprgs
QprgsQprgs
Circular queues
Circular queuesCircular queues
Circular queues
Ssankett Negi
 

More from Ssankett Negi (10)

Binary tree
Binary treeBinary tree
Binary tree
 
Multi way&btree
Multi way&btreeMulti way&btree
Multi way&btree
 
Heapsort
HeapsortHeapsort
Heapsort
 
Binary trees
Binary treesBinary trees
Binary trees
 
Threaded binarytree&heapsort
Threaded binarytree&heapsortThreaded binarytree&heapsort
Threaded binarytree&heapsort
 
U3.stack queue
U3.stack queueU3.stack queue
U3.stack queue
 
Stack prgs
Stack prgsStack prgs
Stack prgs
 
Recursion
RecursionRecursion
Recursion
 
Qprgs
QprgsQprgs
Qprgs
 
Circular queues
Circular queuesCircular queues
Circular queues
 

Recently uploaded

20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 

Recently uploaded (20)

20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 

U2.linked list

  • 1.
  • 2. List ADT  List is an ordered collection of items. Items in the collection may be integers, Strings, characters or any kind of objects.  Basic operations are  Adding an item to the collection  Deleting an item from the collection  Testing if list is empty  Testing if list is full  Getting an item on specified location  Getting an item with specified key value
  • 3. Linked List  Collection of links with reference to the first.   Each link has  part to store data  link that refers to the next link in the list.  Data part of the link can be an integer, a character, a String or an object of any kind.
  • 4. Linked Lists  A linked list is a linear collection of data elements called nodes where linear order is given by means of pointers.  Each node has two parts 1) Data Field – Stores data of the node 2) Link Field – Store address of the next node ( i.e. Link to the next node) LINK NODE : DATA
  • 5. Linked Lists -START is List pointer contains address of the first node in the List - All nodes are connected to each other through Link fields - Link of the last node is NULL pointer denoted by ‘X’ sign - Null pointer indicated end of the list start data link datalink datalink Data link  x A B C D
  • 6. Algorithms  Lets consider, • START is the 1st position in Linked List • NewNode is the new node to be created • DATA is the element to be inserted in new node • POS is the position where the new node to be inserted • TEMP and HOLD are temporary pointers to hold the node address
  • 7. Algorithm to Insert a Node at the beginning  1. Input DATA to be inserted  2. Create NewNode  3. NewNode -> DATA = DATA  4. If START is equal to NULL  a) NewNode -> LINK = NULL  5. Else  a) NewNode -> LINK = START  6. START = NewNode  7. Exit
  • 8. Insert a Node at the beginning start datalink datalink data link  NewNode x
  • 9. Algorithm to Insert a Node at the end 1. Input DATA to be inserted 2. Create NewNode 3. NewNode -> DATA = DATA 4. NewNode -> LINK = NULL 5. If START is equal to NULL  a) START = NewNode  6. Else  a) TEMP = START  b) while (TEMP -> LINK not equal to NULL)  i) TEMP = TEMP -> LINK  7. TEMP -> Link = NewNode  8. Exit
  • 10. Insert a Node at the end start data link datalink datalink NewNode X A B C P
  • 11. Algorithm to Insert a Node at any specified position 1. Input DATA to be inserted and POS, the position to be inserted. 2. Initialize TEMP = START and K=1 3. Repeat step 3 while ( K is less than POS)  a) TEMP = TEMP -> LINK  b) If TEMP -> LINK = NULL  i) Exit  c) K = K + 1  4. Create a Newnode  5. Newnode -> DATA = DATA  6. Newnode -> LINK = TEMP -> LINK  7. TEMP -> LINK = NewNode  8. Exit
  • 12. Insert a Node at middle position start Lets consider, POS = 3 1 2 3 4 data link datalink datalink data link  x C A B D NewNode P
  • 13. Algorithm to Delete a Node  1. Input DATA to be deleted  2. If START is equal to DATA  a) TEMP = START  b) START = START -> LINK  c) Set free node TEMP - which is deleted  d) Exit  3. HOLD = START  4. While ((HOLD -> LINK ->LINK) not equal to NULL)  a) If(HOLD -> LINK ->DATA) equal to DATA  i) TEMP = HOLD -> LINK  ii) HOLD -> LINK = TEMP -> LINK  iii) Set free node TEMP - which is deleted  iv) Exit  b) HOLD = HOLD -> NEXT
  • 14. Algorithm to Delete a Node  5. If(HOLD -> LINK ->DATA) equal to DATA  i) TEMP = HOLD -> LINK  ii) Set free node TEMP - which is deleted  iii) HOLD -> LINK = NULL  iv) Exit  6. Display DATA not found  7. Exit
  • 15. Algorithm to Delete a Node Node to be start deleted data link datalink datalink data link  x A B C D
  • 16. Algorithm for Searching a Node  Suppose START is the address of the first node in the linked list and DATA is the informSation to be searched. 1. Input the DATA to be searched. 2. Initialize TEMP = START and Pos =1 3. Repeat the step 4,5 and 6 until (TEMP is equal to NULL) 4. If (TEMP -> DATA is equal to DATA)  (a) Display “The DATA found at POS “  (b) Exit  5. TEMP = TEMP -> LINK  6. POS = POS + 1  7. If (TEMP is equal to NULL)  (a) Display “ The DATA is not found in the list”  8. Exit.
  • 17. Algorithm for Displaying all Nodes  Suppose List is the address of the first node in the linked list. 1. If ( START is equal to NULL)  ( a ) Display “The List is Empty”  ( b ) Exit 2. Initialize TEMP = START 3. Repeat the Step 4 and 5 until (TEMP == NULL) 4. Display TEMP -> DATA 5. TEMP = TEMP -> LINK 6. Exit
  • 18. Singly Linked Lists and Arrays Singly linked list Array Elements are stored in linear Elements are stored in linear order, accessible with links. order, accessible with an index. Do not have a fixed size. Have a fixed size. Cannot access the previous Can access the previous element directly. element easily.
  • 19. Doubly Linked List  A doubly linked list is often more prev next convenient!  Nodes store:  element  link to the previous node elem node  link to the next node  Special trailer and header nodes header nodes/positionstrailer elements
  • 20. Insertion  We visualize operation insertAfter(p, X), which returns position q p A B C p A B q C X p q A B X C
  • 21. Deletion  We visualize remove(p), where p == last() p A B C D A B C p D A B C