SlideShare a Scribd company logo
Creating a Linked list :
Algorithm :
Create first node and assign the address of the first node to the
pointer ‘start’.
Step : 1 start =getnode( );
Use another pointer to store the address of the first node, called
CURRPTR
Step : 2 currptr=Start;
Accept the item and store it in the INFO field of the node
Step : 3 info[currptr ]= item;
Accept the Choice from the keyboard whether to create another node
or not
Step : 4 if ( choice = ‘Y’)
goto step 5
else
goto step 6
If choice is ‘Y’ to create another node
Step : 5 i) Newnode = getnode( );
Newnode which contains the address of the newly created node
ii) link[currptr]=Newnode;
Making a link between the original last node and present newnode
iii) currptr=Newnode;
Address of the Newnode is assigned to the original newnode
iv) info[currptr]=item;
Accepting the item and storing it in the info field of currptr
go to step 4
If choice is ‘N’ to make the LINK field of the last node to NULL
Step : 6 link [currptr] = NULL and
Exit
Step : 7 return
• Traversing a linked list :
Algorithm:
Step 1 : Is linked list is empty
if ( start ==NULL)
display (“ linked list is empty “);
exit( )
Step 2 : Assign start value to CURRPTR
currptr=start;
Step 3 : Repeat while(currptr!=NULL)
Process info[currptr]
Step 4 : currptr=link[currptr] /* moving the currptr from one
node to the next node */
Step 5 : Exit
• Algorithm for Displaying a list :
• first check list is empty or not
• Step 1 : if ( start == NULL)
– Write (“ list is Empty”)
– return;
Store the Address of first node in another pointer CURRPTR
• Step 2 : set currptr = start;
• Step 3 : Repeat step4 and step5 while ( currptr !=NULL)
• Display items one-by-one from first node until Currptr becomes
NULL
• Step 4 : display ( info[currptr]);
After the display of this element ,Currptr should point to the next node
• Step 5 : currptr=link[currptr];
• Step 6 : Exit
• Insert operation at the beginning :
• Algorithm :
• Creating a node that is to be inserted
• step 1 : Newnode =getnode( );
• Enter the item into the Info field of the New node
• step 2 : info [Newnode]= item;
• Assign the start value to the LINK part of the inserted node(New
node).
• It makes a link from ‘New node’ to the previous first node.
• Now start and New node points to the original first node of the list.
• It makes link between start and Newnode.
• step 3 : link [Newnode]=start;
• step 4 : start = Newnode;
Exit;
• Algorithm : insert operation at end
Step 1 : if list is empty
if ( start == NULL)
insert at the beginning
exit( )
end if
Step 2 : currptr = start;
Traverse the list to obtain the last node address
Step 3 : while (link [currptr]! = NULL)
currptr = link [ currptr]
end while
Create a newnode and enter the accepted ITEM into its INFO fields
Step 4 : Newnode =getnode( );
Newnode -> info =item;
Make a link between Currptr(last node) and New node
Step 5 : link [currptr] = Newnode;
Step 6 : link [Newnode] = NULL
Step 7 : Exit
• Algorithm for Inserting at certain position :
Step 1: Set CURRPTR to Start
Currptr=Start
Step 2: If the item is to be inserted at 1st position
if (pos==1)
Algorithm for inserting at beginning
Else go to step 3
Step 3: If the item to inserted at some position other than 1st position
for ( i=0; i < pos-2;i++)
{
Currptr= LINK[Currptr]
}
Step 4: Create a Newnode
Newnode=getnode();
Step 5: Enter the element in the INFO field of Newnode
INFO[Newnode]=ITEM;
Step 6: Make a connection between the Newnode and the next node after
CURRPTR
LINK[Newnode]=LINK[Currptr]
Step 7: Make a link between Currptr and newnode
LINK[Currptr]=Newnode;
Step 8 : Exit
• Delete a node from the beginning:
• Algorithm:
Step 1 : check whether the list is empty
if ( start==NULL)
• write “ linked list is empty”
• else goto step 2
Step 2 : Set Currptr to start
Currptr=start;
Step 3 : Assign the link field of the first node to ‘start’ to delete the
original first node
start = link[start];
Step 4 : Free the deleted item
free(Currptr);
Step 5 : Exit
• Delete a node At the end:
• Algorithm:
Step 1 : check whether the list is empty
if ( start==NULL)
• write “ linked list is empty”
• else goto step 2
Step 2 : check if the list has only one element
if ( Link[start]==NULL) then
start=NULL;
else goto step 4
Step 3 : free the deleted node
free(start);
Step 4 : Assign start value to Currptr
Currptr=start;
Step 5 : Assign NULL to the another pointer PREVPTR
PREVPTR = NULL
Step 6 : Traverse the list until the Currptr points to last node
and PREVPTR points to the last before node
While(Link[Currptr]!=NULL)
{
PREVPTR=Currptr;
Currptr = Currptr -> link;
Step 7 : To make the LINK part of the last node, after
deletion to NULL
PREVPTR->LINK=NULL
Step 8 : Exit
• Delete a node at the given position:
• Algorithm:
 Step 1: Check for the position whether the deletion is at first position
if ( pos==1)
Algorithm for deleting a node at beginning
else goto Step 2
 Step 2 : Set Currptr to Start
Currptr=start
 Step 3: set PREVPTR to NULL
PREVPTR = NULL
Step 4 : if the item to be deleted is not at first position
for ( i=1; i<pos; i++ )
{
PREVPTR=Currptr;
Currptr = Currptr->link
}
•  Step 5 : LINK of PREVPTR is assigned with Link of
Currptr i.e. … make a link between the PREVPTR and the
next node of Currptr
PREVPTR  Link = Currptrlink
Step 6 : Exit
• Searching in a single linked list
• Algorithm :
• Step 1: set Currptr=start LOC = NULL
• Step 2: Repeat step 3 while (Currptr !=NULL)
• Step 3: if (item == Info [Currptr] )
– Then LOC = Currptr
– And display “ Search Successful “
– Exit
– else
– Currptr = Link [ Currptr ]
[ so Currptr, Now points to the next node ]
• Step 4: if LOC = NULL
Display “ Search unsuccessful “
• Step 5 : Exit
• Garbage Collection:
Garbage collection is the automatic reclamation of computer storage
The GC function is to find data objects that are no longer in use and make their
space available by the running program.
So Why Garbage Collection:
A software routine operating on data structure should not have to depend
what other routines may be operating on the same structure.
If the process does not free used memory the unused space is accumulated
until the process terminates.
Garbage collection is considered cheaper than explicit deal location
A good garbage collector shows a program down by factor of 10 percent.
Although it seems a lot , it is only a small price to pay for :
Convenience
Development time
Reliability

More Related Content

PDF
Bca data structures linked list mrs.sowmya jyothi
PPT
ds 4Linked lists.ppt
PPT
Data Structure and Algorithms Linked List
PDF
linkrd_list.pdf
PPTX
VCE Unit 02 (1).pptx
PPT
Unit ii(dsc++)
PPT
linked list1.ppt linked list ppts and notes
PPTX
Ppt of operations on one way link list
Bca data structures linked list mrs.sowmya jyothi
ds 4Linked lists.ppt
Data Structure and Algorithms Linked List
linkrd_list.pdf
VCE Unit 02 (1).pptx
Unit ii(dsc++)
linked list1.ppt linked list ppts and notes
Ppt of operations on one way link list

Similar to algorithms_in_linkedlist.pptx (20)

PPTX
Ppt of operations on one way link list
PPTX
Linked list data structures and algorithms
PPTX
DSModule2.pptx
PPTX
Data structures linked list introduction.pptx
PPTX
Linked lists a
PPTX
data structures lists operation of lists
PPTX
11 15 (doubly linked list)
PPTX
Revisiting a data structures in detail with linked list stack and queue
PDF
Solution#includestdio.h#includeconio.h#includealloc.h.pdf
PPTX
linked list in dsa python (presentation)
PPTX
5.Linked list
PPT
Data Structures with C Linked List
PDF
Linked Lists.pdf
PPTX
Lecture 5 data structures and algorithms
PPTX
Linked list (1).pptx
PPT
lecture four of data structures :Linked List-ds.ppt
PPTX
Linked list
PPTX
Circular Linked List in Data Structures Design
PPTX
Doubly Linked List || Operations || Algorithms
Ppt of operations on one way link list
Linked list data structures and algorithms
DSModule2.pptx
Data structures linked list introduction.pptx
Linked lists a
data structures lists operation of lists
11 15 (doubly linked list)
Revisiting a data structures in detail with linked list stack and queue
Solution#includestdio.h#includeconio.h#includealloc.h.pdf
linked list in dsa python (presentation)
5.Linked list
Data Structures with C Linked List
Linked Lists.pdf
Lecture 5 data structures and algorithms
Linked list (1).pptx
lecture four of data structures :Linked List-ds.ppt
Linked list
Circular Linked List in Data Structures Design
Doubly Linked List || Operations || Algorithms
Ad

More from Koteswari Kasireddy (20)

PPTX
DA Syllabus outline (2).pptx
PDF
Chapter-7-Sampling & sampling Distributions.pdf
PDF
Object_Oriented_Programming_Unit3.pdf
PDF
unit-3_Chapter1_RDRA.pdf
PDF
DBMS_UNIT_1.pdf
PDF
business analytics
PPTX
Relational Model and Relational Algebra.pptx
PPTX
CHAPTER -12 it.pptx
PPTX
WEB_DATABASE_chapter_4.pptx
PPTX
Unit 4 chapter - 8 Transaction processing Concepts (1).pptx
PPTX
Database System Concepts AND architecture [Autosaved].pptx
PPTX
Evolution Of WEB_students.pptx
PPTX
Presentation1.pptx
PPTX
Algorithm.pptx
PPTX
Control_Statements_in_Python.pptx
PPTX
Python_Functions_Unit1.pptx
PPTX
parts_of_python_programming_language.pptx
PPTX
linked_list.pptx
PPTX
matrices_and_loops.pptx
PPTX
Control_Statements.pptx
DA Syllabus outline (2).pptx
Chapter-7-Sampling & sampling Distributions.pdf
Object_Oriented_Programming_Unit3.pdf
unit-3_Chapter1_RDRA.pdf
DBMS_UNIT_1.pdf
business analytics
Relational Model and Relational Algebra.pptx
CHAPTER -12 it.pptx
WEB_DATABASE_chapter_4.pptx
Unit 4 chapter - 8 Transaction processing Concepts (1).pptx
Database System Concepts AND architecture [Autosaved].pptx
Evolution Of WEB_students.pptx
Presentation1.pptx
Algorithm.pptx
Control_Statements_in_Python.pptx
Python_Functions_Unit1.pptx
parts_of_python_programming_language.pptx
linked_list.pptx
matrices_and_loops.pptx
Control_Statements.pptx
Ad

Recently uploaded (20)

PDF
Complications of Minimal Access Surgery at WLH
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Computing-Curriculum for Schools in Ghana
PDF
Trump Administration's workforce development strategy
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
Lesson notes of climatology university.
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
advance database management system book.pdf
PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
PPTX
Digestion and Absorption of Carbohydrates, Proteina and Fats
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PDF
Classroom Observation Tools for Teachers
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
Complications of Minimal Access Surgery at WLH
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Computing-Curriculum for Schools in Ghana
Trump Administration's workforce development strategy
Chinmaya Tiranga quiz Grand Finale.pdf
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Weekly quiz Compilation Jan -July 25.pdf
Lesson notes of climatology university.
What if we spent less time fighting change, and more time building what’s rig...
Supply Chain Operations Speaking Notes -ICLT Program
advance database management system book.pdf
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
Digestion and Absorption of Carbohydrates, Proteina and Fats
LDMMIA Reiki Yoga Finals Review Spring Summer
Classroom Observation Tools for Teachers
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
A systematic review of self-coping strategies used by university students to ...
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation

algorithms_in_linkedlist.pptx

  • 1. Creating a Linked list : Algorithm : Create first node and assign the address of the first node to the pointer ‘start’. Step : 1 start =getnode( ); Use another pointer to store the address of the first node, called CURRPTR Step : 2 currptr=Start; Accept the item and store it in the INFO field of the node Step : 3 info[currptr ]= item; Accept the Choice from the keyboard whether to create another node or not Step : 4 if ( choice = ‘Y’) goto step 5 else goto step 6 If choice is ‘Y’ to create another node
  • 2. Step : 5 i) Newnode = getnode( ); Newnode which contains the address of the newly created node ii) link[currptr]=Newnode; Making a link between the original last node and present newnode iii) currptr=Newnode; Address of the Newnode is assigned to the original newnode iv) info[currptr]=item; Accepting the item and storing it in the info field of currptr go to step 4 If choice is ‘N’ to make the LINK field of the last node to NULL Step : 6 link [currptr] = NULL and Exit Step : 7 return
  • 3. • Traversing a linked list : Algorithm: Step 1 : Is linked list is empty if ( start ==NULL) display (“ linked list is empty “); exit( ) Step 2 : Assign start value to CURRPTR currptr=start; Step 3 : Repeat while(currptr!=NULL) Process info[currptr] Step 4 : currptr=link[currptr] /* moving the currptr from one node to the next node */ Step 5 : Exit
  • 4. • Algorithm for Displaying a list : • first check list is empty or not • Step 1 : if ( start == NULL) – Write (“ list is Empty”) – return; Store the Address of first node in another pointer CURRPTR • Step 2 : set currptr = start; • Step 3 : Repeat step4 and step5 while ( currptr !=NULL) • Display items one-by-one from first node until Currptr becomes NULL • Step 4 : display ( info[currptr]); After the display of this element ,Currptr should point to the next node • Step 5 : currptr=link[currptr]; • Step 6 : Exit
  • 5. • Insert operation at the beginning : • Algorithm : • Creating a node that is to be inserted • step 1 : Newnode =getnode( ); • Enter the item into the Info field of the New node • step 2 : info [Newnode]= item; • Assign the start value to the LINK part of the inserted node(New node). • It makes a link from ‘New node’ to the previous first node. • Now start and New node points to the original first node of the list. • It makes link between start and Newnode. • step 3 : link [Newnode]=start; • step 4 : start = Newnode; Exit;
  • 6. • Algorithm : insert operation at end Step 1 : if list is empty if ( start == NULL) insert at the beginning exit( ) end if Step 2 : currptr = start; Traverse the list to obtain the last node address Step 3 : while (link [currptr]! = NULL) currptr = link [ currptr] end while Create a newnode and enter the accepted ITEM into its INFO fields Step 4 : Newnode =getnode( ); Newnode -> info =item; Make a link between Currptr(last node) and New node Step 5 : link [currptr] = Newnode; Step 6 : link [Newnode] = NULL Step 7 : Exit
  • 7. • Algorithm for Inserting at certain position : Step 1: Set CURRPTR to Start Currptr=Start Step 2: If the item is to be inserted at 1st position if (pos==1) Algorithm for inserting at beginning Else go to step 3 Step 3: If the item to inserted at some position other than 1st position for ( i=0; i < pos-2;i++) { Currptr= LINK[Currptr] } Step 4: Create a Newnode Newnode=getnode();
  • 8. Step 5: Enter the element in the INFO field of Newnode INFO[Newnode]=ITEM; Step 6: Make a connection between the Newnode and the next node after CURRPTR LINK[Newnode]=LINK[Currptr] Step 7: Make a link between Currptr and newnode LINK[Currptr]=Newnode; Step 8 : Exit
  • 9. • Delete a node from the beginning: • Algorithm: Step 1 : check whether the list is empty if ( start==NULL) • write “ linked list is empty” • else goto step 2 Step 2 : Set Currptr to start Currptr=start; Step 3 : Assign the link field of the first node to ‘start’ to delete the original first node start = link[start]; Step 4 : Free the deleted item free(Currptr); Step 5 : Exit
  • 10. • Delete a node At the end: • Algorithm: Step 1 : check whether the list is empty if ( start==NULL) • write “ linked list is empty” • else goto step 2 Step 2 : check if the list has only one element if ( Link[start]==NULL) then start=NULL; else goto step 4 Step 3 : free the deleted node free(start); Step 4 : Assign start value to Currptr Currptr=start; Step 5 : Assign NULL to the another pointer PREVPTR PREVPTR = NULL
  • 11. Step 6 : Traverse the list until the Currptr points to last node and PREVPTR points to the last before node While(Link[Currptr]!=NULL) { PREVPTR=Currptr; Currptr = Currptr -> link; Step 7 : To make the LINK part of the last node, after deletion to NULL PREVPTR->LINK=NULL Step 8 : Exit
  • 12. • Delete a node at the given position: • Algorithm:  Step 1: Check for the position whether the deletion is at first position if ( pos==1) Algorithm for deleting a node at beginning else goto Step 2  Step 2 : Set Currptr to Start Currptr=start  Step 3: set PREVPTR to NULL PREVPTR = NULL Step 4 : if the item to be deleted is not at first position for ( i=1; i<pos; i++ ) { PREVPTR=Currptr; Currptr = Currptr->link }
  • 13. •  Step 5 : LINK of PREVPTR is assigned with Link of Currptr i.e. … make a link between the PREVPTR and the next node of Currptr PREVPTR  Link = Currptrlink Step 6 : Exit
  • 14. • Searching in a single linked list • Algorithm : • Step 1: set Currptr=start LOC = NULL • Step 2: Repeat step 3 while (Currptr !=NULL) • Step 3: if (item == Info [Currptr] ) – Then LOC = Currptr – And display “ Search Successful “ – Exit – else – Currptr = Link [ Currptr ] [ so Currptr, Now points to the next node ] • Step 4: if LOC = NULL Display “ Search unsuccessful “ • Step 5 : Exit
  • 15. • Garbage Collection: Garbage collection is the automatic reclamation of computer storage The GC function is to find data objects that are no longer in use and make their space available by the running program. So Why Garbage Collection: A software routine operating on data structure should not have to depend what other routines may be operating on the same structure. If the process does not free used memory the unused space is accumulated until the process terminates. Garbage collection is considered cheaper than explicit deal location A good garbage collector shows a program down by factor of 10 percent. Although it seems a lot , it is only a small price to pay for : Convenience Development time Reliability