Bca data structures linked list mrs.sowmya jyothiSowmya Jyothi
1. Linked lists are a linear data structure where each element contains a data field and a pointer to the next element. This allows flexible insertion and deletion compared to arrays.
2. Each node of a singly linked list contains a data field and a next pointer. Traversal follows the next pointers from head to tail. Doubly linked lists add a back pointer for bidirectional traversal.
3. Common operations on linked lists include traversal, search, insertion at head/specific point, and deletion by adjusting pointers. Memory for new nodes comes from a free list, and deleted nodes return there.
1. The document discusses linked lists, including their representation in memory using nodes containing data and pointer fields, common operations like traversal, searching, and examples of single/double/circular linked lists.
2. Linked lists allow for efficient insertion/deletion by avoiding the need to shift elements like in arrays, but can only be traversed sequentially through each node.
3. The key aspects of linked lists like representation, traversing algorithms, searching unsorted lists, handling overflow and underflow are explained through examples.
Linked List Representation of a Linked List.pptxAAUsH2
A linked list is a linear data structure that stores a collection of data elements dynamically.
Nodes represent those data elements, and links or pointers connect each node.
Each node consists of two fields, the information stored in a linked list and a pointer that stores the address of its next node.
The last node contains null in its second field because it will point to no node.
A linked list can grow and shrink its size, as per the requirement.
It does not waste memory space.
This document discusses different types of linked lists including singly linked lists, circular linked lists, and doubly linked lists. It provides details on representing stacks and queues using linked lists. Key advantages of linked lists over arrays are that linked lists can dynamically grow in size as needed, elements can be inserted and deleted without shifting other elements, and there is no memory wastage. Operations like insertion, deletion, traversal, and searching are described for singly linked lists along with sample C code to implement a linked list, stack, and queue.
The document discusses different types of linked lists including:
- Singly linked lists that can only be traversed in one direction.
- Doubly linked lists that allow traversal in both directions using forward and backward pointers.
- Circular linked lists where the last node points back to the first node allowing continuous traversal.
- Header linked lists that include a header node at the beginning for simplified insertion and deletion. Header lists can be grounded where the last node contains a null pointer or circular where the last node points to the header.
- Two-way or doubly linked lists where each node contains a forward and backward pointer allowing bidirectional traversal through the list.
This is a presentation on Linked Lists, one of the most important topics on Data Structures and algorithms. Anyone who is new to DSA or wants to have a theoretical understanding of the same can refer to it :D
The document discusses linked lists and how they are represented in memory. Linked lists allow for efficient insertion and deletion by using nodes that contain a data field and a pointer to the next node. Each node is represented by two arrays, one storing data and one storing next pointers. A starting pointer points to the first node. Traversing a linked list involves using a pointer variable that iterates through each node by following its next pointer until a null pointer signifies the end of the list.
A linked list is a linear data structure where elements are linked using pointers. Each element contains a data field and a pointer to the next node. Linked lists allow for dynamic sizes and easy insertion/deletion. They are less cache friendly than arrays due to non-contiguous memory allocation. Common operations include insertion/deletion at the beginning, middle, or end which have time complexities ranging from O(1) to O(n) depending on the operation and presence of additional pointers. Doubly linked lists contain pointers to both the next and previous nodes, enabling traversal in both directions but using more memory.
The document discusses various data structures and operations on linked lists. It defines linked lists as a collection of nodes where each node contains a data field and a link to the next node. The summary describes:
Linked lists allow dynamic sizes and efficient insertions/deletions by not requiring shifting of elements, unlike arrays. Common operations on linked lists include insertion, deletion, traversal, searching, and concatenation of lists. Single linked lists contain next pointers, while double linked lists contain both next and previous pointers.
What is DSA ?
What are different types of data structures ?
Primitive and Non Primitive DSA
Arrays
Queue
Stack
Linked List
Memory representation of Linked Lists
Linked List Presentation in data structurepptxnikhilcse1
This document discusses linked lists, including:
- Linked lists store elements in nodes that point to the next node, with each node containing data and a pointer.
- There are different types of linked lists like singly, doubly, and circular linked lists.
- Linked lists allow dynamic memory allocation and efficient insertion/deletion compared to arrays.
- Basic operations on linked lists include insertion, traversal, and deletion through manipulating the pointers between nodes.
- Linked lists have applications in implementing stacks, queues, and hash tables.
A linked list is a linear data structure consisting of nodes that are connected to each other through pointers. Each node contains a data field and a pointer to the next node. Linked lists allow for efficient insertion and removal of nodes and are more flexible than arrays in terms of memory allocation. Common types of linked lists include singly linked lists, doubly linked lists, circular linked lists, and header linked lists.
This document discusses data structures and linked lists. It provides definitions and examples of different types of linked lists, including:
- Single linked lists, which contain nodes with a data field and a link to the next node.
- Circular linked lists, where the last node links back to the first node, forming a loop.
- Doubly linked lists, where each node contains links to both the previous and next nodes.
- Operations on linked lists such as insertion, deletion, traversal, and searching are also described.
The document discusses different types of linked lists, including linear, doubly, and circular linked lists. Linear linked lists contain nodes with an information field and a next pointer. Doubly linked lists contain previous and next pointers. Circular linked lists form a continuous circle without a null pointer, with the next node after the last being the first. Key operations on linked lists include searching, insertion, and deletion. Linked lists allow for dynamic memory allocation and efficient insertion/deletion compared to arrays.
This document discusses the key concepts and operations related to linked lists. It describes the different types of linked lists including singly linked lists, doubly linked lists, circular linked lists, and circular doubly linked lists. It provides algorithms for common linked list operations like insertion, deletion, and traversal. Memory allocation and various applications of linked lists are also covered.
This document discusses linked lists, their types, operations, and applications. It covers:
- Linked lists are dynamic data structures that allow elements to be added or removed easily. They consist of nodes that point to the next node.
- The main types are single linked lists, doubly linked lists, and circular linked lists. Doubly linked lists allow traversal in both directions.
- Basic linked list operations include initialization, adding elements, traversing nodes, and removing elements.
- Linked lists can be used to implement stacks, queues, and priority queues. They are also useful for simulation models using events.
This document discusses linked lists and representing stacks and queues using linked lists. It provides information on different types of linked lists including singly, doubly, and circular linked lists. It describes inserting, deleting, and traversing nodes in a singly linked list. It also provides a C program example to implement a stack using a linked list with functions for push, pop, and display operations. The document discusses how linked lists are dynamic data structures that can grow and shrink in size as needed, unlike arrays.
The document provides information on linked lists including:
- Linked lists are a linear data structure where each node contains data and a pointer to the next node.
- They allow for dynamic memory allocation and easier insertion/deletion than arrays.
- Common types include singly linked, doubly linked, circular singly/doubly linked lists.
- The document describes creating linked lists in C using structures, and operations like insertion, deletion, searching.
This document summarizes a lecture on arrays and linked lists. It discusses arrays, including how to declare and access array elements. It then covers linear arrays and 2-dimensional arrays. Linked lists are introduced, including how they are composed of nodes that link to the next node. Operations on linked lists like traversing, searching, inserting and deleting nodes are described. Doubly linked lists are also covered, which include pointers to both the next and previous nodes.
本資料「To CoT or not to CoT?」では、大規模言語モデルにおけるChain of Thought(CoT)プロンプトの効果について詳しく解説しています。
CoTはあらゆるタスクに効く万能な手法ではなく、特に数学的・論理的・アルゴリズム的な推論を伴う課題で高い効果を発揮することが実験から示されています。
一方で、常識や一般知識を問う問題に対しては効果が限定的であることも明らかになりました。
複雑な問題を段階的に分解・実行する「計画と実行」のプロセスにおいて、CoTの強みが活かされる点も注目ポイントです。
This presentation explores when Chain of Thought (CoT) prompting is truly effective in large language models.
The findings show that CoT significantly improves performance on tasks involving mathematical or logical reasoning, while its impact is limited on general knowledge or commonsense tasks.
More Related Content
Similar to linked list in dsa python (presentation) (20)
This is a presentation on Linked Lists, one of the most important topics on Data Structures and algorithms. Anyone who is new to DSA or wants to have a theoretical understanding of the same can refer to it :D
The document discusses linked lists and how they are represented in memory. Linked lists allow for efficient insertion and deletion by using nodes that contain a data field and a pointer to the next node. Each node is represented by two arrays, one storing data and one storing next pointers. A starting pointer points to the first node. Traversing a linked list involves using a pointer variable that iterates through each node by following its next pointer until a null pointer signifies the end of the list.
A linked list is a linear data structure where elements are linked using pointers. Each element contains a data field and a pointer to the next node. Linked lists allow for dynamic sizes and easy insertion/deletion. They are less cache friendly than arrays due to non-contiguous memory allocation. Common operations include insertion/deletion at the beginning, middle, or end which have time complexities ranging from O(1) to O(n) depending on the operation and presence of additional pointers. Doubly linked lists contain pointers to both the next and previous nodes, enabling traversal in both directions but using more memory.
The document discusses various data structures and operations on linked lists. It defines linked lists as a collection of nodes where each node contains a data field and a link to the next node. The summary describes:
Linked lists allow dynamic sizes and efficient insertions/deletions by not requiring shifting of elements, unlike arrays. Common operations on linked lists include insertion, deletion, traversal, searching, and concatenation of lists. Single linked lists contain next pointers, while double linked lists contain both next and previous pointers.
What is DSA ?
What are different types of data structures ?
Primitive and Non Primitive DSA
Arrays
Queue
Stack
Linked List
Memory representation of Linked Lists
Linked List Presentation in data structurepptxnikhilcse1
This document discusses linked lists, including:
- Linked lists store elements in nodes that point to the next node, with each node containing data and a pointer.
- There are different types of linked lists like singly, doubly, and circular linked lists.
- Linked lists allow dynamic memory allocation and efficient insertion/deletion compared to arrays.
- Basic operations on linked lists include insertion, traversal, and deletion through manipulating the pointers between nodes.
- Linked lists have applications in implementing stacks, queues, and hash tables.
A linked list is a linear data structure consisting of nodes that are connected to each other through pointers. Each node contains a data field and a pointer to the next node. Linked lists allow for efficient insertion and removal of nodes and are more flexible than arrays in terms of memory allocation. Common types of linked lists include singly linked lists, doubly linked lists, circular linked lists, and header linked lists.
This document discusses data structures and linked lists. It provides definitions and examples of different types of linked lists, including:
- Single linked lists, which contain nodes with a data field and a link to the next node.
- Circular linked lists, where the last node links back to the first node, forming a loop.
- Doubly linked lists, where each node contains links to both the previous and next nodes.
- Operations on linked lists such as insertion, deletion, traversal, and searching are also described.
The document discusses different types of linked lists, including linear, doubly, and circular linked lists. Linear linked lists contain nodes with an information field and a next pointer. Doubly linked lists contain previous and next pointers. Circular linked lists form a continuous circle without a null pointer, with the next node after the last being the first. Key operations on linked lists include searching, insertion, and deletion. Linked lists allow for dynamic memory allocation and efficient insertion/deletion compared to arrays.
This document discusses the key concepts and operations related to linked lists. It describes the different types of linked lists including singly linked lists, doubly linked lists, circular linked lists, and circular doubly linked lists. It provides algorithms for common linked list operations like insertion, deletion, and traversal. Memory allocation and various applications of linked lists are also covered.
This document discusses linked lists, their types, operations, and applications. It covers:
- Linked lists are dynamic data structures that allow elements to be added or removed easily. They consist of nodes that point to the next node.
- The main types are single linked lists, doubly linked lists, and circular linked lists. Doubly linked lists allow traversal in both directions.
- Basic linked list operations include initialization, adding elements, traversing nodes, and removing elements.
- Linked lists can be used to implement stacks, queues, and priority queues. They are also useful for simulation models using events.
This document discusses linked lists and representing stacks and queues using linked lists. It provides information on different types of linked lists including singly, doubly, and circular linked lists. It describes inserting, deleting, and traversing nodes in a singly linked list. It also provides a C program example to implement a stack using a linked list with functions for push, pop, and display operations. The document discusses how linked lists are dynamic data structures that can grow and shrink in size as needed, unlike arrays.
The document provides information on linked lists including:
- Linked lists are a linear data structure where each node contains data and a pointer to the next node.
- They allow for dynamic memory allocation and easier insertion/deletion than arrays.
- Common types include singly linked, doubly linked, circular singly/doubly linked lists.
- The document describes creating linked lists in C using structures, and operations like insertion, deletion, searching.
This document summarizes a lecture on arrays and linked lists. It discusses arrays, including how to declare and access array elements. It then covers linear arrays and 2-dimensional arrays. Linked lists are introduced, including how they are composed of nodes that link to the next node. Operations on linked lists like traversing, searching, inserting and deleting nodes are described. Doubly linked lists are also covered, which include pointers to both the next and previous nodes.
本資料「To CoT or not to CoT?」では、大規模言語モデルにおけるChain of Thought(CoT)プロンプトの効果について詳しく解説しています。
CoTはあらゆるタスクに効く万能な手法ではなく、特に数学的・論理的・アルゴリズム的な推論を伴う課題で高い効果を発揮することが実験から示されています。
一方で、常識や一般知識を問う問題に対しては効果が限定的であることも明らかになりました。
複雑な問題を段階的に分解・実行する「計画と実行」のプロセスにおいて、CoTの強みが活かされる点も注目ポイントです。
This presentation explores when Chain of Thought (CoT) prompting is truly effective in large language models.
The findings show that CoT significantly improves performance on tasks involving mathematical or logical reasoning, while its impact is limited on general knowledge or commonsense tasks.
David Boutry - Mentors Junior DevelopersDavid Boutry
David Boutry is a Senior Software Engineer in New York with expertise in high-performance data processing and cloud technologies like AWS and Kubernetes. With over eight years in the field, he has led projects that improved system scalability and reduced processing times by 40%. He actively mentors aspiring developers and holds certifications in AWS, Scrum, and Azure.
4th International Conference on Computer Science and Information Technology (...ijait
4th International Conference on Computer Science and Information Technology
(COMSCI 2025) will act as a major forum for the presentation of innovative ideas,
approaches, developments, and research projects in the area computer Science and
Information Technology. It will also serve to facilitate the exchange of information
between researchers and industry professionals to discuss the latest issues and
advancement in the research area.
Water demand - Types , variations and WDSdhanashree78
Water demand refers to the volume of water needed or requested by users for various purposes. It encompasses the water required for domestic, industrial, agricultural, public, and other uses. Essentially, it represents the overall need or quantity of water required to meet the demands of different sectors and activities.
Blood bank management system project report.pdfKamal Acharya
The main objective of the “Blood Bank management System” all the details in the Blood
Bank’sprocess. This project has some tasks to maintain the Blood Bank through computerization.
Using this blood bank system people can search blood group available which they are needed.
They check it on using our blood bank management website. If in case blood group is not available
in blood bank they can also contact numbers of the persons who has the same blood group he is
need. And he can request the person to done the blood for saving someone life.
The Project describes the smart Blood Bank management system. This report will help you
to know in deep the actual work that has been done as a team work. The main objective of this
application is to automate the complete operations of the blood bank. They need to maintain
hundreds of thousands of records. Also searching should be very faster, so they can find required
details instantly. Main objective is to create a system which helps them to complete their work
faster in simple way by using computer not the oldest way which is used paper. Also our project
contains updated information and many things else.
The project consists of a central repository containing various blood deposits available
along with associated details. These details include blood type, storage area and date of storage.
These details help in maintaining and monitoring the blood deposits. The project is an online
system that allows checking weather required blood deposits of a particular group are available in
the blood bank. Moreover the system also has added features such as patient name and contacts,
blood booking and even need for certain blood group is posted on the website to find available
donors for a blood emergency. This online system is developed on PHP platform and supported
by an MYSQL database to store blood and user specific details.
Understanding Amplitude Modulation : A GuideCircuitDigest
Discover how amplitude modulation works through a detailed guide covering its principles, waveform behavior, and hands-on AM circuit demo using simple electronic components. Great for students and RF beginners.
Read more : https://circuitdigest.com/electronic-circuits/what-is-amplitude-modulation-complete-guide-formula-circuit-diagram-practical-demonstration
A SEW-EURODRIVE brake repair kit is needed for maintenance and repair of specific SEW-EURODRIVE brake models, like the BE series. It includes all necessary parts for preventative maintenance and repairs. This ensures proper brake functionality and extends the lifespan of the brake system
3. Linked Lists
• A linked list, is a linear collection of data
elements called nodes, where the linear order is
given by means of pointers.
• It is the second most used data structure after
array
5. Advantages of Linked Lists
They are a dynamic in nature which allocates the
memory when required.
Insertion and deletion operations can be easily
implemented.
Stacks and queues can be easily executed.
Linked List reduces the access time.
6. Disadvantages of Linked Lists
The memory is wasted as pointers require extra
memory for storage.
No element can be accessed randomly; it has to
access each node sequentially.
Reverse Traversing is difficult in linked list.
7. Linked List Memory Representation
In memory the linked list is stored in scattered cells (locations).The
memory for each node is allocated dynamically means as and when
required. So the Linked List can increase as per the user wish and the size is
not fixed, it can vary.
Suppose first node of linked list is allocated with an address
1008. Its graphical representation looks like the figure shown
below
Suppose next node is allocated at an address 506, so the list
becomes
8. Linked List Memory Representation
Suppose next node is allocated with an address with an
address 10, the list become,
Address Comments links
1008 Root & single element 506
506 1st
element insertion 10
10 2nd
element insertion NULL
9. Linked List Memory Representation
contd..
Let LIST be the linked list. First of all,
LIST requires two linear arrays–call them
as INFO and LINK. INFO[K] represents
the information part and LINK[K]
represents the next pointer field of the
node of LIST for Kth element. LIST also
requires 2variables such as START which
contains the location of the beginning of
the list and the next pointer sentinel
denoted by NULL which indicates the
end of the list. Since the subscript of the
arrays INFO and LINK will usually be
positive, so NULL should be treated as 0
unless otherwise stated.
10. Types of Linked Lists
Singly Linked Lists
Doubly Linked Lists
Circular Linked List
11. Double Linked List
Important Concepts:
Link−Each Link of a linked list store the data
Next−Each Link of a linked list contain a link to next link
Prev−Each Link of a linked list contain a link to previous
link
Linked List− A Linked List contains the connection link to
the first Link called First and to the last link called Last.
12. Circular Linked List
Circular Linked List is a variation of Linked list in which first
element points to last element and last element points to first
element. Both Singly Linked List and Doubly Linked List can
be made into as circular linked list.
Singly Linked List as Circular In singly linked list, the next
pointer of the last node points to the first node.
13. Circular Linked List
Doubly Linked List as Circular In doubly linked list, the
next pointer of the last node points to the first node and the
previous pointer of the first node points to the last node
making the circular in both directions.
14. Linked List Basic Operation
Insertion−add an element at the beginning of the list.
Deletion−delete an element at the beginning of the list.
Insert Last-add an element in the end of the list.
Delete Last−delete an element from the end of the list.
Insert After−add an element after an item of the list.
Traverse−Traverse and display the complete list in forward
manner.
Search−search an element using given key or data item.
Delete−delete an element using given key or data item.
Traverse Backward−displaying complete list in backward manner.
Applicable for double and circular linked list
15. Traverse Algorithm
1.Traverse Algorithm
Consider LIST be a linked list in memory
stored in linear arrays INFO and LINK with
START pointing to the first element, NULL
indicating the end of the list and PTR is the
pointer that points to the node currently
being processed. Below is the algorithm to
traverse through all nodes exactly once and
write the node data element and can be
represented using procedure
PRINT(INFO,LINK,START)
1.Set PTR :=START
2.Repeat steps 3 and 4 while PTR<>NULL
3. PRINT INFO[PTR]
4. PTR:=LINK[PTR]
[PTR pointing to next node]
5.Exit
2.Find count of no. of element in a linked
list
Consider LIST be a linked list in memory
stored in linear arrays INFO and LINK
with START pointing to the first element,
NULL indicating the end of the list and
PTR is the pointer that points to the node
currently being processed. Below is the
algorithm to find the number of NUM
elements in the linked list and can be
represented using procedure
COUNT(INFO,LINK,START,NUM)
1.Set PTR: = START
2.SetCNT=0
3.Repeat steps 4 and 5 while PTR<>NULL
4. IF(INFO[PTR]=NUM) THEN
Set CNT=CNT+1
5. PTR=LINK[PTR] [PTR pointing
to next node]
6.PRINT CNT
7.Exit
16. Searching Algorithm
Unsorted List
Consider LIST be a linked list in memory stored in
linear arrays INFO and LINK with START
pointing to the first element, NULL indicating the
end of the list and PTR is the pointer that points to
the node currently being processed and ITEM is
the information given. Below is the algorithm to
find the location LOC of the node where ITEM
first appears in the LIST and can be represented by
SEARCH(INFO,LINK,START,ITEM)
1.Set PTR = START
2.Set LOC=NULL
3.Repeat steps 4 and 5 while PTR <> NULL
4.IF (ITEM= INFO[PTR]) THEN LOC=PTR
EXIT
5.ELSE PTR=LINK[PTR]
6.Exit
Sorted List
Consider LIST be a linked list in memory
stored in linear arrays INFO and LINK with
START pointing to the first element, NULL
indicating the end of the list and PTR is the
pointer that points to the node currently being
processed and ITEM is the information given.
Below is the algorithm to find the location
LOC of the node where ITEM first appears in
the LIST and can be represented by
SEARCH_SL(INFO,LINK,START,ITEM)
1.Set PTR = START
2.Set LOC = NULL
3.Repeat 4 while PTR<>NULL
4.IF(ITEM<INFO[PTR]) then Set
PTR=LINK[PTR] else
IF(ITEM=INFO[PTR])
then LOC=PTR
EXIT
else EXIT
17. Garbage Collection
The maintenance of the linked list in
memory assumes the possibility of
inserting new nodes into the list requires
some mechanism which provides unused
memory space for the new nodes.
Analogously some mechanism is required
where by the memory space of deleted
nodes becomes available for further use.
Together with the linked list in memory, a
special list is maintained which consists of
unused memory cells. The list, which has
its own pointer, is called the list of
available space or the free storage list or
free pool. Suppose the linked list is
implemented by parallel arrays and then the
unused memory cells in the array will be
also linked together to form linked list
using AVAIL as its list pointer variable.
18. Garbage Collection contd..
Suppose some memory space becomes reusable because a
node is deleted from a list or an entire list is deleted from
the program. Clearly we want the space to be available for
future use. One way to bring this is to immediately
reinsert the space into the free-storage list. This is what
will do when we implement the linked list by means of
linear arrays. However, the method may be too time-
consuming for the operating system of a computer and
which may choose an alternative method as follows.
19. Garbage Collection contd..
The operating system of a computer may periodically collect all the
deleted space on to the free storage list and the techniques does this
collection is called garbage collection. It is invisible to the
programmer. It takes 2 steps
1st –The computer runs through all the list, tagging those cells which
are currently in use
2nd –computer run through the memory, collecting all untagged
space onto the free-storage list The garbage collection take place
when-
There is only some minimum amount of space
No space at all left in the free-storage list
CPU is idle and has time to do the collection
20. The situation is called
Overflow when the data
are inserted into a data
structure but there is no
available space i.e.free
storage list is empty. This
will happen when AVAIL
is NULL and insertion
operation is initiated.
The situation is called
Underflow when deletion
operation is initiated when the
data structure is empty. This
will happen when START is
NULL and deletion operation
is initiated.
Overflow and Underflow
21. Insertion Algorithm
Various situations are possible for inserting a node in a linked list. They are
as following
• Inserts node at the beginning of the list
• Inserts node after the node with a given location
• Inserts a node into a sorted list
All our algorithms assume that the linked list is in memory in the form
LIST(INFO,LINK,START,AVAIL)
and that the variable ITEM contains new information to be added to the list.
All algorithms will include following steps:
• If AVAIL=NULL, then print OVERFLOW
• NEW:=AVAIL, AVAIL=LINK[AVAIL]
• INFO[NEW]:=ITEM
22. Inserting at the beginning of the list
INSFIRST(INFO, LINK,START,AVAIL,ITEM)
1.If AVAIL=NULL, then Write: OVERFLOW and Exit
2.Set NEW:=AVAIL and AVAIL:=LINK[AVAIL]
3.Set INFO[NEW]:=ITEM
4.LINK[NEW]:=START
5.START:=NEW
6.Exit
23. Inserting After a Given Node
INSLOC(INFO, LINK, START, AVAIL, LOC, ITEM)
1. If AVAIL=NULL then WRITE:OVERFLOW and Exit
2. Set NEW:=AVAIL and AVAIL:=LINK[AVAIL]
3. Set INFO[NEW]:=ITEM
4. If LOC=NULL then
Set LINK[NEW]:=START and START:=NEW
Else:
Set LINK[NEW]:=LINK[LOC] and LINK[LOC]:=NEW
5.Exit
24. Inserting into a sorted linked list
1.IF(START=NULL) THEN Set LOC=NULL and Return
2.IF(ITEM<INFO[START]) THEN LOC=NULL and Return
3.Set SAVE=START and PTR=LINK[START]
4.REPEAT 5 and 6 WHILE PTR<>NULL
5. IF ITEM<INFO[PTR] THEN Set LOC=SAVE and
Return
6. Set SAVE = PTR and PTR=LINK[PTR]
7.Set LOC=SAVE
8.Call INSLOC(INFO,LINK,START,AVAIL,LOC,ITEM)
9.Return
25. Deletion Algorithm
The three pointers fields are changed as follows:
1.The next pointer field of first node now points to second node, where node N
previously pointed.
2.The next pointer field of N now points to the original first node in the free
poll, where AVAIL previously pointed.
3.AVAIL now points to the deleted node N.
27. Deletion from a node following a given
node
DEL(INFO, LINK, START, AVAIL, LOC, LOCP)
This algorithm deletes the 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]
Else:
Set LINK[LOCP]:=LINK[LOC]
2.Set LINK[LOC]:=AVAIL and AVAIL:=LOC
3.Exit
28. Header Linked List
A header linked list is a list which always contains a
special node, called the header node, at the beginning of
the list. The following are two kinds of widely used
header lists:
1.A grounded header list is a header list where the last node
contains the null pointer
2.A circular header list is a header list where the last node
points back to the header node.
29. Circular Header List Algorithm
Consider LIST to be a circular header
linked list in memory. START pointing
to the first element, NULL indicating the
end of the list and PTR is the pointer that
points to the node currently being
processed. Below is the algorithm to
traverse through all nodes exactly once
and write the node data element
1.SetPTR=LINK[START]
2.Repeat steps 3 and 4 while
PTR<>START
3.PRINT INFO[PTR]
4.PTR=LINK[PTR]
5.Exit
Consider LIST to be a circular header
linked list in memory with START pointing
to the first element, specific ITEM info is
given, NULL indicating the end of the list
and PTR is the pointer that points to the
node currently being processed. Below is
the algorithm to find the location LOC in
LIST which contains the ITEM. It can be
represented using procedure
SEARCHCHL(INFO,LINK,START,ITEM)
1.SetLOC=NULL
2.Repeat step3 while PTR<>START AND
INFO[PTR]<>ITEM
3.SetPTR=LINK[PTR]
4.IF(INFO[PTR]=ITEM)THEN
Set LOC=PTR
ELSE
Set LOC=NULL
30. Circular Header List Algorithm cont…
Delete the first node N which contains ITEM Consider LIST to be a circular
header linked list in memory with START pointing to the first element, specific
ITEM info is given, NULL indicating the end of the list and PTR is the pointer that
points to the node currently being processed. Below is the algorithm to delete the
first node N which contains ITEM. It can be represented using procedure
DELLOCHL(INFO,LINK,START,AVAIL,ITEM)
1.Set SAVE = START and PTR=LINK[START]
2.Repeat steps 3 while PTR<>START AND INFO[PTR]<>ITEM
3.Set SAVE=PTR and PTR=LINK[PTR]
4.IF(INFO[PTR]=ITEM) THEN Set LOC=PTR and LOCP=SAVE ELSE Set
LOC=NULL and LOCP=SAVE
5.IF(LOC=NULL) THEN PRINT(ITEM not exist) and EXIT
6.Set LINK[LOCP]=LINK[LOC]
7.Set LINK[LOC]=AVAIL and AVAIL=LOC
8.Exit
32. Double Linked List –Deletion Algorithm
Suppose we are given the location LOC of a node N in LIST and want to delete N from the
list. We assume that LIST is a two-way circular header list. Note that PREV[LOC] and
NEXT[LOC] are the locations respectively of the nodes which precede and follow node
N. So N is deleted from the list by changing the following pair of
pointers: NEXT[PREV[LOC]]=NEXT[LOC] and PREV[NEXT[LOC]]=PREV[LOC] The
deleted node N is then returned to the AVAIL list by the assignments: NEXT[LOC]=AVAIL
and AVAIL=LOC
1.SetNEXT[PREV[LOC]]=NEXT[LOC] and PREV[NEXT[LOC]]=PREV[LOC]
2.SetNEXT[LOC]=AVAIL and AVAIL=LOC
3.Exit
33. Double Linked List –Insertion Algorithm
Suppose we are given the locations LOCA and LOCB of adjacent
nodes A and B in LIST and wanted to insert a given ITEM of
information between nodes A and B. As with a single linklist, we
first remove the first node N from the AVAIL list, using the variable
NEW to keep track of its location and then copy the data ITEM into
the node N i.e.we set: NEW=AVAIL, AVAIL=NEXT[AVAIL],
INFO[NEW]=ITEM As shown in the picture, the node N with
contents ITEM is inserted into the list by changing the following
four pointers: NEXT[LOC]=NEW, NEXT[NEW]=LOCB,
PREV[LOCB]=NEW and PREV[NEW]=LOCA
1.IF(AVAIL=NULL) THEN PRINT(OVERFLOW) and EXIT
2.NEW=AVAIL, AVAIL=NEXT[AVAIL], INFO[NEW]=ITEM
3.NEXT[LOCA]=NEW, NEXT[NEW]=LOCB, PREV[LOCB]=NEW and
PREV[NEW]=LOCA 4.Exit
34. Sparse Matrix
A sparse matrix is a two-dimensional array in which most
of the elements are zero or null. It is a wastage of memory
and processing time if we store null values or 0 of the
matrix in an array. To avoid such circumstances different
techniques are used such as linked list.
N-square sparse matrices is called triangular matrix. A
square matrix is called lower triangular if all the entries
above the main diagonal are zero. Similarly, a square
matrix is called upper triangular if all the entries below the
main diagonal are zero.