SlideShare a Scribd company logo
LINK LIST




  SHEETAL WAGHMARE
  M.TECH (Computer Science & Data Processing)
  IIT KHARAGPUR
  EMAIL-ID: shitu2iitkgp@gmail.com
            sheetalw3@gmail.com
Instruction To Use This Presentation
 Dear user I have kept some
  animated/executable/video files so it will be easy for
  you to understand but that wont be run/play in
  slideshow

 To see/run that files you have to exit from slideshow
  then click on the icon and also install KM Player

 For example: click on the below icons one by one(
  one is executable file and other is video) you will be
  able to see the animation



SHEETAL WAGHMARE   FROM IIT KHARAGPUR
CONTENTS

SINGLY LINKLIST (INSERTION,DELETION,SORT,SEARCH)
STACK(PUSH,POP)
QUEUE(ADD,REMOVE)
CIRCULAR LINKLIST
DOUBLE ENDED QUEUE
CIRCULAR QUEUE
PRIORITY QUEUE
DOUBLY LINKLIST(INSERTION,DELETION,SORT,SEARCH)



    SHEETAL WAGHMARE   FROM IIT
    KHARAGPUR
What’s wrong with Array and Why lists?
   Disadvantages of arrays as storage data structures:
     slow searching in unordered array
     slow insertion in ordered array
     Fixed size
   Linked lists solve some of these problems




  SHEETAL WAGHMARE   FROM IIT
  KHARAGPUR
List Implementation using Linked Lists
 Linked list
   Linear collection of self-referential class objects, called nodes
   Connected by pointer links
   Accessed via a pointer to the first node of the list
   Link pointer in the last node is set to null to mark the list’s end
 Use a linked list instead of an array when
   You have an unpredictable number of data elements
   You want to insert and delete quickly.




      SHEETAL WAGHMARE   FROM IIT
      KHARAGPUR
Linked Lists

                     A               B           C

         Head

 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
 Head: pointer to the first node                      node
 The last node points to NULL
                                                      A

     SHEETAL WAGHMARE    FROM IIT                    data     pointer
     KHARAGPUR
Part II: Linked Lists
As an abstract data type, a list is a finite sequence (possibly empty) of
elements with basic operations that vary from one application to
another.

Basic operations commonly include:

Construction:   Allocate and initialize a list object (usually empty)
Empty:          Check if list is empty
Insert:         Add an item to the list at any point
Delete:         Remove an item from the list at any point

Traverse:      Go through the list or a part of it, accessing and
processing theWAGHMARE in the order they are stored
       SHEETAL
               elements FROM IIT
       KHARAGPUR
Linked Representation
  Data structure for a linked list:


 first




           Node

          •Data
          •Link (pointer): used to store the address of the next node.




 SHEETAL WAGHMARE    FROM IIT
 KHARAGPUR
Anatomy of a linked list
 A linked list consists of:
    A sequence of nodes



  myList


                       a              b          c          d

     Each node contains a value
     and a link (pointer or reference) to some other node
     The last node contains a null link
     The list may (or may not) have a header
    SHEETAL WAGHMARE       FROM IIT
    KHARAGPUR
More terminology
 A node’s successor is the next node in the sequence
    The last node has no successor
 A node’s predecessor is the previous node in the sequence
    The first node has no predecessor
 A list’s length is the number of elements in it
    A list may be empty (contain no elements)




    SHEETAL WAGHMARE   FROM IIT
    KHARAGPUR
Linked Lists
 Types of linked lists:
   Singly linked list
      Begins with a pointer to the first node
      Terminates with a null pointer
      Only traversed in one direction
    Circular, singly linked
      Pointer in the last node points
       back to the first node
    Doubly linked list
      Two “start pointers” – first element and last element
      Each node has a forward pointer and a backward pointer
      Allows traversals both forwards and backwards
    Circular, doubly linked list
      Forward pointer of the last node points to the first node and backward pointer
       of the first node points to the last node
        SHEETAL WAGHMARE FROM IIT
         KHARAGPUR
Declarations
  First you must declare a data structure that will be used
   for the nodes. For example, the following struct could
   be used to create a list where each node holds a float:




  SHEETAL WAGHMARE   FROM IIT
  KHARAGPUR
Conventions of Linked List
There are several conventions for the link to indicate the end of
   the list.
1. A null link that points to no node (0 or NULL)
2. A dummy node that contains no item
3. A reference back to the first node, making it a circular list.




     SHEETAL WAGHMARE   FROM IIT
     KHARAGPUR
Convention of the linked list
 A special list is maintained which consists of unused memory
  cells. This list, which has its own pointer, is called the list of
  available space or the free storage list or the free pool.
 The operating system of a computer may periodically collect all
  the deleted space onto the free storage list. Any technique
  which does this collection is called garbage collection.




       SHEETAL WAGHMARE   FROM IIT
       KHARAGPUR
Conventions

 Sometimes new data are to be inserted into the data structure but
  there is no available space, i.e. the free storage list is empty. This
  situation is usually called overflow.
      means when AVAIL = NULL and there is an insertion.


 The term underflow refers to the situation where one wants to delete
  data from a data structure that is empty. The programmer may handle
  underflow by printing the message UNDERFLOW.
     means If START = NULL,



       SHEETAL WAGHMARE   FROM IIT
       KHARAGPUR
Inserting to the Front
head        93
         head              48   17        142




 There is no work to find the correct location
 Empty or not, head will point to the right location




  SHEETAL WAGHMARE   FROM IIT
  KHARAGPUR
Insert first position
   INFIRST(INFO,START,AVAIL,ITEM)
  1. [OVERFLOW] if AVAIL=NULL then write:OVERFLOW and exit.
  2. [remove first node from AVAIL list]
    set NEW=AVAIL and AVAIL=LINK[AVAIL].
  3. Set INFO[NEW]=ITEM [copies new data into new node]
  4. Set LINK[NEW]=START [new node now points to original first node]
  5. Set START=NEW [changes START so it points to the new node]
  6. Exit




  SHEETAL WAGHMARE   FROM IIT
  KHARAGPUR
Inserting to the Middle
head        17            48    142
                                 93
                                         //
                                          142
                                                 //



 Used when order is important
 Go to the node that should follow the one to
   add
    Recursion or iteration

  SHEETAL WAGHMARE   FROM IIT
  KHARAGPUR
Algorithm
 INSLOC[INFO,LINK,START,AVAIL,LOC,ITEM]
1. [OVERFLOW] if AVAIL=NULL then write OVERFLOW and exit.
2. [remove first node from AVAIL list]
       set NEW:=AVAIL and AVAIL:=LINK[AVAIL]
3. Set INFO[NEW]:=ITEM[copies new data into new node]
4. If LOC=NULL then [insert as a 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
[end of if structure]
5. Exit


                                              after.exe




       SHEETAL WAGHMARE   FROM IIT
       KHARAGPUR
Inserting to the End
head        48            17    142
                                      //93   //



 Find the end of the list
   (when at NIL)
    Recursion or iteration



  SHEETAL WAGHMARE   FROM IIT
  KHARAGPUR
Inserting to End of a Linked List
 Recursively traverse the list until at end
 Then:
   Create new node at current
   Fill in data
   Terminate the new node’s next pointer to point to NIL




     SHEETAL WAGHMARE   FROM IIT
     KHARAGPUR
Inserting to End of a Linked List
 1. allocate memory for the new node.
 2. Assign value to the data of the new node.
 3. if START is NULL then(if the list is empty)
       a. Make START point to the NEW node.
      b. make LAST point to the new node
      c. go to step 6.
   4. Make the next field of LAST point to the New node
   5. Mark the new node as LAST.
   6. Make the next field of the new node point to NULL.




          SHEETAL WAGHMARE    FROM IIT
          KHARAGPUR
Inserting to End of a Linked List
 INLAST(INFO,START,AVAIL,ITEM)
1. [OVERFLOW] if AVAIL=NULL then write:OVERFLOW and exit.
2, [remove first node from AVAIL list]
  set NEW=AVAIL and AVAIL=LINK[AVAIL].
3. Set INFO[NEW]=ITEM [copies new data into new node]
4. If START=NULL
Set START=NEW and LOC=START
5. Repeat step 6 untill LINK[LOC] != NULL
6. Set LOC=LINK[LOC]
7. Set LINK[LOC]=NEW
8. Exit



      SHEETAL WAGHMARE   FROM IIT
      KHARAGPUR
Inserting at the End of a Linked List
  head           48               17               142            53




                                                     current    Rnew_data 53

                                       current   Rnew_data 53

                  current      Rnew_data 53

    current   Rnew_data 53


     SHEETAL WAGHMARE       FROM IIT                                           end.exe
     KHARAGPUR
Find the desired element
 FINDB(INFO,LINK,START,ITEM,LOC,LOCP]
 This function finds the location LOC of the first node N which contains ITEM and the
   location LOCP of the node preceding N. if ITEM does not appear in the list, then the
   function set LOC=NULL and it item appears in the first node then it sets LOCP=NULL]
 1.[list empty?] if START=NULL then set LOC=NULL and
      LOCP=NULL and return.
     [end of if structure]
 2. [ITEM in first node?] if INFO[START]==ITEM then
 Set LOC=START and LCOP=NULL and return.
 [end of if structure]
 3 . Set SAVE=START and PTR=LINK[START] [intializes
      pointers]
 4. Repeat step 5 and 6 while PTR != NULL
 5. Contd…….
    SHEETAL WAGHMARE      FROM IIT
    KHARAGPUR
Contd….
 5. if INFO[PTR]=ITEM then
     Set LOC= PTR and LOCP=SAVE and return
     [end of IF structure]
  6. set SAVE=PTR and PTR=LINK[PTR] [ updates pointers]
      [end of step 4 loop]
 7. set LOC=NULL. [search unsuccessful]
 8. return .




      SHEETAL WAGHMARE   FROM IIT
      KHARAGPUR
Delete
 DELETE(INFO,LINK,START,AVAIL,ITEM)
 This algorithm deletes from a linked list the first node N which
    contains the given ITEM of information
   1.[use function FINDB]        call FINDB
   2. if LOC=NULL then write ITEM not in list and exit
   3. [delete node]
        if LOCP=NULL then set START=LINK[START] [delete first
    node]
   Else set LINK[ LOCP]=LINK[LOC]
   [end of if structure]
   4.[return deleted node to the AVAIL list]
    set LINK[LOC]=AVAIL and AVAIL=LOC
   Exit                                         deletion.exe
       SHEETAL WAGHMARE   FROM IIT
       KHARAGPUR
Sorting




SHEETAL WAGHMARE   FROM IIT
KHARAGPUR
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.

 No binary search.               Binary search.


 SHEETAL WAGHMARE    FROM IIT
 KHARAGPUR
ARRAY IMPLEMENTATION OF STACK
 PUSH:-
 1.if(top==max-1)
 1.print(stack overflow)
 2.else
 1.top=top+1
 2.stack arr[top]=pushed item
 3.endif
 end algorithm

 POP:-
 1.if (top==-1)
 1.print(stack underflow)
 2.else
 1.print(popped element is stack arr[top])
 2.top=top-1
 3.end if
 end algorithm
  SHEETAL WAGHMARE     FROM IIT
  KHARAGPUR
QUEUE IMPLEMENTATION
   Procedure Q INSERT (Q, FRONT, REAR,MAX,Y)
    1.[Overflow ?]
        IF REAR>=N
          THEN WRITE ("OVERFLOW")
       RETURN
    2.REAR<-REAR+1
    3.Q[REAR]<-Y
     4.IF FRONT=0
        THEN FRONT<-1
        RETURN
 ENQUEUE:-
    if(rear==(MAX-1))
          print (queue overflow)
      elseif (front==-1)
              front=0
            rear=rear+1
            queue_arr[rear]=added_item
    endif

       SHEETAL WAGHMARE       FROM IIT
       KHARAGPUR
 DEQUEUE
  if(front==-1 OR front>rear)
  print(queue underflow)
  else
  print(element deleted from queue,queue_arr[front])
  front=front+1
  end if
  end algorithm
 Procedure Q DELETE (Q,FRONT, REAR)
   1.UNDERFLOW
   IF FRONT=0
   THEN WRITE ("UNDERFLOW")
   RETURN
   2.Y<-Q[FRONT]
   3.IF FRONT=REAR
   THEN FRONT<-REAR<-0
   ELSE REAR<-REAR+1
   4.RETURN Y
   SHEETAL WAGHMARE    FROM IIT
   KHARAGPUR
PRIORITY QUEUE




                    priority queue.swf




SHEETAL WAGHMARE   FROM IIT KHARAGPUR
Circular Link list




   SHEETAL WAGHMARE   FROM IIT
   KHARAGPUR
10
  Insert into an empty
   list
                                          New    Rear
•Insert into Head of circular link list




             10          20          40          55      70

               New        Cur                              Prev
                                                        Rear
   New->next = Cur;
   Prev->next = New;

      SHEETAL WAGHMARE   FROM IIT
      KHARAGPUR
 Insert to middle of a Circular Linked List between
    Pre and Cur
                    New->next = Cur;
                    Prev->next = New;




          10           20                 55     70

                                   40
                            Prev           Cur    Rear
SHEETAL WAGHMARE   FROM IIT
KHARAGPUR                           New
CIRCULAR QUEUE                            circular queue.swf




Procedure CQINSERT(FRONT,        Procedure CQDELETE
REAR, Q , N ,Y)                  (FRONT, REAR, Q)
 1.IF R=N                          1.[Underflow?]
 THEN R<-1                         IF FRONT =0
 ELSE R<-R+1                       WRITE UNDERFLOW
 2.[Overflow?]                      2.Y<-Q[REAR]
 IF R=F                             3.IF FRONT=REAR
 THEN WRITE ("OVERFLOW")           THEN FRONT<-REAR<-0
 RETURN                            RETURN Y
 3.Q[R]<-Y                          4.IF FRONT= N
 4.                                THEN F<-1
 IF FRONT=0                        ELSE F<-F+1
 FRONT<-1                       
                                    RETURN Y
   SHEETAL WAGHMARE   FROM IIT
   KHARAGPUR
Doubly Linklist
 Traversing the list
 Traversal of a doubly linked list can be in either
  direction. In fact, the direction of traversal can change
  many times




SHEETAL WAGHMARE   FROM IIT
KHARAGPUR
 Forward:
  node := list.firstNode
  while node ≠ null
  <do something with node.data> //print the data
  node := node.next

 Backward:
  node := list.lastNode
  while node ≠ null
  <do something with node.data> // print data
  node := node.prev



    SHEETAL WAGHMARE   FROM IIT
    KHARAGPUR
Inserting into Doubly Linklist
 Inserting a node
 These symmetric functions insert a node either
  after or before a given node, with the diagram
  demonstrating after:




SHEETAL WAGHMARE   FROM IIT
KHARAGPUR
Insert After




 function insertAfter(List list, Node node, Node newNode)
 newNode.prev := node
 newNode.next := node.next
  if node.next == null
     list.lastNode := newNode
 else
      node.next.prev := newNode
       node.next := newNode

 SHEETAL WAGHMARE   FROM IIT
 KHARAGPUR
Insert Before
 function insertBefore(List list, Node node, Node newNode)
  newNode.prev := node.prev
  newNode.next := node
  if node.prev == null
      list.firstNode := newNode
 else
      node.prev.next := newNode
       node.prev := newNode




   SHEETAL WAGHMARE   FROM IIT
   KHARAGPUR
Insert at the Beginning

 function insertBeginning(List list, Node newNode)
  if list.firstNode == null
      list.firstNode := newNode
      list.lastNode := newNode
      newNode.prev := null
      newNode.next := null
 else
     insertBefore(list, list.firstNode, newNode)



   SHEETAL WAGHMARE   FROM IIT
   KHARAGPUR
Insert at the End

 function insertEnd(List list, Node newNode)
  if list.lastNode == null
     insertBeginning(list, newNode)
  else insertAfter(list, list.lastNode, newNode)




 SHEETAL WAGHMARE   FROM IIT
 KHARAGPUR
Deletion
 Deleting a node
 Deletion of a node is easier than insertion, but requires special
  handling if the node to be removed is the firstNode or lastNode:

 function remove(List list, Node node)
     if node.prev == null
      list.firstNode := node.next
    else
     node.prev.next := node.next
   if node.next == null
       list.lastNode := node.prev
   else node.next.prev := node.prev
          destroy node

SHEETAL WAGHMARE   FROM IIT
KHARAGPUR
Multi-lists
 Multi-lists are essentially the technique of embedding
  multiple lists into a single data structure.
 A multi-list has more than one next pointer, like a doubly
  linked list, but the pointers create separate lists.




SHEETAL WAGHMARE   FROM IIT KHARAGPUR
Multi-lists


head




 SHEETAL WAGHMARE   FROM IIT
 KHARAGPUR
Multi-lists

head




 SHEETAL WAGHMARE   FROM IIT
 KHARAGPUR
Multi-lists (Not Required)
                               head
head




 SHEETAL WAGHMARE   FROM IIT
 KHARAGPUR
EXAMPLE




 SHEETAL WAGHMARE   FROM IIT
 KHARAGPUR

More Related Content

What's hot

Doubly Linked List
Doubly Linked ListDoubly Linked List
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structure
eShikshak
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm
KristinaBorooah
 
Stack
StackStack
Link list
Link listLink list
Link list
Didar Rashad
 
sorting and searching.pptx
sorting and searching.pptxsorting and searching.pptx
sorting and searching.pptx
ParagAhir1
 
Queues
QueuesQueues
Insertion sort
Insertion sortInsertion sort
Insertion sort
almaqboli
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
Trupti Agrawal
 
Linked list
Linked listLinked list
Linked list
KalaivaniKS1
 
Data Structures with C Linked List
Data Structures with C Linked ListData Structures with C Linked List
Data Structures with C Linked List
Reazul Islam
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
single linked list
single linked listsingle linked list
single linked list
Sathasivam Rangasamy
 
stack presentation
stack presentationstack presentation
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
Ninad Mankar
 
Presentation on the topic selection sort
Presentation on the topic selection sortPresentation on the topic selection sort
Presentation on the topic selection sort
District Administration
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked lists
Abdullah Al-hazmy
 
Quick sort
Quick sortQuick sort
Quick sort
Dhruv Sabalpara
 
Quick Sort
Quick SortQuick Sort
Quick Sort
Shweta Sahu
 
Different Sorting tecniques in Data Structure
Different Sorting tecniques in Data StructureDifferent Sorting tecniques in Data Structure
Different Sorting tecniques in Data Structure
Tushar Gonawala
 

What's hot (20)

Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structure
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm
 
Stack
StackStack
Stack
 
Link list
Link listLink list
Link list
 
sorting and searching.pptx
sorting and searching.pptxsorting and searching.pptx
sorting and searching.pptx
 
Queues
QueuesQueues
Queues
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Linked list
Linked listLinked list
Linked list
 
Data Structures with C Linked List
Data Structures with C Linked ListData Structures with C Linked List
Data Structures with C Linked List
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
 
single linked list
single linked listsingle linked list
single linked list
 
stack presentation
stack presentationstack presentation
stack presentation
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Presentation on the topic selection sort
Presentation on the topic selection sortPresentation on the topic selection sort
Presentation on the topic selection sort
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked lists
 
Quick sort
Quick sortQuick sort
Quick sort
 
Quick Sort
Quick SortQuick Sort
Quick Sort
 
Different Sorting tecniques in Data Structure
Different Sorting tecniques in Data StructureDifferent Sorting tecniques in Data Structure
Different Sorting tecniques in Data Structure
 

Viewers also liked

Linklist Creation
Linklist CreationLinklist Creation
Linklist Creation
Swarup Saha
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
Gagan Deep
 
Linked list
Linked listLinked list
Linked list
akshat360
 
Link list CSE ( Data structure ) .
Link list CSE  ( Data structure ) .Link list CSE  ( Data structure ) .
Link list CSE ( Data structure ) .
Nirjhor003
 
Data Structure Lecture 5
Data Structure Lecture 5Data Structure Lecture 5
Data Structure Lecture 5
Teksify
 
Link list
Link listLink list
Link list
Ravi Gautam
 
Singly link list
Singly link listSingly link list
Singly link list
Rojin Khadka
 
Link list(by harshit)
Link list(by harshit)Link list(by harshit)
Link list(by harshit)
Harshit Jain
 
Cinterviews Binarysearch Tree
Cinterviews Binarysearch TreeCinterviews Binarysearch Tree
Cinterviews Binarysearch Tree
cinterviews
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
Muhammad Hammad Waseem
 
linked list
linked list linked list
linked list
Mohaimin Rahat
 
Skiena algorithm 2007 lecture07 heapsort priority queues
Skiena algorithm 2007 lecture07 heapsort priority queuesSkiena algorithm 2007 lecture07 heapsort priority queues
Skiena algorithm 2007 lecture07 heapsort priority queues
zukun
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
eShikshak
 
Priority queue
Priority queuePriority queue
Priority queue
Alvian yudha Prawira
 
Data Structure (Circular Linked List)
Data Structure (Circular Linked List)Data Structure (Circular Linked List)
Data Structure (Circular Linked List)
Adam Mukharil Bachtiar
 
Link List
Link ListLink List
Link List
umiekalsum
 
Priority queues
Priority queuesPriority queues
Priority queues
Yeela Mehroz
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
EngineerBabu
 
Algorithm: priority queue
Algorithm: priority queueAlgorithm: priority queue
Algorithm: priority queue
Tareq Hasan
 

Viewers also liked (20)

Linklist Creation
Linklist CreationLinklist Creation
Linklist Creation
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
 
Linked list
Linked listLinked list
Linked list
 
Link list CSE ( Data structure ) .
Link list CSE  ( Data structure ) .Link list CSE  ( Data structure ) .
Link list CSE ( Data structure ) .
 
Data Structure Lecture 5
Data Structure Lecture 5Data Structure Lecture 5
Data Structure Lecture 5
 
Link list
Link listLink list
Link list
 
Singly link list
Singly link listSingly link list
Singly link list
 
Link list(by harshit)
Link list(by harshit)Link list(by harshit)
Link list(by harshit)
 
Cinterviews Binarysearch Tree
Cinterviews Binarysearch TreeCinterviews Binarysearch Tree
Cinterviews Binarysearch Tree
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
 
circular linked list
circular linked listcircular linked list
circular linked list
 
linked list
linked list linked list
linked list
 
Skiena algorithm 2007 lecture07 heapsort priority queues
Skiena algorithm 2007 lecture07 heapsort priority queuesSkiena algorithm 2007 lecture07 heapsort priority queues
Skiena algorithm 2007 lecture07 heapsort priority queues
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
 
Priority queue
Priority queuePriority queue
Priority queue
 
Data Structure (Circular Linked List)
Data Structure (Circular Linked List)Data Structure (Circular Linked List)
Data Structure (Circular Linked List)
 
Link List
Link ListLink List
Link List
 
Priority queues
Priority queuesPriority queues
Priority queues
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
 
Algorithm: priority queue
Algorithm: priority queueAlgorithm: priority queue
Algorithm: priority queue
 

Similar to Linklist

Linked list
Linked list Linked list
Linked list
Arbind Mandal
 
ds 4Linked lists.ppt
ds 4Linked lists.pptds 4Linked lists.ppt
ds 4Linked lists.ppt
AlliVinay1
 
Unit 2 linked list and queues
Unit 2   linked list and queuesUnit 2   linked list and queues
Unit 2 linked list and queues
kalyanineve
 
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
 
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
 
Data structure lecture 5
Data structure lecture 5Data structure lecture 5
Data structure lecture 5
Kumar
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
Durga Devi
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queue
Rai University
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queue
Rai University
 
Linked Lists.pdf
Linked Lists.pdfLinked Lists.pdf
Linked Lists.pdf
Kaynattariq1
 
cp264_lecture13_14_linkedlist.ppt
cp264_lecture13_14_linkedlist.pptcp264_lecture13_14_linkedlist.ppt
cp264_lecture13_14_linkedlist.ppt
ssuser9dd05f
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
Rai University
 
STACK, LINKED LIST ,AND QUEUE
STACK, LINKED LIST ,AND QUEUESTACK, LINKED LIST ,AND QUEUE
STACK, LINKED LIST ,AND QUEUE
Dev Chauhan
 
Linear data structure concepts
Linear data structure conceptsLinear data structure concepts
Linear data structure concepts
Akila Krishnamoorthy
 
IRJET- Dynamic Implementation of Stack using Single Linked List
IRJET- Dynamic Implementation of Stack using Single Linked ListIRJET- Dynamic Implementation of Stack using Single Linked List
IRJET- Dynamic Implementation of Stack using Single Linked List
IRJET Journal
 
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 Presentation in data structurepptx
Linked List Presentation in data structurepptxLinked List Presentation in data structurepptx
Linked List Presentation in data structurepptx
nikhilcse1
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
Dabbal Singh Mahara
 
DS_LinkedList.pptx
DS_LinkedList.pptxDS_LinkedList.pptx
DS_LinkedList.pptx
msohail37
 

Similar to Linklist (20)

Linked list
Linked list Linked list
Linked list
 
ds 4Linked lists.ppt
ds 4Linked lists.pptds 4Linked lists.ppt
ds 4Linked lists.ppt
 
Unit 2 linked list and queues
Unit 2   linked list and queuesUnit 2   linked list and queues
Unit 2 linked list and queues
 
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
 
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
 
Data structure lecture 5
Data structure lecture 5Data structure lecture 5
Data structure lecture 5
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queue
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queue
 
Linked Lists.pdf
Linked Lists.pdfLinked Lists.pdf
Linked Lists.pdf
 
cp264_lecture13_14_linkedlist.ppt
cp264_lecture13_14_linkedlist.pptcp264_lecture13_14_linkedlist.ppt
cp264_lecture13_14_linkedlist.ppt
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
 
STACK, LINKED LIST ,AND QUEUE
STACK, LINKED LIST ,AND QUEUESTACK, LINKED LIST ,AND QUEUE
STACK, LINKED LIST ,AND QUEUE
 
Linear data structure concepts
Linear data structure conceptsLinear data structure concepts
Linear data structure concepts
 
IRJET- Dynamic Implementation of Stack using Single Linked List
IRJET- Dynamic Implementation of Stack using Single Linked ListIRJET- Dynamic Implementation of Stack using Single Linked List
IRJET- Dynamic Implementation of Stack using Single Linked List
 
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 Presentation in data structurepptx
Linked List Presentation in data structurepptxLinked List Presentation in data structurepptx
Linked List Presentation in data structurepptx
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
 
DS_LinkedList.pptx
DS_LinkedList.pptxDS_LinkedList.pptx
DS_LinkedList.pptx
 

More from SHEETAL WAGHMARE

Heaps
HeapsHeaps
Multi ways trees
Multi ways treesMulti ways trees
Multi ways trees
SHEETAL WAGHMARE
 
Sales Force Automation
Sales Force AutomationSales Force Automation
Sales Force Automation
SHEETAL WAGHMARE
 
Enterprise Relationship Management
Enterprise Relationship ManagementEnterprise Relationship Management
Enterprise Relationship Management
SHEETAL WAGHMARE
 
Call Center
Call CenterCall Center
Call Center
SHEETAL WAGHMARE
 
Introduction To CRM
Introduction To CRMIntroduction To CRM
Introduction To CRM
SHEETAL WAGHMARE
 
Tree
TreeTree

More from SHEETAL WAGHMARE (7)

Heaps
HeapsHeaps
Heaps
 
Multi ways trees
Multi ways treesMulti ways trees
Multi ways trees
 
Sales Force Automation
Sales Force AutomationSales Force Automation
Sales Force Automation
 
Enterprise Relationship Management
Enterprise Relationship ManagementEnterprise Relationship Management
Enterprise Relationship Management
 
Call Center
Call CenterCall Center
Call Center
 
Introduction To CRM
Introduction To CRMIntroduction To CRM
Introduction To CRM
 
Tree
TreeTree
Tree
 

Recently uploaded

Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
JomonJoseph58
 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
RamseyBerglund
 
The basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptxThe basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptx
heathfieldcps1
 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
National Information Standards Organization (NISO)
 
Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)
nitinpv4ai
 
Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10
nitinpv4ai
 
Juneteenth Freedom Day 2024 David Douglas School District
Juneteenth Freedom Day 2024 David Douglas School DistrictJuneteenth Freedom Day 2024 David Douglas School District
Juneteenth Freedom Day 2024 David Douglas School District
David Douglas School District
 
Bossa N’ Roll Records by Ismael Vazquez.
Bossa N’ Roll Records by Ismael Vazquez.Bossa N’ Roll Records by Ismael Vazquez.
Bossa N’ Roll Records by Ismael Vazquez.
IsmaelVazquez38
 
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
ImMuslim
 
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
EduSkills OECD
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
nitinpv4ai
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17
Celine George
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
zuzanka
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdfREASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
giancarloi8888
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
Steve Thomason
 
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
TechSoup
 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
zuzanka
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 

Recently uploaded (20)

Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
 
The basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptxThe basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptx
 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
 
Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)
 
Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10
 
Juneteenth Freedom Day 2024 David Douglas School District
Juneteenth Freedom Day 2024 David Douglas School DistrictJuneteenth Freedom Day 2024 David Douglas School District
Juneteenth Freedom Day 2024 David Douglas School District
 
Bossa N’ Roll Records by Ismael Vazquez.
Bossa N’ Roll Records by Ismael Vazquez.Bossa N’ Roll Records by Ismael Vazquez.
Bossa N’ Roll Records by Ismael Vazquez.
 
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
 
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdfREASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
 
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 

Linklist

  • 1. LINK LIST SHEETAL WAGHMARE M.TECH (Computer Science & Data Processing) IIT KHARAGPUR EMAIL-ID: shitu2iitkgp@gmail.com sheetalw3@gmail.com
  • 2. Instruction To Use This Presentation  Dear user I have kept some animated/executable/video files so it will be easy for you to understand but that wont be run/play in slideshow  To see/run that files you have to exit from slideshow then click on the icon and also install KM Player  For example: click on the below icons one by one( one is executable file and other is video) you will be able to see the animation SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 3. CONTENTS SINGLY LINKLIST (INSERTION,DELETION,SORT,SEARCH) STACK(PUSH,POP) QUEUE(ADD,REMOVE) CIRCULAR LINKLIST DOUBLE ENDED QUEUE CIRCULAR QUEUE PRIORITY QUEUE DOUBLY LINKLIST(INSERTION,DELETION,SORT,SEARCH) SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 4. What’s wrong with Array and Why lists?  Disadvantages of arrays as storage data structures:  slow searching in unordered array  slow insertion in ordered array  Fixed size  Linked lists solve some of these problems SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 5. List Implementation using Linked Lists  Linked list  Linear collection of self-referential class objects, called nodes  Connected by pointer links  Accessed via a pointer to the first node of the list  Link pointer in the last node is set to null to mark the list’s end  Use a linked list instead of an array when  You have an unpredictable number of data elements  You want to insert and delete quickly. SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 6. Linked Lists A B C Head  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  Head: pointer to the first node node  The last node points to NULL A SHEETAL WAGHMARE FROM IIT data pointer KHARAGPUR
  • 7. Part II: Linked Lists As an abstract data type, a list is a finite sequence (possibly empty) of elements with basic operations that vary from one application to another. Basic operations commonly include: Construction: Allocate and initialize a list object (usually empty) Empty: Check if list is empty Insert: Add an item to the list at any point Delete: Remove an item from the list at any point Traverse: Go through the list or a part of it, accessing and processing theWAGHMARE in the order they are stored SHEETAL elements FROM IIT KHARAGPUR
  • 8. Linked Representation  Data structure for a linked list: first Node •Data •Link (pointer): used to store the address of the next node. SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 9. Anatomy of a linked list  A linked list consists of:  A sequence of nodes myList a b c d Each node contains a value and a link (pointer or reference) to some other node The last node contains a null link The list may (or may not) have a header SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 10. More terminology  A node’s successor is the next node in the sequence  The last node has no successor  A node’s predecessor is the previous node in the sequence  The first node has no predecessor  A list’s length is the number of elements in it  A list may be empty (contain no elements) SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 11. Linked Lists  Types of linked lists:  Singly linked list  Begins with a pointer to the first node  Terminates with a null pointer  Only traversed in one direction  Circular, singly linked  Pointer in the last node points back to the first node  Doubly linked list  Two “start pointers” – first element and last element  Each node has a forward pointer and a backward pointer  Allows traversals both forwards and backwards  Circular, doubly linked list  Forward pointer of the last node points to the first node and backward pointer of the first node points to the last node SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 12. Declarations  First you must declare a data structure that will be used for the nodes. For example, the following struct could be used to create a list where each node holds a float: SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 13. Conventions of Linked List There are several conventions for the link to indicate the end of the list. 1. A null link that points to no node (0 or NULL) 2. A dummy node that contains no item 3. A reference back to the first node, making it a circular list. SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 14. Convention of the linked list  A special list is maintained which consists of unused memory cells. This list, which has its own pointer, is called the list of available space or the free storage list or the free pool.  The operating system of a computer may periodically collect all the deleted space onto the free storage list. Any technique which does this collection is called garbage collection. SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 15. Conventions  Sometimes new data are to be inserted into the data structure but there is no available space, i.e. the free storage list is empty. This situation is usually called overflow. means when AVAIL = NULL and there is an insertion.  The term underflow refers to the situation where one wants to delete data from a data structure that is empty. The programmer may handle underflow by printing the message UNDERFLOW. means If START = NULL, SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 16. Inserting to the Front head 93 head 48 17 142  There is no work to find the correct location  Empty or not, head will point to the right location SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 17. Insert first position  INFIRST(INFO,START,AVAIL,ITEM) 1. [OVERFLOW] if AVAIL=NULL then write:OVERFLOW and exit. 2. [remove first node from AVAIL list] set NEW=AVAIL and AVAIL=LINK[AVAIL]. 3. Set INFO[NEW]=ITEM [copies new data into new node] 4. Set LINK[NEW]=START [new node now points to original first node] 5. Set START=NEW [changes START so it points to the new node] 6. Exit SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 18. Inserting to the Middle head 17 48 142 93 // 142 //  Used when order is important  Go to the node that should follow the one to add  Recursion or iteration SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 19. Algorithm  INSLOC[INFO,LINK,START,AVAIL,LOC,ITEM] 1. [OVERFLOW] if AVAIL=NULL then write OVERFLOW and exit. 2. [remove first node from AVAIL list] set NEW:=AVAIL and AVAIL:=LINK[AVAIL] 3. Set INFO[NEW]:=ITEM[copies new data into new node] 4. If LOC=NULL then [insert as a 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 [end of if structure] 5. Exit after.exe SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 20. Inserting to the End head 48 17 142 //93 //  Find the end of the list (when at NIL)  Recursion or iteration SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 21. Inserting to End of a Linked List  Recursively traverse the list until at end  Then:  Create new node at current  Fill in data  Terminate the new node’s next pointer to point to NIL SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 22. Inserting to End of a Linked List  1. allocate memory for the new node.  2. Assign value to the data of the new node.  3. if START is NULL then(if the list is empty)  a. Make START point to the NEW node.  b. make LAST point to the new node  c. go to step 6.  4. Make the next field of LAST point to the New node  5. Mark the new node as LAST.  6. Make the next field of the new node point to NULL. SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 23. Inserting to End of a Linked List  INLAST(INFO,START,AVAIL,ITEM) 1. [OVERFLOW] if AVAIL=NULL then write:OVERFLOW and exit. 2, [remove first node from AVAIL list] set NEW=AVAIL and AVAIL=LINK[AVAIL]. 3. Set INFO[NEW]=ITEM [copies new data into new node] 4. If START=NULL Set START=NEW and LOC=START 5. Repeat step 6 untill LINK[LOC] != NULL 6. Set LOC=LINK[LOC] 7. Set LINK[LOC]=NEW 8. Exit SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 24. Inserting at the End of a Linked List head 48 17 142 53 current Rnew_data 53 current Rnew_data 53 current Rnew_data 53 current Rnew_data 53 SHEETAL WAGHMARE FROM IIT end.exe KHARAGPUR
  • 25. Find the desired element FINDB(INFO,LINK,START,ITEM,LOC,LOCP] This function finds the location LOC of the first node N which contains ITEM and the location LOCP of the node preceding N. if ITEM does not appear in the list, then the function set LOC=NULL and it item appears in the first node then it sets LOCP=NULL] 1.[list empty?] if START=NULL then set LOC=NULL and LOCP=NULL and return. [end of if structure] 2. [ITEM in first node?] if INFO[START]==ITEM then Set LOC=START and LCOP=NULL and return. [end of if structure] 3 . Set SAVE=START and PTR=LINK[START] [intializes pointers] 4. Repeat step 5 and 6 while PTR != NULL 5. Contd……. SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 26. Contd….  5. if INFO[PTR]=ITEM then Set LOC= PTR and LOCP=SAVE and return [end of IF structure] 6. set SAVE=PTR and PTR=LINK[PTR] [ updates pointers] [end of step 4 loop] 7. set LOC=NULL. [search unsuccessful] 8. return . SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 27. Delete  DELETE(INFO,LINK,START,AVAIL,ITEM)  This algorithm deletes from a linked list the first node N which contains the given ITEM of information  1.[use function FINDB] call FINDB  2. if LOC=NULL then write ITEM not in list and exit  3. [delete node]  if LOCP=NULL then set START=LINK[START] [delete first node]  Else set LINK[ LOCP]=LINK[LOC]  [end of if structure]  4.[return deleted node to the AVAIL list]  set LINK[LOC]=AVAIL and AVAIL=LOC  Exit deletion.exe SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 28. Sorting SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 29. 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. No binary search. Binary search. SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 30. ARRAY IMPLEMENTATION OF STACK PUSH:- 1.if(top==max-1) 1.print(stack overflow) 2.else 1.top=top+1 2.stack arr[top]=pushed item 3.endif end algorithm POP:- 1.if (top==-1) 1.print(stack underflow) 2.else 1.print(popped element is stack arr[top]) 2.top=top-1 3.end if end algorithm SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 31. QUEUE IMPLEMENTATION  Procedure Q INSERT (Q, FRONT, REAR,MAX,Y) 1.[Overflow ?] IF REAR>=N THEN WRITE ("OVERFLOW") RETURN 2.REAR<-REAR+1 3.Q[REAR]<-Y 4.IF FRONT=0 THEN FRONT<-1 RETURN  ENQUEUE:- if(rear==(MAX-1)) print (queue overflow) elseif (front==-1) front=0 rear=rear+1 queue_arr[rear]=added_item endif SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 32.  DEQUEUE if(front==-1 OR front>rear) print(queue underflow) else print(element deleted from queue,queue_arr[front]) front=front+1 end if end algorithm  Procedure Q DELETE (Q,FRONT, REAR) 1.UNDERFLOW IF FRONT=0 THEN WRITE ("UNDERFLOW") RETURN 2.Y<-Q[FRONT] 3.IF FRONT=REAR THEN FRONT<-REAR<-0 ELSE REAR<-REAR+1 4.RETURN Y SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 33. PRIORITY QUEUE priority queue.swf SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 34. Circular Link list SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 35. 10  Insert into an empty list New Rear •Insert into Head of circular link list 10 20 40 55 70 New Cur Prev Rear New->next = Cur; Prev->next = New; SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 36.  Insert to middle of a Circular Linked List between Pre and Cur New->next = Cur; Prev->next = New; 10 20 55 70 40 Prev Cur Rear SHEETAL WAGHMARE FROM IIT KHARAGPUR New
  • 37. CIRCULAR QUEUE circular queue.swf Procedure CQINSERT(FRONT, Procedure CQDELETE REAR, Q , N ,Y) (FRONT, REAR, Q)  1.IF R=N  1.[Underflow?]  THEN R<-1  IF FRONT =0  ELSE R<-R+1  WRITE UNDERFLOW  2.[Overflow?]  2.Y<-Q[REAR]  IF R=F  3.IF FRONT=REAR  THEN WRITE ("OVERFLOW")  THEN FRONT<-REAR<-0  RETURN  RETURN Y  3.Q[R]<-Y  4.IF FRONT= N  4.  THEN F<-1  IF FRONT=0  ELSE F<-F+1  FRONT<-1   RETURN Y SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 38. Doubly Linklist  Traversing the list  Traversal of a doubly linked list can be in either direction. In fact, the direction of traversal can change many times SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 39.  Forward: node := list.firstNode while node ≠ null <do something with node.data> //print the data node := node.next  Backward: node := list.lastNode while node ≠ null <do something with node.data> // print data node := node.prev SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 40. Inserting into Doubly Linklist  Inserting a node  These symmetric functions insert a node either after or before a given node, with the diagram demonstrating after: SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 41. Insert After function insertAfter(List list, Node node, Node newNode) newNode.prev := node newNode.next := node.next if node.next == null list.lastNode := newNode else node.next.prev := newNode node.next := newNode SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 42. Insert Before  function insertBefore(List list, Node node, Node newNode) newNode.prev := node.prev newNode.next := node if node.prev == null list.firstNode := newNode else node.prev.next := newNode node.prev := newNode SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 43. Insert at the Beginning  function insertBeginning(List list, Node newNode) if list.firstNode == null list.firstNode := newNode list.lastNode := newNode newNode.prev := null newNode.next := null else insertBefore(list, list.firstNode, newNode) SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 44. Insert at the End  function insertEnd(List list, Node newNode) if list.lastNode == null insertBeginning(list, newNode) else insertAfter(list, list.lastNode, newNode) SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 45. Deletion  Deleting a node  Deletion of a node is easier than insertion, but requires special handling if the node to be removed is the firstNode or lastNode:  function remove(List list, Node node) if node.prev == null list.firstNode := node.next else node.prev.next := node.next if node.next == null list.lastNode := node.prev else node.next.prev := node.prev destroy node SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 46. Multi-lists  Multi-lists are essentially the technique of embedding multiple lists into a single data structure.  A multi-list has more than one next pointer, like a doubly linked list, but the pointers create separate lists. SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 47. Multi-lists head SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 48. Multi-lists head SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 49. Multi-lists (Not Required) head head SHEETAL WAGHMARE FROM IIT KHARAGPUR
  • 50. EXAMPLE SHEETAL WAGHMARE FROM IIT KHARAGPUR