SlideShare a Scribd company logo
LINKED LIST
MRS.SOWMYA JYOTHI, SDMCBM, MANGALORE
Reference: Data Structures with C by Seymour
Lipschutz, Schaum’s Outlines Series.
•The term list refers to a linear collection of items.
•Data processing frequently involves storing and
processing of data organized into lists.
• There are two ways of storing data in lists.
1. One way to store such data is by means of arrays.
• The linear relationship between the data elements of an array is
reflected by the physical relationship of the data in memory, not by
any information contained in the data elements themselves. This
makes easy to compute the address of a particular element in the
array.
• On the other hand, storing data in arrays has certain
disadvantages. Example: It is relatively expensive to insert and
delete elements in arrays.
• Since an array occupies a block of space, its size is fixed. The size of
the array cannot be changed.
2. Another way of storing a list in memory is to have each
element in the list contain certain field, called a link or a
pointer which contains the address of the next element in
the list.
• The successive elements in the list need not occupy adjacent
space in the memory. This will make it easier to insert and
delete elements in the list(Linked List).
• LINKED LISTS
• A linked list or one-way list is a linear collection of data elements
called nodes.
• Each node is divided into two parts:
1. the first part, called the info field contains the information of the
element, and
2. the second part, called the link field or nextpointer field contains the
address of the next node in the list. The pointer of the last node
contains a special value called null pointer, with invalid address. The null
pointer is denoted by X in the diagram and it signals the end of the list.
The linked list also contains a list pointer variable called START which
contains the address of the first node in the list.
Bca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothi
REPRESENTATION OF LINKED LIST IN MEMORY
• Let LIST be a linked list.
• Then LIST will be maintained in memory, unless otherwise specified or
implied.
• First of all, LIST requires two linear arrays – INFO and LINK- such that
• INFO[K] and LINK[K] contain, respectively, the information part and the
nextpointer field of a node of LIST.
• LIST also requires a variable name – such as START – which contain the
location of the beginning of the list, and a nextpointer sentinel – denoted
by a NULL – which indicates the end of the list.
• Since the subscripts of the arrays INFO and LINK will usually be positive, we
will choose NULL=0, unless and otherwise stated.
The following diagram pictures a linked list
in memory where each node of the list
contains a single character. We can obtain
the actual list of characters, or as follows:
START=9, so INFO[9]=N is the first
character.
LINK[9]=3, so INFO[3]=O is the second
character.
LINK[3]=6, so INFO[6]= (blank) is the third
character.
LINK[6]=11, so INFO[11]=E is the fourth
character.
LINK[11]=7, so INFO[7]=X is the fifth
character.
LINK[7]=10, so INFO[10]=I is the sixth
character.
LINK[10]=4, so INFO[4]=T is the seventh
character.
LINK[4]=0, the NULL value, so the list has
ended.
TRAVERSING A LINKED LIST i=1
• Let LIST be a linked list in memory. i=i+1=2
• Let INFO be the data in the current node,
• LINK points to the address of the next node,
• START is pointing to the address of the first node and NULL indicating the
end of the list.
• Suppose we want to traverse LIST in order to process
each node exactly once.
• The pointer variable PTR which points to the node that is currently being
processes.
• Accordingly, LINK[PTR] points to the next node to be processed.
• Thus the assignment PTR:=LINK[PTR] moves the pointer to the
next node in the list
pointer variable PTR which points to the node that is currently being
processes.
Accordingly, LINK[PTR] points to the next node to be processed.
Algorithm 5.1: (Traversing a Linked List)
•Let LIST be a linked list in the memory. This algorithm
traverses LIST, by applying an operation PROCESS to each
element of the LIST.
•The variable PTR points to the node that is currently being
processed.
1. Set PTR:=START [Initializes pointer to PTR]
2. Repeat Steps 3 and 4 while PTR ≠ NULL
3. Apply PROCESS to INFO[PTR]
4. Set PTR:=LINK[PTR] [PTR now points to the next node]
[End of Step 2 Loop]
5. Exit.
SEARCHING A LINKED LIST
•Let LIST be a linked list in memory.
•Suppose a specific ITEM of information is given, for
finding the location LOC of the node where ITEM
first appears in the LIST.
•Then, one searches for ITEM in LIST by traversing
through the list using a pointer variable PTR and
comparing ITEM with the contents of INFO[PTR] of
each node, one by one, of LIST.
Searching a Linked List (When LIST is Unsorted)
Algorithm 5.2: SEARCH(INFO, LINK, START, ITEM, LOC)
•LIST is the linked list in memory.
•This algorithm finds the location LOC of the node
where ITEM first appears in the LIST, or sets
LOC=NULL.
1. Set PTR:=START [Initializes pointer to PTR]
2. Repeat Steps 3 while PTR ≠ NULL
3. If ITEM=INFO[PTR] then
Set LOC:=PTR, and Exit.
Else:
Set PTR:=LINK[PTR] [PTR now points to the next node]
[End of If structure]
[End of Step 2 Loop]
4. Set LOC:=NULL. [Search is unsuccessful?]
5. Exit.
MEMORY ALLOCATION
The maintenance of linked lists in memory assumes the possibility of
inserting new nodes into the lists and hence requires some mechanism
which provides unused memory space for the new nodes.
• Together with linked lists in memory, 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 free pool.
• The unused memory cells can be linked together as AVAIL. Such a data
structure is usually denoted by writing
• LIST (INFO, LINK, START, AVAIL)
GARBAGE COLLECTION
•Suppose some memory space becomes reusable
because a node is deleted from the linked list, it can
be made available for the future use.
1. One way to do this is to immediately reinsert the
space into the free storage list.
•This method is too time-consuming for the operating
system.
2. Another alternative method can be used known as
garbage collection. It works as follows:
• The operating system may periodically collect all the deleted
space into free storage list. The technique which does this is called
garbage collection.
• Garbage collection usually takes place in two steps.
• First, the computer runs through all cells, tagging those cells
which are currently in use and then the computer runs through
the memory, collecting all untagged space onto the free storage
list.
• The garbage collection may take place when there is only some
minimum amount of space or no space at all left in the free-
storage list, or when CPU is idle and has some time for collection.
• Garbage collection is invisible to the programmer.
OVERFLOW AND UNDERFLOW
1. Sometimes new data are to be inserted into a data
structure but there is no available space, i.e, the free storage
list is empty. This situation is called as overflow.
• The programmer may handle overflow by printing a message
OVERFLOW when AVAIL=NULL.
2. The term underflow refers to some situation where one
wants to delete data from a data structure that is empty.
• The programmer may handle underflow by printing a
message UNDERFLOW when START=NULL and there is a
deletion.
•Avail list empty-Overflow
•Linked list is empty-underfow
INSERTION INTO A LINKED LIST
• Let LIST be a linked list with successive node A and node B.
• Suppose a node N is to be inserted into the list between node
A and node B.
• The node A now points to the new node N, and node N points to
node B, to which node A previously pointed.
•The first node in the AVAIL list will be used for the new
node N.
•The three pointer fields are changed as follows.
1) The link (nextpointer) field of node A now points to the
new node N, to which AVAIL, previously pointed.
2) AVAIL now points to the second node in the free pool, to
which node N previously pointed.
3) The link (nextpointer) field of node N now points to node
B, to which node A previously pointed.
NEW:=AVAIL, AVAIL:=LINK[AVAIL]
INFO[NEW]:=ITEM
INSERTION ALGORITHMS
• Since insertion algorithms will use a node in the AVAIL list, all of
the algorithms will include the following steps:
a) Checking to see if free space is available in the AVAIL list. If not,
that is, if AVAIL=NULL, then the algorithm will print the message
OVERFLOW.
b) Removing the first node from the AVAIL list.
Using the variable NEW to keep track of the location of the new
node, this step can be implemented by the pair of assignments
NEW:=AVAIL, AVAIL:=LINK[AVAIL]
c) Copying new information into the new node.
In other words, INFO[NEW]:=ITEM
INFO[NEW]:=ITEM
2. AVAIL:=LINK[AVAIL]
NEW:=AVAIL, AVAIL:=LINK[AVAIL]
1. NEW:=AVAIL
•Insert at the Beginning of a List
INFO[NEW]:=ITEM LINK [NEW]:=START START:=NEW
1
2
Algorithm 5.4: INSFIRST(INFO, LINK, START, AVAIL, ITEM)
• This algorithm inserts ITEM as the first node in the list.
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 the new node]
4. Set LINK [NEW]:=START [New node now points to the original first node]
5. Set START:=NEW [Change START so it points to the new node]
6. Exit
INSERTING AFTER A GIVEN NODE
• Suppose either the value of LOC or the location LOC is given, the
following algorithm will insert ITEM into LIST so that ITEM follows
node A or when LOC is null ITEM is the first node.
Algorithm 5.5: INSLOC (INFO, LINK, START,AVAIL,LOC, ITEM)
• This algorithm inserts ITEM so that ITEM follows the node with location LOC or
inserts ITEM as the first node when LOC =NULL
1. IF AVAIL=NULL, then Write: OVERFLOW, and Exit. [OVERFLOW?]
2. [Remove first node from AVAIL list]
Set NEW:=AVAIL and AVAIL:=LINK[AVAIL]
3. Set INFO[NEW]:=ITEM [Copies new data into the new node]
4. If LOC=NULL, then:
[Insert as the first node.]
Set LINK[NEW]:=START and START:=NEW.
[Insert after the node with location LOC.]
Else:
Set LINK[NEW]:=LINK[LOC] and LINK[LOC]:=NEW.
5. Exit [End of If Structure]
DELETION FROM A LINKED LIST
•Let LIST be a linked list with a node N between node
A and node B (Fig-a).
•Suppose node N is to be deleted from the linked list
(Fig-b).
•The deletion occurs as soon as the link (nextpointer)
field of node A is changed so that it points to node B.
Bca data structures linked list mrs.sowmya jyothi
• Suppose linked list is maintained in the form,
• LIST(INFO, LINK, START, AVAIL)
• When node is deleted from the LIST, it is immediately returned
to the memory space at the beginning of the AVAIL list.
The three pointer fields are changed as follows:
1) The link (nextpointer) field of node A now points to node B,
where node N previously pointed.
2) The link (nextpointer) field of N now points to the original
first node in the free pool, where AVAIL previously pointed.
3) AVAIL now points to the deleted node N
Bca data structures linked list mrs.sowmya jyothi
DELETION ALGORITHMS
•Algorithms which delete nodes form linked lists come
up in various situations.
1. First one is deleting the node following a given node
and
2. The second one deletes a node with given
information.
•All deletion algorithms will return the memory space of
the deleted node N to the beginning of the AVAIL list.
Bca data structures linked list mrs.sowmya jyothi
Deleting the node following a Given Node
•Let LIST be a linked list in the memory.
•Suppose LOC is the location of a node N in LIST, the
following algorithm deletes N from the list.
Algorithm 5.8:
DEL (INFO, LINK, START, AVAIL, LOC, LOCP)
•This algorithm deletes a node N with location LOC.
•LOCP is the location of the node which precedes N, or
when N is the first node LOCP=NULL.
1. If LOCP:=NULL, then:
Set START:=LINK[START] [Deletes the First node.]
Else:
Set LINK[LOCP]:=LINK[LOC] [Deletes node N.]
2. [Return deleted node to the AVAIL list.]
Set Link[LOC]:=AVAIL and AVAIL:=LOC.
3. Exit.
Bca data structures linked list mrs.sowmya jyothi
CIRCULARLY LINKED LIST
•In circularly linked list, the link field of the last node
points to the first node of the list.
•This type of list is mainly used in lists that allow access
to nodes in the middle of the list without starting at
the beginning.
•The node does not contain NULL pointers as in a singly
linked list.
•The link field of the last node is connected to the
information part of the first node.
Bca data structures linked list mrs.sowmya jyothi
• Insertion and deletion from a circularly linked list follows the
same pattern used in a singly linked list.
1. However, in this case, the last node points to the first node.
Therefore, when inserting or deleting the last node, besides
updating the rear pointer, the last pointer must updated to point
to the first node.
• However, there will be a problem during searching operation.
2. In case of singly linked list, search will be completed if the item
is found or if the end of list is reached.
But in case of circularly linked list, when the last node is
reached, it will point to the beginning. So in case of unsuccessful
search, to avoid infinite loop starting address needs to be saved
and search must be stopped when circled around it.
TWO-WAY LISTS (OR DOUBLY LINKED LISTS)
•Singly linked lists and circularly linked lists are called
one-way lists, since there is only one way that the list
can be traversed, which means, that the lists can be
traversed only in one direction.
•A doubly linked list can be traversed in two directions:
in the usual forward direction from the beginning of
the list to the end, or in the backward direction from
the end of the list to the beginning. Furthermore, from
a given node N, in the list, one can access both the
preceding and the next node.
• A two-way list is a linear collection of data elements, called
nodes, where each node N is divided into three parts:
1. An information field INFO which contains data of Node N.
2. A pointer field FORW which contains the location of the
next node in the list.
3. A pointer field BACK which contains the location of the
preceding node in the list.
• The list also requires two list pointer variables:
1. FIRST, which points to the first node in the list and LAST, which points to
the last node in the list as shown in the figure above.
2. NULL pointer appears in the FORW field of the last node and BACK field
of the first node in the list.
• FIRST and FORW can be used to traverse the list in forward direction and
LAST and BACK can be used to traverse the list in backward direction.
• Suppose LOCA and LOCB are the locations respectively, of Nodes A and
Node B in a two-way list.
• Then the way that the pointers FORW and BACK are defined gives the
following:
•Pointer property: FORW[LOCA]=LOCB if and only if BACK[LOCB]=LOCA.
• In other words, the statement that the Node B follows Node A is equivalent
to the statement that Node A precedes Node B.
Operations on Two-Way Lists
• Traversing: A list can be traversed and each node can be processed
only once.
• Searching: A search for an ITEM in the linked list can be carried out
to find the location LOC of the ITEM in the list.
• Deleting: A node N can be deleted from the two-way list with the
help of FORW and BACK pointers as follows:
• FORW[BACK[LOC]]:=FORW[LOC] and
BACK[FORW[LOC]]:=BACK[LOCK],
• The deleted node N can then be returned to the list of available
nodes AVAIL by the assignments:
• FORW[LOC]:=AVAIL and AVAIL:=LOC.

More Related Content

What's hot (20)

linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
DurgaDeviCbit
 
Linked list
Linked list Linked list
Linked list
Arbind Mandal
 
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHIBCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
Stack using Linked List
Stack using Linked ListStack using Linked List
Stack using Linked List
Sayantan Sur
 
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
 
Singly link list
Singly link listSingly link list
Singly link list
Rojin Khadka
 
Linked List
Linked ListLinked List
Linked List
Ashim Lamichhane
 
Linked list
Linked listLinked list
Linked list
Muhammad Qasim
 
Heaps
HeapsHeaps
Heaps
Hafiz Atif Amin
 
Ppt on Linked list,stack,queue
Ppt on Linked list,stack,queuePpt on Linked list,stack,queue
Ppt on Linked list,stack,queue
Srajan Shukla
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
Apurbo Datta
 
Queues
QueuesQueues
Queues
Ashim Lamichhane
 
Computer Science-Data Structures :Abstract DataType (ADT)
Computer Science-Data Structures :Abstract DataType (ADT)Computer Science-Data Structures :Abstract DataType (ADT)
Computer Science-Data Structures :Abstract DataType (ADT)
St Mary's College,Thrissur,Kerala
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
Selection sort
Selection sortSelection sort
Selection sort
stella D
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
Fahd Allebdi
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
shameen khan
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
Afaq Mansoor Khan
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
somendra kumar
 

Similar to Bca data structures linked list mrs.sowmya jyothi (20)

linked list1.ppt linked list ppts and notes
linked list1.ppt linked list ppts and noteslinked list1.ppt linked list ppts and notes
linked list1.ppt linked list ppts and notes
nisharaheja1986
 
linked list in dsa python (presentation)
linked list in dsa python (presentation)linked list in dsa python (presentation)
linked list in dsa python (presentation)
MirzaAbdullahTariq
 
Data structure lecture 5
Data structure lecture 5Data structure lecture 5
Data structure lecture 5
Kumar
 
Engineering.CSE.DataStructure.Linkedlist.notes
Engineering.CSE.DataStructure.Linkedlist.notesEngineering.CSE.DataStructure.Linkedlist.notes
Engineering.CSE.DataStructure.Linkedlist.notes
limev72215
 
5.Linked list
5.Linked list 5.Linked list
5.Linked list
Mandeep Singh
 
linked list2.ppt linked list part 2 ppt
linked list2.ppt linked list part 2  pptlinked list2.ppt linked list part 2  ppt
linked list2.ppt linked list part 2 ppt
nisharaheja1986
 
DSModule2.pptx
DSModule2.pptxDSModule2.pptx
DSModule2.pptx
ChrisSosaJacob
 
Linked list (1).pptx
Linked list (1).pptxLinked list (1).pptx
Linked list (1).pptx
rajveersingh643731
 
unit 2- linked list- PPT for btech students.pdf
unit 2- linked list- PPT for btech students.pdfunit 2- linked list- PPT for btech students.pdf
unit 2- linked list- PPT for btech students.pdf
soniasharmafdp
 
unit 2- PPT.pdf
unit 2- PPT.pdfunit 2- PPT.pdf
unit 2- PPT.pdf
PranavMakwana6
 
ds-lecture-4-171012041008 (1).pdf
ds-lecture-4-171012041008 (1).pdfds-lecture-4-171012041008 (1).pdf
ds-lecture-4-171012041008 (1).pdf
KamranAli649587
 
Linked lists a
Linked lists aLinked lists a
Linked lists a
Khuram Shahzad
 
Lecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsLecture 5 data structures and algorithms
Lecture 5 data structures and algorithms
Aakash deep Singhal
 
Link list assi
Link list assiLink list assi
Link list assi
PATILPANKAJ106130
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
shameen khan
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
Durga Devi
 
ds 4Linked lists.ppt
ds 4Linked lists.pptds 4Linked lists.ppt
ds 4Linked lists.ppt
AlliVinay1
 
DSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptx
DSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptxDSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptx
DSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptx
vaibhavkore8
 
data structures lists operation of lists
data structures lists operation of listsdata structures lists operation of lists
data structures lists operation of lists
muskans14
 
Ppt of operations on one way link list
Ppt of operations on one way  link listPpt of operations on one way  link list
Ppt of operations on one way link list
Sukhdeep Kaur
 
linked list1.ppt linked list ppts and notes
linked list1.ppt linked list ppts and noteslinked list1.ppt linked list ppts and notes
linked list1.ppt linked list ppts and notes
nisharaheja1986
 
linked list in dsa python (presentation)
linked list in dsa python (presentation)linked list in dsa python (presentation)
linked list in dsa python (presentation)
MirzaAbdullahTariq
 
Data structure lecture 5
Data structure lecture 5Data structure lecture 5
Data structure lecture 5
Kumar
 
Engineering.CSE.DataStructure.Linkedlist.notes
Engineering.CSE.DataStructure.Linkedlist.notesEngineering.CSE.DataStructure.Linkedlist.notes
Engineering.CSE.DataStructure.Linkedlist.notes
limev72215
 
linked list2.ppt linked list part 2 ppt
linked list2.ppt linked list part 2  pptlinked list2.ppt linked list part 2  ppt
linked list2.ppt linked list part 2 ppt
nisharaheja1986
 
unit 2- linked list- PPT for btech students.pdf
unit 2- linked list- PPT for btech students.pdfunit 2- linked list- PPT for btech students.pdf
unit 2- linked list- PPT for btech students.pdf
soniasharmafdp
 
ds-lecture-4-171012041008 (1).pdf
ds-lecture-4-171012041008 (1).pdfds-lecture-4-171012041008 (1).pdf
ds-lecture-4-171012041008 (1).pdf
KamranAli649587
 
Lecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsLecture 5 data structures and algorithms
Lecture 5 data structures and algorithms
Aakash deep Singhal
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
shameen khan
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
Durga Devi
 
ds 4Linked lists.ppt
ds 4Linked lists.pptds 4Linked lists.ppt
ds 4Linked lists.ppt
AlliVinay1
 
DSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptx
DSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptxDSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptx
DSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptx
vaibhavkore8
 
data structures lists operation of lists
data structures lists operation of listsdata structures lists operation of lists
data structures lists operation of lists
muskans14
 
Ppt of operations on one way link list
Ppt of operations on one way  link listPpt of operations on one way  link list
Ppt of operations on one way link list
Sukhdeep Kaur
 

More from Sowmya Jyothi (19)

Functions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiFunctions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothi
Sowmya Jyothi
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
Sowmya Jyothi
 
Arrays in c unit iii chapter 1 mrs.sowmya jyothi
Arrays in c unit iii chapter 1 mrs.sowmya jyothiArrays in c unit iii chapter 1 mrs.sowmya jyothi
Arrays in c unit iii chapter 1 mrs.sowmya jyothi
Sowmya Jyothi
 
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHIBCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHIBCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
Sowmya Jyothi
 
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHIBCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
Sowmya Jyothi
 
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
Sowmya Jyothi
 
Unit II chapter 4 Loops in C
Unit II chapter 4 Loops in CUnit II chapter 4 Loops in C
Unit II chapter 4 Loops in C
Sowmya Jyothi
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
Sowmya Jyothi
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
Sowmya Jyothi
 
Overview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiOverview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya Jyothi
Sowmya Jyothi
 
NETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHI
NETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHINETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHI
NETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
Introduction to computers MRS. SOWMYA JYOTHI
Introduction to computers MRS. SOWMYA JYOTHIIntroduction to computers MRS. SOWMYA JYOTHI
Introduction to computers MRS. SOWMYA JYOTHI
Sowmya Jyothi
 
Introduction to graphics
Introduction to graphicsIntroduction to graphics
Introduction to graphics
Sowmya Jyothi
 
Inter Process Communication PPT
Inter Process Communication PPTInter Process Communication PPT
Inter Process Communication PPT
Sowmya Jyothi
 
Internal representation of file chapter 4 Sowmya Jyothi
Internal representation of file chapter 4 Sowmya JyothiInternal representation of file chapter 4 Sowmya Jyothi
Internal representation of file chapter 4 Sowmya Jyothi
Sowmya Jyothi
 
Buffer cache unix ppt Mrs.Sowmya Jyothi
Buffer cache unix ppt Mrs.Sowmya JyothiBuffer cache unix ppt Mrs.Sowmya Jyothi
Buffer cache unix ppt Mrs.Sowmya Jyothi
Sowmya Jyothi
 
Introduction to the Kernel Chapter 2 Mrs.Sowmya Jyothi
Introduction to the Kernel  Chapter 2 Mrs.Sowmya JyothiIntroduction to the Kernel  Chapter 2 Mrs.Sowmya Jyothi
Introduction to the Kernel Chapter 2 Mrs.Sowmya Jyothi
Sowmya Jyothi
 
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya JyothiIntroduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi
Sowmya Jyothi
 
Functions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiFunctions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothi
Sowmya Jyothi
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
Sowmya Jyothi
 
Arrays in c unit iii chapter 1 mrs.sowmya jyothi
Arrays in c unit iii chapter 1 mrs.sowmya jyothiArrays in c unit iii chapter 1 mrs.sowmya jyothi
Arrays in c unit iii chapter 1 mrs.sowmya jyothi
Sowmya Jyothi
 
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHIBCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHIBCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
Sowmya Jyothi
 
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHIBCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
Sowmya Jyothi
 
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
Sowmya Jyothi
 
Unit II chapter 4 Loops in C
Unit II chapter 4 Loops in CUnit II chapter 4 Loops in C
Unit II chapter 4 Loops in C
Sowmya Jyothi
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
Sowmya Jyothi
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
Sowmya Jyothi
 
Overview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiOverview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya Jyothi
Sowmya Jyothi
 
NETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHI
NETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHINETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHI
NETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
Introduction to computers MRS. SOWMYA JYOTHI
Introduction to computers MRS. SOWMYA JYOTHIIntroduction to computers MRS. SOWMYA JYOTHI
Introduction to computers MRS. SOWMYA JYOTHI
Sowmya Jyothi
 
Introduction to graphics
Introduction to graphicsIntroduction to graphics
Introduction to graphics
Sowmya Jyothi
 
Inter Process Communication PPT
Inter Process Communication PPTInter Process Communication PPT
Inter Process Communication PPT
Sowmya Jyothi
 
Internal representation of file chapter 4 Sowmya Jyothi
Internal representation of file chapter 4 Sowmya JyothiInternal representation of file chapter 4 Sowmya Jyothi
Internal representation of file chapter 4 Sowmya Jyothi
Sowmya Jyothi
 
Buffer cache unix ppt Mrs.Sowmya Jyothi
Buffer cache unix ppt Mrs.Sowmya JyothiBuffer cache unix ppt Mrs.Sowmya Jyothi
Buffer cache unix ppt Mrs.Sowmya Jyothi
Sowmya Jyothi
 
Introduction to the Kernel Chapter 2 Mrs.Sowmya Jyothi
Introduction to the Kernel  Chapter 2 Mrs.Sowmya JyothiIntroduction to the Kernel  Chapter 2 Mrs.Sowmya Jyothi
Introduction to the Kernel Chapter 2 Mrs.Sowmya Jyothi
Sowmya Jyothi
 
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya JyothiIntroduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi
Sowmya Jyothi
 

Recently uploaded (20)

Quality Assurance and Quality Management, B. Pharm 6th Semester-Unit-1
Quality Assurance and Quality Management, B. Pharm 6th Semester-Unit-1Quality Assurance and Quality Management, B. Pharm 6th Semester-Unit-1
Quality Assurance and Quality Management, B. Pharm 6th Semester-Unit-1
Amit Kumar Sahoo
 
Combustion in Compression Ignition Engine (CIE)
Combustion in Compression Ignition Engine (CIE)Combustion in Compression Ignition Engine (CIE)
Combustion in Compression Ignition Engine (CIE)
NileshKumbhar21
 
How to create Record rules in odoo 18 - Odoo Slides
How to create Record rules in odoo 18 - Odoo  SlidesHow to create Record rules in odoo 18 - Odoo  Slides
How to create Record rules in odoo 18 - Odoo Slides
Celine George
 
From Hype to Moat: Building a Defensible AI Strategy
From Hype to Moat: Building a Defensible AI StrategyFrom Hype to Moat: Building a Defensible AI Strategy
From Hype to Moat: Building a Defensible AI Strategy
victoriamangiantini1
 
Flower Identification Class-10 by Kushal Lamichhane.pdf
Flower Identification Class-10 by Kushal Lamichhane.pdfFlower Identification Class-10 by Kushal Lamichhane.pdf
Flower Identification Class-10 by Kushal Lamichhane.pdf
kushallamichhame
 
How to Manage Allow Ship Later for Sold Product in odoo Point of Sale
How to Manage Allow Ship Later for Sold Product in odoo Point of SaleHow to Manage Allow Ship Later for Sold Product in odoo Point of Sale
How to Manage Allow Ship Later for Sold Product in odoo Point of Sale
Celine George
 
Statement by Linda McMahon on May 21, 2025
Statement by Linda McMahon on May 21, 2025Statement by Linda McMahon on May 21, 2025
Statement by Linda McMahon on May 21, 2025
Mebane Rash
 
EUPHORIA GENERAL QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025EUPHORIA GENERAL QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
Quiz Club of PSG College of Arts & Science
 
Taxonomy and Systematics: Classification and Diversity of Insects.pptx
Taxonomy and Systematics: Classification and Diversity of Insects.pptxTaxonomy and Systematics: Classification and Diversity of Insects.pptx
Taxonomy and Systematics: Classification and Diversity of Insects.pptx
Arshad Shaikh
 
Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...
Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...
Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...
EduSkills OECD
 
Protest - Student Revision Booklet For VCE English
Protest - Student Revision Booklet For VCE EnglishProtest - Student Revision Booklet For VCE English
Protest - Student Revision Booklet For VCE English
jpinnuck
 
Intervene with Precision: Zooming In as a Leader Without Micromanaging
Intervene with Precision: Zooming In as a Leader Without MicromanagingIntervene with Precision: Zooming In as a Leader Without Micromanaging
Intervene with Precision: Zooming In as a Leader Without Micromanaging
victoriamangiantini1
 
Product in Wartime: How to Build When the Market Is Against You
Product in Wartime: How to Build When the Market Is Against YouProduct in Wartime: How to Build When the Market Is Against You
Product in Wartime: How to Build When the Market Is Against You
victoriamangiantini1
 
ALL BENGAL U25 QUIZ LEAGUE 2.0 SET BY SKP.pptx
ALL BENGAL U25 QUIZ LEAGUE 2.0 SET BY SKP.pptxALL BENGAL U25 QUIZ LEAGUE 2.0 SET BY SKP.pptx
ALL BENGAL U25 QUIZ LEAGUE 2.0 SET BY SKP.pptx
Sourav Kr Podder
 
Automated Actions (Automation) in the Odoo 18
Automated Actions (Automation) in the Odoo 18Automated Actions (Automation) in the Odoo 18
Automated Actions (Automation) in the Odoo 18
Celine George
 
Basic principles involved in the traditional systems of medicine, Chapter 7,...
Basic principles involved in the traditional systems of medicine,  Chapter 7,...Basic principles involved in the traditional systems of medicine,  Chapter 7,...
Basic principles involved in the traditional systems of medicine, Chapter 7,...
ARUN KUMAR
 
NS3 Unit 5 Matter changes presentation.pptx
NS3 Unit 5 Matter changes presentation.pptxNS3 Unit 5 Matter changes presentation.pptx
NS3 Unit 5 Matter changes presentation.pptx
manuelaromero2013
 
TechSoup - Microsoft Discontinuation of Selected Cloud Donated Offers 2025.05...
TechSoup - Microsoft Discontinuation of Selected Cloud Donated Offers 2025.05...TechSoup - Microsoft Discontinuation of Selected Cloud Donated Offers 2025.05...
TechSoup - Microsoft Discontinuation of Selected Cloud Donated Offers 2025.05...
TechSoup
 
Maslows Toolbox - Inclusive Classrooms.pptx
Maslows Toolbox - Inclusive Classrooms.pptxMaslows Toolbox - Inclusive Classrooms.pptx
Maslows Toolbox - Inclusive Classrooms.pptx
Pooky Knightsmith
 
Salinity Resistance in Plants.Rice plant
Salinity Resistance in Plants.Rice plantSalinity Resistance in Plants.Rice plant
Salinity Resistance in Plants.Rice plant
aliabatool11
 
Quality Assurance and Quality Management, B. Pharm 6th Semester-Unit-1
Quality Assurance and Quality Management, B. Pharm 6th Semester-Unit-1Quality Assurance and Quality Management, B. Pharm 6th Semester-Unit-1
Quality Assurance and Quality Management, B. Pharm 6th Semester-Unit-1
Amit Kumar Sahoo
 
Combustion in Compression Ignition Engine (CIE)
Combustion in Compression Ignition Engine (CIE)Combustion in Compression Ignition Engine (CIE)
Combustion in Compression Ignition Engine (CIE)
NileshKumbhar21
 
How to create Record rules in odoo 18 - Odoo Slides
How to create Record rules in odoo 18 - Odoo  SlidesHow to create Record rules in odoo 18 - Odoo  Slides
How to create Record rules in odoo 18 - Odoo Slides
Celine George
 
From Hype to Moat: Building a Defensible AI Strategy
From Hype to Moat: Building a Defensible AI StrategyFrom Hype to Moat: Building a Defensible AI Strategy
From Hype to Moat: Building a Defensible AI Strategy
victoriamangiantini1
 
Flower Identification Class-10 by Kushal Lamichhane.pdf
Flower Identification Class-10 by Kushal Lamichhane.pdfFlower Identification Class-10 by Kushal Lamichhane.pdf
Flower Identification Class-10 by Kushal Lamichhane.pdf
kushallamichhame
 
How to Manage Allow Ship Later for Sold Product in odoo Point of Sale
How to Manage Allow Ship Later for Sold Product in odoo Point of SaleHow to Manage Allow Ship Later for Sold Product in odoo Point of Sale
How to Manage Allow Ship Later for Sold Product in odoo Point of Sale
Celine George
 
Statement by Linda McMahon on May 21, 2025
Statement by Linda McMahon on May 21, 2025Statement by Linda McMahon on May 21, 2025
Statement by Linda McMahon on May 21, 2025
Mebane Rash
 
Taxonomy and Systematics: Classification and Diversity of Insects.pptx
Taxonomy and Systematics: Classification and Diversity of Insects.pptxTaxonomy and Systematics: Classification and Diversity of Insects.pptx
Taxonomy and Systematics: Classification and Diversity of Insects.pptx
Arshad Shaikh
 
Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...
Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...
Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...
EduSkills OECD
 
Protest - Student Revision Booklet For VCE English
Protest - Student Revision Booklet For VCE EnglishProtest - Student Revision Booklet For VCE English
Protest - Student Revision Booklet For VCE English
jpinnuck
 
Intervene with Precision: Zooming In as a Leader Without Micromanaging
Intervene with Precision: Zooming In as a Leader Without MicromanagingIntervene with Precision: Zooming In as a Leader Without Micromanaging
Intervene with Precision: Zooming In as a Leader Without Micromanaging
victoriamangiantini1
 
Product in Wartime: How to Build When the Market Is Against You
Product in Wartime: How to Build When the Market Is Against YouProduct in Wartime: How to Build When the Market Is Against You
Product in Wartime: How to Build When the Market Is Against You
victoriamangiantini1
 
ALL BENGAL U25 QUIZ LEAGUE 2.0 SET BY SKP.pptx
ALL BENGAL U25 QUIZ LEAGUE 2.0 SET BY SKP.pptxALL BENGAL U25 QUIZ LEAGUE 2.0 SET BY SKP.pptx
ALL BENGAL U25 QUIZ LEAGUE 2.0 SET BY SKP.pptx
Sourav Kr Podder
 
Automated Actions (Automation) in the Odoo 18
Automated Actions (Automation) in the Odoo 18Automated Actions (Automation) in the Odoo 18
Automated Actions (Automation) in the Odoo 18
Celine George
 
Basic principles involved in the traditional systems of medicine, Chapter 7,...
Basic principles involved in the traditional systems of medicine,  Chapter 7,...Basic principles involved in the traditional systems of medicine,  Chapter 7,...
Basic principles involved in the traditional systems of medicine, Chapter 7,...
ARUN KUMAR
 
NS3 Unit 5 Matter changes presentation.pptx
NS3 Unit 5 Matter changes presentation.pptxNS3 Unit 5 Matter changes presentation.pptx
NS3 Unit 5 Matter changes presentation.pptx
manuelaromero2013
 
TechSoup - Microsoft Discontinuation of Selected Cloud Donated Offers 2025.05...
TechSoup - Microsoft Discontinuation of Selected Cloud Donated Offers 2025.05...TechSoup - Microsoft Discontinuation of Selected Cloud Donated Offers 2025.05...
TechSoup - Microsoft Discontinuation of Selected Cloud Donated Offers 2025.05...
TechSoup
 
Maslows Toolbox - Inclusive Classrooms.pptx
Maslows Toolbox - Inclusive Classrooms.pptxMaslows Toolbox - Inclusive Classrooms.pptx
Maslows Toolbox - Inclusive Classrooms.pptx
Pooky Knightsmith
 
Salinity Resistance in Plants.Rice plant
Salinity Resistance in Plants.Rice plantSalinity Resistance in Plants.Rice plant
Salinity Resistance in Plants.Rice plant
aliabatool11
 

Bca data structures linked list mrs.sowmya jyothi

  • 1. LINKED LIST MRS.SOWMYA JYOTHI, SDMCBM, MANGALORE Reference: Data Structures with C by Seymour Lipschutz, Schaum’s Outlines Series.
  • 2. •The term list refers to a linear collection of items. •Data processing frequently involves storing and processing of data organized into lists.
  • 3. • There are two ways of storing data in lists. 1. One way to store such data is by means of arrays. • The linear relationship between the data elements of an array is reflected by the physical relationship of the data in memory, not by any information contained in the data elements themselves. This makes easy to compute the address of a particular element in the array. • On the other hand, storing data in arrays has certain disadvantages. Example: It is relatively expensive to insert and delete elements in arrays. • Since an array occupies a block of space, its size is fixed. The size of the array cannot be changed.
  • 4. 2. Another way of storing a list in memory is to have each element in the list contain certain field, called a link or a pointer which contains the address of the next element in the list. • The successive elements in the list need not occupy adjacent space in the memory. This will make it easier to insert and delete elements in the list(Linked List).
  • 5. • LINKED LISTS • A linked list or one-way list is a linear collection of data elements called nodes. • Each node is divided into two parts: 1. the first part, called the info field contains the information of the element, and 2. the second part, called the link field or nextpointer field contains the address of the next node in the list. The pointer of the last node contains a special value called null pointer, with invalid address. The null pointer is denoted by X in the diagram and it signals the end of the list. The linked list also contains a list pointer variable called START which contains the address of the first node in the list.
  • 8. REPRESENTATION OF LINKED LIST IN MEMORY • Let LIST be a linked list. • Then LIST will be maintained in memory, unless otherwise specified or implied. • First of all, LIST requires two linear arrays – INFO and LINK- such that • INFO[K] and LINK[K] contain, respectively, the information part and the nextpointer field of a node of LIST. • LIST also requires a variable name – such as START – which contain the location of the beginning of the list, and a nextpointer sentinel – denoted by a NULL – which indicates the end of the list. • Since the subscripts of the arrays INFO and LINK will usually be positive, we will choose NULL=0, unless and otherwise stated.
  • 9. The following diagram pictures a linked list in memory where each node of the list contains a single character. We can obtain the actual list of characters, or as follows: START=9, so INFO[9]=N is the first character. LINK[9]=3, so INFO[3]=O is the second character. LINK[3]=6, so INFO[6]= (blank) is the third character. LINK[6]=11, so INFO[11]=E is the fourth character. LINK[11]=7, so INFO[7]=X is the fifth character. LINK[7]=10, so INFO[10]=I is the sixth character. LINK[10]=4, so INFO[4]=T is the seventh character. LINK[4]=0, the NULL value, so the list has ended.
  • 10. TRAVERSING A LINKED LIST i=1 • Let LIST be a linked list in memory. i=i+1=2 • Let INFO be the data in the current node, • LINK points to the address of the next node, • START is pointing to the address of the first node and NULL indicating the end of the list. • Suppose we want to traverse LIST in order to process each node exactly once. • The pointer variable PTR which points to the node that is currently being processes. • Accordingly, LINK[PTR] points to the next node to be processed. • Thus the assignment PTR:=LINK[PTR] moves the pointer to the next node in the list
  • 11. pointer variable PTR which points to the node that is currently being processes. Accordingly, LINK[PTR] points to the next node to be processed.
  • 12. Algorithm 5.1: (Traversing a Linked List) •Let LIST be a linked list in the memory. This algorithm traverses LIST, by applying an operation PROCESS to each element of the LIST. •The variable PTR points to the node that is currently being processed. 1. Set PTR:=START [Initializes pointer to PTR] 2. Repeat Steps 3 and 4 while PTR ≠ NULL 3. Apply PROCESS to INFO[PTR] 4. Set PTR:=LINK[PTR] [PTR now points to the next node] [End of Step 2 Loop] 5. Exit.
  • 13. SEARCHING A LINKED LIST •Let LIST be a linked list in memory. •Suppose a specific ITEM of information is given, for finding the location LOC of the node where ITEM first appears in the LIST. •Then, one searches for ITEM in LIST by traversing through the list using a pointer variable PTR and comparing ITEM with the contents of INFO[PTR] of each node, one by one, of LIST.
  • 14. Searching a Linked List (When LIST is Unsorted) Algorithm 5.2: SEARCH(INFO, LINK, START, ITEM, LOC) •LIST is the linked list in memory. •This algorithm finds the location LOC of the node where ITEM first appears in the LIST, or sets LOC=NULL.
  • 15. 1. Set PTR:=START [Initializes pointer to PTR] 2. Repeat Steps 3 while PTR ≠ NULL 3. If ITEM=INFO[PTR] then Set LOC:=PTR, and Exit. Else: Set PTR:=LINK[PTR] [PTR now points to the next node] [End of If structure] [End of Step 2 Loop] 4. Set LOC:=NULL. [Search is unsuccessful?] 5. Exit.
  • 16. MEMORY ALLOCATION The maintenance of linked lists in memory assumes the possibility of inserting new nodes into the lists and hence requires some mechanism which provides unused memory space for the new nodes. • Together with linked lists in memory, 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 free pool. • The unused memory cells can be linked together as AVAIL. Such a data structure is usually denoted by writing • LIST (INFO, LINK, START, AVAIL)
  • 17. GARBAGE COLLECTION •Suppose some memory space becomes reusable because a node is deleted from the linked list, it can be made available for the future use. 1. One way to do this is to immediately reinsert the space into the free storage list. •This method is too time-consuming for the operating system. 2. Another alternative method can be used known as garbage collection. It works as follows:
  • 18. • The operating system may periodically collect all the deleted space into free storage list. The technique which does this is called garbage collection. • Garbage collection usually takes place in two steps. • First, the computer runs through all cells, tagging those cells which are currently in use and then the computer runs through the memory, collecting all untagged space onto the free storage list. • The garbage collection may take place when there is only some minimum amount of space or no space at all left in the free- storage list, or when CPU is idle and has some time for collection. • Garbage collection is invisible to the programmer.
  • 19. OVERFLOW AND UNDERFLOW 1. Sometimes new data are to be inserted into a data structure but there is no available space, i.e, the free storage list is empty. This situation is called as overflow. • The programmer may handle overflow by printing a message OVERFLOW when AVAIL=NULL. 2. The term underflow refers to some situation where one wants to delete data from a data structure that is empty. • The programmer may handle underflow by printing a message UNDERFLOW when START=NULL and there is a deletion.
  • 20. •Avail list empty-Overflow •Linked list is empty-underfow
  • 21. INSERTION INTO A LINKED LIST • Let LIST be a linked list with successive node A and node B. • Suppose a node N is to be inserted into the list between node A and node B. • The node A now points to the new node N, and node N points to node B, to which node A previously pointed.
  • 22. •The first node in the AVAIL list will be used for the new node N. •The three pointer fields are changed as follows. 1) The link (nextpointer) field of node A now points to the new node N, to which AVAIL, previously pointed. 2) AVAIL now points to the second node in the free pool, to which node N previously pointed. 3) The link (nextpointer) field of node N now points to node B, to which node A previously pointed.
  • 24. INSERTION ALGORITHMS • Since insertion algorithms will use a node in the AVAIL list, all of the algorithms will include the following steps: a) Checking to see if free space is available in the AVAIL list. If not, that is, if AVAIL=NULL, then the algorithm will print the message OVERFLOW. b) Removing the first node from the AVAIL list. Using the variable NEW to keep track of the location of the new node, this step can be implemented by the pair of assignments NEW:=AVAIL, AVAIL:=LINK[AVAIL] c) Copying new information into the new node. In other words, INFO[NEW]:=ITEM
  • 26. •Insert at the Beginning of a List INFO[NEW]:=ITEM LINK [NEW]:=START START:=NEW 1 2
  • 27. Algorithm 5.4: INSFIRST(INFO, LINK, START, AVAIL, ITEM) • This algorithm inserts ITEM as the first node in the list. 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 the new node] 4. Set LINK [NEW]:=START [New node now points to the original first node] 5. Set START:=NEW [Change START so it points to the new node] 6. Exit
  • 28. INSERTING AFTER A GIVEN NODE • Suppose either the value of LOC or the location LOC is given, the following algorithm will insert ITEM into LIST so that ITEM follows node A or when LOC is null ITEM is the first node.
  • 29. Algorithm 5.5: INSLOC (INFO, LINK, START,AVAIL,LOC, ITEM) • This algorithm inserts ITEM so that ITEM follows the node with location LOC or inserts ITEM as the first node when LOC =NULL 1. IF AVAIL=NULL, then Write: OVERFLOW, and Exit. [OVERFLOW?] 2. [Remove first node from AVAIL list] Set NEW:=AVAIL and AVAIL:=LINK[AVAIL] 3. Set INFO[NEW]:=ITEM [Copies new data into the new node] 4. If LOC=NULL, then: [Insert as the first node.] Set LINK[NEW]:=START and START:=NEW. [Insert after the node with location LOC.] Else: Set LINK[NEW]:=LINK[LOC] and LINK[LOC]:=NEW. 5. Exit [End of If Structure]
  • 30. DELETION FROM A LINKED LIST •Let LIST be a linked list with a node N between node A and node B (Fig-a). •Suppose node N is to be deleted from the linked list (Fig-b). •The deletion occurs as soon as the link (nextpointer) field of node A is changed so that it points to node B.
  • 32. • Suppose linked list is maintained in the form, • LIST(INFO, LINK, START, AVAIL) • When node is deleted from the LIST, it is immediately returned to the memory space at the beginning of the AVAIL list. The three pointer fields are changed as follows: 1) The link (nextpointer) field of node A now points to node B, where node N previously pointed. 2) The link (nextpointer) field of N now points to the original first node in the free pool, where AVAIL previously pointed. 3) AVAIL now points to the deleted node N
  • 34. DELETION ALGORITHMS •Algorithms which delete nodes form linked lists come up in various situations. 1. First one is deleting the node following a given node and 2. The second one deletes a node with given information. •All deletion algorithms will return the memory space of the deleted node N to the beginning of the AVAIL list.
  • 36. Deleting the node following a Given Node •Let LIST be a linked list in the memory. •Suppose LOC is the location of a node N in LIST, the following algorithm deletes N from the list. Algorithm 5.8: DEL (INFO, LINK, START, AVAIL, LOC, LOCP) •This algorithm deletes a node N with location LOC. •LOCP is the location of the node which precedes N, or when N is the first node LOCP=NULL.
  • 37. 1. If LOCP:=NULL, then: Set START:=LINK[START] [Deletes the First node.] Else: Set LINK[LOCP]:=LINK[LOC] [Deletes node N.] 2. [Return deleted node to the AVAIL list.] Set Link[LOC]:=AVAIL and AVAIL:=LOC. 3. Exit.
  • 39. CIRCULARLY LINKED LIST •In circularly linked list, the link field of the last node points to the first node of the list. •This type of list is mainly used in lists that allow access to nodes in the middle of the list without starting at the beginning. •The node does not contain NULL pointers as in a singly linked list. •The link field of the last node is connected to the information part of the first node.
  • 41. • Insertion and deletion from a circularly linked list follows the same pattern used in a singly linked list. 1. However, in this case, the last node points to the first node. Therefore, when inserting or deleting the last node, besides updating the rear pointer, the last pointer must updated to point to the first node. • However, there will be a problem during searching operation. 2. In case of singly linked list, search will be completed if the item is found or if the end of list is reached. But in case of circularly linked list, when the last node is reached, it will point to the beginning. So in case of unsuccessful search, to avoid infinite loop starting address needs to be saved and search must be stopped when circled around it.
  • 42. TWO-WAY LISTS (OR DOUBLY LINKED LISTS) •Singly linked lists and circularly linked lists are called one-way lists, since there is only one way that the list can be traversed, which means, that the lists can be traversed only in one direction. •A doubly linked list can be traversed in two directions: in the usual forward direction from the beginning of the list to the end, or in the backward direction from the end of the list to the beginning. Furthermore, from a given node N, in the list, one can access both the preceding and the next node.
  • 43. • A two-way list is a linear collection of data elements, called nodes, where each node N is divided into three parts: 1. An information field INFO which contains data of Node N. 2. A pointer field FORW which contains the location of the next node in the list. 3. A pointer field BACK which contains the location of the preceding node in the list.
  • 44. • The list also requires two list pointer variables: 1. FIRST, which points to the first node in the list and LAST, which points to the last node in the list as shown in the figure above. 2. NULL pointer appears in the FORW field of the last node and BACK field of the first node in the list. • FIRST and FORW can be used to traverse the list in forward direction and LAST and BACK can be used to traverse the list in backward direction. • Suppose LOCA and LOCB are the locations respectively, of Nodes A and Node B in a two-way list. • Then the way that the pointers FORW and BACK are defined gives the following: •Pointer property: FORW[LOCA]=LOCB if and only if BACK[LOCB]=LOCA. • In other words, the statement that the Node B follows Node A is equivalent to the statement that Node A precedes Node B.
  • 45. Operations on Two-Way Lists • Traversing: A list can be traversed and each node can be processed only once. • Searching: A search for an ITEM in the linked list can be carried out to find the location LOC of the ITEM in the list. • Deleting: A node N can be deleted from the two-way list with the help of FORW and BACK pointers as follows: • FORW[BACK[LOC]]:=FORW[LOC] and BACK[FORW[LOC]]:=BACK[LOCK], • The deleted node N can then be returned to the list of available nodes AVAIL by the assignments: • FORW[LOC]:=AVAIL and AVAIL:=LOC.
  翻译: