SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Linked List outline

•   Why linked lists
•   Linked lists
•   Representation of Linked lists in memory
•   Traversing a linked lists
•   Memory allocation: Garbage collection
•   Overflow and Underflow
•   Basic operations of linked lists
     – Insert, find, delete, print, etc.
•   Variations of linked lists
     – Circular linked lists
     – Doubly linked lists
Lecture – 5
     on
Data Structure

  Linked Lists
Why linked lists

•   Disadvantages of arrays as storage data structures:
     – Slow insertion in ordered array
     – Contiguous Size is required
     – Inefficient usage of Memory
•   Linked lists solve some of these problems
•   Linked lists are general purpose storage data structures.
Linked lists
   •A linked list, or one way list, is a linear collection of data elements, called
   nodes, where the linear order is given by means of pointers.
   •Each node is divided into two parts:
   •The first part contains the information of the element, and
   •The second part, called the link field or next pointer field, contains the
   address of the next node in the list.
   •The pointer of the last node contains a special value,called the null pointer.
   •A pointer variable – called START which contains the address of the first
   node.
   •A special case is the list that has no nodes, such a list is called the null list
   or empty list and is denoted by the null pointer in the variable START.

Start
           node                      node                      node
            Data Next                 Data Next                 Data

                           Linked list with 3 nodes
                                                               node
                                                                          A

                                                                         data   pointer
linked lists

•A linked list organizes a collection of data items (elements ) such that elements
can easily be added to and deleted from any position in the list.
•Only references To next elements are updated in insertion and deletion
operations.
•There is no need to copy or move large blocks of data to facilitate insertion and
deletion of elements.
•Lists grow dynamically.
Representation of Linked lists in memory

            INFO   LINK
        1
START                     START=3, INFO[3]=45
        2   67     5      LINK[3]=2, INFO[2]=67
 3
        3   45     2      LINK[2]=5, INFO[5]=75

            80     7      LINK[5]=4, INFO[4]=80
        4
                          LINK[4]=7, INFO[7]=90
        5   75     4
                          LINK[7]=0, NULL value, So the list has ended
        6

        7   90     0

        8
Traversing a linked lists
LIST be a linked list in memory stored in linear arrays INFO and LINK with START
pointing to the first element and NULL indicating the end of LIST.
We want to traverse LIST in order to process each node exactly once.
Pointer variable PTR points to the node that is currently being processed.
LINK[PTR] points to the next node to be processed.
Thus update PTR by the assignment
                  PTR : =LINK[PTR]
                                                 PTR



                                    START               INFO LINK
                                                                             X


                                             Fig : PTR : = LINK[PTR]
Traversing a linked lists
For printing the information at each node of a linked list, must traverse the list.
Algorithm 5.1 : PRINT(INFO, LINK, START)
             Algorithm Prints the information at each node of the list.


              1. Set PTR : =START.
              2. Repeat steps 3 and 4 while PTR : ≠ NULL:
              3. Write : INFO[PTR].
              4. Set PTR : =LINK[PTR].
              5. Exit.
Traversing a linked lists
For Finding the number NUM of elements in a linked list, must traverse the list.
Algorithm 5.1 : COUNT(INFO, LINK, START, NUM)


             1. Set NUM: =0.
             2. . Set PTR : =START.
             3. Repeat steps 4 and 5 while PTR : ≠ NULL:
             4. Set NUM : =NUM+1.
             5. Set PTR : =LINK[PTR].
             6. Exit.
Memory allocation: Garbage collection
•   Memory space can be reused if a node is deleted from a list
     – i.e deleted node can be made available for future use
•   The operating system of a computer may periodically collect all the deleted space
    on to the free storage list. Any technique which does this collection called garbage
    collection




                                                                          Periodic
                                                                          Collector
       Computer
       programs                       Garbage                                      Sent to
                                  (Deleted Space)
                                                                                   avail list

          Takes
          space                                            …
          avail list                       Avail List (Free space)
Overflow and Underflow
•   Overflow:
     – Sometimes data are inserted into a data structure but there is no
       available space.
     – This situation is called overflow
     – Example: In linked list overflow occurs when
         • AVAIL= NULL and
         • There is an insertion operation
•   Underflow:
     – Situation:
         • Want to delete data from data structure that is empty.
     – Example: In linked list overflow occurs when
         • START = NULL and
         • There is an deletion operation
Insertion into a linked list
•    Node N is to be inserted in to the list between nodes A and B
•    Three pointer fields are changed as follows:
1.   The next pointer field of node A now points to the new node N, to which AVAIL previously
     pointed.
2.   AVAIL now point to the second node in the free pool, to which node N previously pointed.
3.   The next pointer field of node N now points to node B, to which node A previously pointed.
        START

                                           Node          Node
                                           A             B
      START
                                 (a) Before insertion
                                         Node               Node
                                         A                  B


     AVAIL                (a) After insertion
                   Node N                         Node N




                                                                 Free storage list
Inserting a new node

•   Possible cases of Insert Node

    1.   Insert into an empty list
    2.   Insert in front
    3.   Insert at back
    4.   Insert in middle

•   But, in fact, only need to handle two cases:

    1.   Insert as the first node (Case 1 and Case 2)
    2.   Insert in the middle or at the end of the list (Case 3 and Case 4)
Inserting a new node



INSLOC(INFO, LINK, START, AVAIL, LOC, ITEM)

1. [OVERFLOW?] If AVAIL=NULL, then print OVERFLOW and exit

2. Set NEW= AVAIL and AVAIL=LINK[AVAIL]

3. Set INFO[NEW]= ITEM
                                                        Check for available
                                                            memory
4. IF LOC = NULL then [Insert as first Node]
   Set LINK[NEW]= START and START=NEW.

 Else: [Insert after node with location LOC]
   Set LINK[NEW]= LINK [LOC] and LINK[LOC]= NEW

5. Exit.
Inserting a new node



INSLOC(INFO, LINK, START, AVAIL, LOC, ITEM)

1. [OVERFLOW?] If AVAIL=NULL, then print OVERFLOW and exit

2. Set NEW= AVAIL and AVAIL=LINK[AVAIL]

3. Set INFO[NEW]= ITEM

4. IF LOC = NULL then [Insert as first Node]
   Set LINK[]= START and START=NEW.
                                                  Create a new node
  Else: [Insert after node with location LOC]
   Set LINK[NEW]= LINK [LOC] and LINK[LOC]= NEW

5. Exit.
Inserting a new node



INSLOC(INFO, LINK, START, AVAIL, LOC, ITEM)

1. [OVERFLOW?] If AVAIL=NULL, then print OVERFLOW and exit

2. Set NEW= AVAIL and AVAIL=LINK[AVAIL]

3. Set INFO[NEW]= ITEM
                                                         Insert as first element
4. IF LOC = NULL then [Insert as first Node]
        Set LINK[NEW]= START and START=NEW.                        START

   Else: [Insert after node with location LOC]
          Set LINK[NEW]= LINK [LOC] and LINK[LOC]= NEW

5. Exit.                                                               NEW
Inserting a new node


INSLOC(INFO, LINK, START, AVAIL, LOC, ITEM)

1. [OVERFLOW?] If AVAIL=NULL, then print OVERFLOW and exit

2. Set NEW= AVAIL and AVAIL=LINK[AVAIL]

3. Set INFO[NEW]= ITEM

4. IF LOC = NULL then [Insert as first Node]
        Set LINK[NEW]= START and START=NEW.    Insert after currNode
                                                        LOC
  Else: [Insert after node with location LOC]
       Set LINK[NEW]= LINK [LOC] and LINK[LOC]= NEW

5. Exit.

                                                              NEW

Weitere ähnliche Inhalte

Was ist angesagt?

trees in data structure
trees in data structure trees in data structure
trees in data structure shameen khan
 
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]Muhammad Hammad Waseem
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data StructureMeghaj Mallick
 
Introduction to data structure ppt
Introduction to data structure pptIntroduction to data structure ppt
Introduction to data structure pptNalinNishant3
 
Database architecture
Database architectureDatabase architecture
Database architectureVENNILAV6
 
358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10sumitbardhan
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applicationsJsaddam Hussain
 
Stack data structure
Stack data structureStack data structure
Stack data structureTech_MX
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data StructureDharita Chokshi
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - NotesOmprakash Chauhan
 
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListPTCL
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data StructureMeghaj Mallick
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stackvaibhav2910
 

Was ist angesagt? (20)

trees in data structure
trees in data structure trees in data structure
trees in data structure
 
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]
 
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
 
Introduction to data structure ppt
Introduction to data structure pptIntroduction to data structure ppt
Introduction to data structure ppt
 
Database architecture
Database architectureDatabase architecture
Database architecture
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10
 
Linked List
Linked ListLinked List
Linked List
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
 
Stack data structure
Stack data structureStack data structure
Stack 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
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
Stack
StackStack
Stack
 
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked List
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
Shell sort
Shell sortShell sort
Shell sort
 
Arrays
ArraysArrays
Arrays
 

Ähnlich wie 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 jyothiSowmya Jyothi
 
Unit 2 linked list and queues
Unit 2   linked list and queuesUnit 2   linked list and queues
Unit 2 linked list and queueskalyanineve
 
Linked list
Linked listLinked list
Linked listVONI
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)Durga Devi
 
Linked List Presentation in data structurepptx
Linked List Presentation in data structurepptxLinked List Presentation in data structurepptx
Linked List Presentation in data structurepptxnikhilcse1
 
Linked list using Dynamic Memory Allocation
Linked list using Dynamic Memory AllocationLinked list using Dynamic Memory Allocation
Linked list using Dynamic Memory Allocationkiran Patel
 
Funddamentals of data structures
Funddamentals of data structuresFunddamentals of data structures
Funddamentals of data structuresGlobalidiots
 
DS Module 03.pdf
DS Module 03.pdfDS Module 03.pdf
DS Module 03.pdfSonaPathak5
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked ListsAfaq Mansoor Khan
 
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 queuessuser7319f8
 
Arrays and linked lists
Arrays and linked listsArrays and linked lists
Arrays and linked listsAfriyieCharles
 
cp264_lecture13_14_linkedlist.ppt
cp264_lecture13_14_linkedlist.pptcp264_lecture13_14_linkedlist.ppt
cp264_lecture13_14_linkedlist.pptssuser9dd05f
 

Ähnlich wie Data structure lecture 5 (20)

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
 
5.Linked list
5.Linked list 5.Linked list
5.Linked list
 
DSModule2.pptx
DSModule2.pptxDSModule2.pptx
DSModule2.pptx
 
Unit 2 linked list and queues
Unit 2   linked list and queuesUnit 2   linked list and queues
Unit 2 linked list and queues
 
Linked list
Linked listLinked list
Linked list
 
unit 2- PPT.pdf
unit 2- PPT.pdfunit 2- PPT.pdf
unit 2- PPT.pdf
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
 
Dounly linked list
Dounly linked listDounly linked list
Dounly linked list
 
Linked List Presentation in data structurepptx
Linked List Presentation in data structurepptxLinked List Presentation in data structurepptx
Linked List Presentation in data structurepptx
 
Linklist
LinklistLinklist
Linklist
 
Linked list using Dynamic Memory Allocation
Linked list using Dynamic Memory AllocationLinked list using Dynamic Memory Allocation
Linked list using Dynamic Memory Allocation
 
Funddamentals of data structures
Funddamentals of data structuresFunddamentals of data structures
Funddamentals of data structures
 
Linked list
Linked listLinked list
Linked list
 
DS Module 03.pdf
DS Module 03.pdfDS Module 03.pdf
DS Module 03.pdf
 
Singly linked list
Singly linked listSingly linked list
Singly linked list
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
 
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
 
Arrays and linked lists
Arrays and linked listsArrays and linked lists
Arrays and linked lists
 
cp264_lecture13_14_linkedlist.ppt
cp264_lecture13_14_linkedlist.pptcp264_lecture13_14_linkedlist.ppt
cp264_lecture13_14_linkedlist.ppt
 

Mehr von Kumar

Graphics devices
Graphics devicesGraphics devices
Graphics devicesKumar
 
Fill area algorithms
Fill area algorithmsFill area algorithms
Fill area algorithmsKumar
 
region-filling
region-fillingregion-filling
region-fillingKumar
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivationKumar
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons dericationKumar
 
Introductionto xslt
Introductionto xsltIntroductionto xslt
Introductionto xsltKumar
 
Extracting data from xml
Extracting data from xmlExtracting data from xml
Extracting data from xmlKumar
 
Xml basics
Xml basicsXml basics
Xml basicsKumar
 
XML Schema
XML SchemaXML Schema
XML SchemaKumar
 
Publishing xml
Publishing xmlPublishing xml
Publishing xmlKumar
 
Applying xml
Applying xmlApplying xml
Applying xmlKumar
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XMLKumar
 
How to deploy a j2ee application
How to deploy a j2ee applicationHow to deploy a j2ee application
How to deploy a j2ee applicationKumar
 
JNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLJNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLKumar
 
EJB Fundmentals
EJB FundmentalsEJB Fundmentals
EJB FundmentalsKumar
 
JSP and struts programming
JSP and struts programmingJSP and struts programming
JSP and struts programmingKumar
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programmingKumar
 
Introduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversIntroduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversKumar
 
Introduction to J2EE
Introduction to J2EEIntroduction to J2EE
Introduction to J2EEKumar
 

Mehr von Kumar (20)

Graphics devices
Graphics devicesGraphics devices
Graphics devices
 
Fill area algorithms
Fill area algorithmsFill area algorithms
Fill area algorithms
 
region-filling
region-fillingregion-filling
region-filling
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivation
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons derication
 
Introductionto xslt
Introductionto xsltIntroductionto xslt
Introductionto xslt
 
Extracting data from xml
Extracting data from xmlExtracting data from xml
Extracting data from xml
 
Xml basics
Xml basicsXml basics
Xml basics
 
XML Schema
XML SchemaXML Schema
XML Schema
 
Publishing xml
Publishing xmlPublishing xml
Publishing xml
 
DTD
DTDDTD
DTD
 
Applying xml
Applying xmlApplying xml
Applying xml
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
How to deploy a j2ee application
How to deploy a j2ee applicationHow to deploy a j2ee application
How to deploy a j2ee application
 
JNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLJNDI, JMS, JPA, XML
JNDI, JMS, JPA, XML
 
EJB Fundmentals
EJB FundmentalsEJB Fundmentals
EJB Fundmentals
 
JSP and struts programming
JSP and struts programmingJSP and struts programming
JSP and struts programming
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programming
 
Introduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversIntroduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC Drivers
 
Introduction to J2EE
Introduction to J2EEIntroduction to J2EE
Introduction to J2EE
 

Kürzlich hochgeladen

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 

Kürzlich hochgeladen (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

Data structure lecture 5

  • 1. Linked List outline • Why linked lists • Linked lists • Representation of Linked lists in memory • Traversing a linked lists • Memory allocation: Garbage collection • Overflow and Underflow • Basic operations of linked lists – Insert, find, delete, print, etc. • Variations of linked lists – Circular linked lists – Doubly linked lists
  • 2. Lecture – 5 on Data Structure Linked Lists
  • 3. Why linked lists • Disadvantages of arrays as storage data structures: – Slow insertion in ordered array – Contiguous Size is required – Inefficient usage of Memory • Linked lists solve some of these problems • Linked lists are general purpose storage data structures.
  • 4. Linked lists •A linked list, or one way list, is a linear collection of data elements, called nodes, where the linear order is given by means of pointers. •Each node is divided into two parts: •The first part contains the information of the element, and •The second part, called the link field or next pointer field, contains the address of the next node in the list. •The pointer of the last node contains a special value,called the null pointer. •A pointer variable – called START which contains the address of the first node. •A special case is the list that has no nodes, such a list is called the null list or empty list and is denoted by the null pointer in the variable START. Start node node node Data Next Data Next Data Linked list with 3 nodes node A data pointer
  • 5. linked lists •A linked list organizes a collection of data items (elements ) such that elements can easily be added to and deleted from any position in the list. •Only references To next elements are updated in insertion and deletion operations. •There is no need to copy or move large blocks of data to facilitate insertion and deletion of elements. •Lists grow dynamically.
  • 6. Representation of Linked lists in memory INFO LINK 1 START START=3, INFO[3]=45 2 67 5 LINK[3]=2, INFO[2]=67 3 3 45 2 LINK[2]=5, INFO[5]=75 80 7 LINK[5]=4, INFO[4]=80 4 LINK[4]=7, INFO[7]=90 5 75 4 LINK[7]=0, NULL value, So the list has ended 6 7 90 0 8
  • 7. Traversing a linked lists LIST be a linked list in memory stored in linear arrays INFO and LINK with START pointing to the first element and NULL indicating the end of LIST. We want to traverse LIST in order to process each node exactly once. Pointer variable PTR points to the node that is currently being processed. LINK[PTR] points to the next node to be processed. Thus update PTR by the assignment PTR : =LINK[PTR] PTR START INFO LINK X Fig : PTR : = LINK[PTR]
  • 8. Traversing a linked lists For printing the information at each node of a linked list, must traverse the list. Algorithm 5.1 : PRINT(INFO, LINK, START) Algorithm Prints the information at each node of the list. 1. Set PTR : =START. 2. Repeat steps 3 and 4 while PTR : ≠ NULL: 3. Write : INFO[PTR]. 4. Set PTR : =LINK[PTR]. 5. Exit.
  • 9. Traversing a linked lists For Finding the number NUM of elements in a linked list, must traverse the list. Algorithm 5.1 : COUNT(INFO, LINK, START, NUM) 1. Set NUM: =0. 2. . Set PTR : =START. 3. Repeat steps 4 and 5 while PTR : ≠ NULL: 4. Set NUM : =NUM+1. 5. Set PTR : =LINK[PTR]. 6. Exit.
  • 10. Memory allocation: Garbage collection • Memory space can be reused if a node is deleted from a list – i.e deleted node can be made available for future use • The operating system of a computer may periodically collect all the deleted space on to the free storage list. Any technique which does this collection called garbage collection Periodic Collector Computer programs Garbage Sent to (Deleted Space) avail list Takes space … avail list Avail List (Free space)
  • 11. Overflow and Underflow • Overflow: – Sometimes data are inserted into a data structure but there is no available space. – This situation is called overflow – Example: In linked list overflow occurs when • AVAIL= NULL and • There is an insertion operation • Underflow: – Situation: • Want to delete data from data structure that is empty. – Example: In linked list overflow occurs when • START = NULL and • There is an deletion operation
  • 12. Insertion into a linked list • Node N is to be inserted in to the list between nodes A and B • Three pointer fields are changed as follows: 1. The next pointer field of node A now points to the new node N, to which AVAIL previously pointed. 2. AVAIL now point to the second node in the free pool, to which node N previously pointed. 3. The next pointer field of node N now points to node B, to which node A previously pointed. START Node Node A B START (a) Before insertion Node Node A B AVAIL (a) After insertion Node N Node N Free storage list
  • 13. Inserting a new node • Possible cases of Insert Node 1. Insert into an empty list 2. Insert in front 3. Insert at back 4. Insert in middle • But, in fact, only need to handle two cases: 1. Insert as the first node (Case 1 and Case 2) 2. Insert in the middle or at the end of the list (Case 3 and Case 4)
  • 14. Inserting a new node INSLOC(INFO, LINK, START, AVAIL, LOC, ITEM) 1. [OVERFLOW?] If AVAIL=NULL, then print OVERFLOW and exit 2. Set NEW= AVAIL and AVAIL=LINK[AVAIL] 3. Set INFO[NEW]= ITEM Check for available memory 4. IF LOC = NULL then [Insert as first Node] Set LINK[NEW]= START and START=NEW. Else: [Insert after node with location LOC] Set LINK[NEW]= LINK [LOC] and LINK[LOC]= NEW 5. Exit.
  • 15. Inserting a new node INSLOC(INFO, LINK, START, AVAIL, LOC, ITEM) 1. [OVERFLOW?] If AVAIL=NULL, then print OVERFLOW and exit 2. Set NEW= AVAIL and AVAIL=LINK[AVAIL] 3. Set INFO[NEW]= ITEM 4. IF LOC = NULL then [Insert as first Node] Set LINK[]= START and START=NEW. Create a new node Else: [Insert after node with location LOC] Set LINK[NEW]= LINK [LOC] and LINK[LOC]= NEW 5. Exit.
  • 16. Inserting a new node INSLOC(INFO, LINK, START, AVAIL, LOC, ITEM) 1. [OVERFLOW?] If AVAIL=NULL, then print OVERFLOW and exit 2. Set NEW= AVAIL and AVAIL=LINK[AVAIL] 3. Set INFO[NEW]= ITEM Insert as first element 4. IF LOC = NULL then [Insert as first Node] Set LINK[NEW]= START and START=NEW. START Else: [Insert after node with location LOC] Set LINK[NEW]= LINK [LOC] and LINK[LOC]= NEW 5. Exit. NEW
  • 17. Inserting a new node INSLOC(INFO, LINK, START, AVAIL, LOC, ITEM) 1. [OVERFLOW?] If AVAIL=NULL, then print OVERFLOW and exit 2. Set NEW= AVAIL and AVAIL=LINK[AVAIL] 3. Set INFO[NEW]= ITEM 4. IF LOC = NULL then [Insert as first Node] Set LINK[NEW]= START and START=NEW. Insert after currNode LOC Else: [Insert after node with location LOC] Set LINK[NEW]= LINK [LOC] and LINK[LOC]= NEW 5. Exit. NEW