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.
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.
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 provides an overview of different types of linked lists:
- Linked lists are collections of nodes that are randomly stored in memory and connected through pointers. Each node contains data and a pointer to the next node.
- Types of linked lists include singly linked lists, circular linked lists, and doubly linked lists. Singly linked lists allow traversal in one direction, while doubly linked lists allow traversal in both directions.
- Common operations on linked lists include traversing, searching, inserting nodes, and deleting nodes. Algorithms for each operation are presented for different types of linked lists.
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.
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
This document discusses linked lists and their implementation. It begins by defining a list as a sequence of zero or more elements of a given type that can be linearly ordered. Linked lists are introduced as a flexible data structure that uses nodes connected by pointers to dynamically allocate elements in memory. The key operations on linked lists are described, including appending, traversing, inserting, deleting nodes. Code examples are provided to implement these operations using a ListNode struct containing a data element and pointer to the next node. Functions like appendNode and displayList are demonstrated, with appendNode adding to the end of the list and displayList traversing the list to output each element.
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.
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.
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 linked lists and their implementation. It covers topics like:
- Types of linked lists including singly linked, doubly linked, circular linked lists
- Operations on linked lists like traversal, insertion, deletion
- Header linked lists that use a header node for simplifying operations
- Two-way or doubly linked lists that allow traversal in both directions
- Algorithms for common linked list operations like insertion, deletion at different positions
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.
This document provides an overview of linked lists including:
- Representation of linked lists in memory using two arrays - one for node information and one for node links
- Common linked list operations like traversing, searching, insertion and deletion
- Different types of linked lists such as doubly linked lists, circular linked lists and header linked lists
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.
Linked list and its operations - Traversalkasthurimukila
The document discusses linked lists and operations performed on singly linked lists. It defines a linked list as a data structure containing nodes that point to the next node in the list. Singly linked lists contain nodes with a data field and pointer to the next node. Common operations on singly linked lists include traversing the list, inserting and deleting nodes from different positions, searching for a node, sorting list elements, and merging two linked lists.
Linked lists are linear data structures where elements are linked using pointers. Each element contains a data field and a pointer to the next node. Elements are not stored at contiguous memory locations. There are three main types of linked lists: single, double, and circular. Operations like insertion and deletion on linked lists involve adjusting the pointers of neighboring nodes, allowing dynamic memory allocation and efficient addition/removal of elements compared to arrays.
The document provides information on various data structures and algorithms related to linked lists. It discusses topics like list traversal, searching, insertion, deletion, header linked lists, circular linked lists, and two-way linked lists. Algorithms are provided for traversing, searching, inserting and deleting nodes from singly linked lists, circular linked lists, and two-way linked lists. Applications of linked lists in representing polynomials and sparse matrices are also covered.
The document discusses various algorithms for linked lists including traversal, search, insertion, deletion, and other operations. It provides pseudocode for algorithms to print all nodes in a linked list, search for a node containing a given item, insert a new node at the beginning or after a given node, and delete a node following a given node or containing a given item. It also covers concepts like header linked lists, circular linked lists, two-way linked lists, and using linked lists to represent polynomials and sparse matrices.
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.
本資料「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 Engineering.CSE.DataStructure.Linkedlist.notes (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
This document discusses linked lists and their implementation. It begins by defining a list as a sequence of zero or more elements of a given type that can be linearly ordered. Linked lists are introduced as a flexible data structure that uses nodes connected by pointers to dynamically allocate elements in memory. The key operations on linked lists are described, including appending, traversing, inserting, deleting nodes. Code examples are provided to implement these operations using a ListNode struct containing a data element and pointer to the next node. Functions like appendNode and displayList are demonstrated, with appendNode adding to the end of the list and displayList traversing the list to output each element.
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.
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.
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 linked lists and their implementation. It covers topics like:
- Types of linked lists including singly linked, doubly linked, circular linked lists
- Operations on linked lists like traversal, insertion, deletion
- Header linked lists that use a header node for simplifying operations
- Two-way or doubly linked lists that allow traversal in both directions
- Algorithms for common linked list operations like insertion, deletion at different positions
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.
This document provides an overview of linked lists including:
- Representation of linked lists in memory using two arrays - one for node information and one for node links
- Common linked list operations like traversing, searching, insertion and deletion
- Different types of linked lists such as doubly linked lists, circular linked lists and header linked lists
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.
Linked list and its operations - Traversalkasthurimukila
The document discusses linked lists and operations performed on singly linked lists. It defines a linked list as a data structure containing nodes that point to the next node in the list. Singly linked lists contain nodes with a data field and pointer to the next node. Common operations on singly linked lists include traversing the list, inserting and deleting nodes from different positions, searching for a node, sorting list elements, and merging two linked lists.
Linked lists are linear data structures where elements are linked using pointers. Each element contains a data field and a pointer to the next node. Elements are not stored at contiguous memory locations. There are three main types of linked lists: single, double, and circular. Operations like insertion and deletion on linked lists involve adjusting the pointers of neighboring nodes, allowing dynamic memory allocation and efficient addition/removal of elements compared to arrays.
The document provides information on various data structures and algorithms related to linked lists. It discusses topics like list traversal, searching, insertion, deletion, header linked lists, circular linked lists, and two-way linked lists. Algorithms are provided for traversing, searching, inserting and deleting nodes from singly linked lists, circular linked lists, and two-way linked lists. Applications of linked lists in representing polynomials and sparse matrices are also covered.
The document discusses various algorithms for linked lists including traversal, search, insertion, deletion, and other operations. It provides pseudocode for algorithms to print all nodes in a linked list, search for a node containing a given item, insert a new node at the beginning or after a given node, and delete a node following a given node or containing a given item. It also covers concepts like header linked lists, circular linked lists, two-way linked lists, and using linked lists to represent polynomials and sparse matrices.
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.
本資料「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.
This document provides information about the Fifth edition of the magazine "Sthapatya" published by the Association of Civil Engineers (Practicing) Aurangabad. It includes messages from current and past presidents of ACEP, memories and photos from past ACEP events, information on life time achievement awards given by ACEP, and a technical article on concrete maintenance, repairs and strengthening. The document highlights activities of ACEP and provides a technical educational article for members.
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
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODSsamueljackson3773
In this paper, the author discusses the concerns of using various wireless communications and how to use
them safely. The author also discusses the future of the wireless industry, wireless communication
security, protection methods, and techniques that could help organizations establish a secure wireless
connection with their employees. The author also discusses other essential factors to learn and note when
manufacturing, selling, or using wireless networks and wireless communication systems.
Impurities of Water and their Significance.pptxdhanashree78
Impart Taste, Odour, Colour, and Turbidity to water.
Presence of organic matter or industrial wastes or microorganisms (algae) imparts taste and odour to water.
Presence of suspended and colloidal matter imparts turbidity to water.
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.
Decoding Kotlin - Your Guide to Solving the Mysterious in Kotlin - Devoxx PL ...João Esperancinha
Kotlin can be very handy and easy to use. Kotlin offers the possibility to develop code that is easy to understand, safe, immutable, and thus predictable and follows standards that avoid side effects. I realized that very quickly after I started my Kotlin journey that already amounts to more than 5 years.
This is the third version of this presentation focused on more detail explaining inline, crossinline, tailrec and as a bonus a quick run through unnamed classes.
3. Introduction
List refers to a linear collection of data items.
Frequently items get added or deleted from the list.
Data processing involves storing and processing data
organized into lists.
There are two ways to represent link.
4. A)
Array is one way for storing data
Linear relationship between data elements is reflected by
physical relationship of data in memory, not by information
contains in data elements.
Elements are stored at consecutive memory locations.
Inserting and deleting the data elements in an array is
relatively expensive.
Array occupies the block of memory space
Size of the array can not be changed as per requirement .
Introduction
5. Introduction
B)
Another way of storing a list in the memory is to have
each element in the list contain a field called ‘link’ or
pointer, which contains the address of the next element in
the list.
Successive elements in the list need not occupy adjacent
space in the memory.
Inserting and deleting in the list is easier.
6. Linked List
The special list of data elements which are linked to one
another.
Logical ordering is represented by having each element
pointing to the next elements.
Linked list is a linear collection of data elements called
‘nodes’ where the linear order is given by means of
pointers.
67 NEXT/POINTER/LINK
89 NEXT/POINTER/LINK
7. Types of Linked List:
Singly Linked List
Doubly Linked List
Linked List
8. Types of Linked List:
Circular Linked List
Circular Doubly Linked List
Linked List
9. Each node is divided is divided in two parts.
Info/Data field – Stores the information of the element.
Link field / Next pointer field /Pointer – Contains address of next
node in the list.
Singly Linked List
11. The pointer of the last node contains a special value called
“Null Pointer’ which is any invalid address.
The Null pointer is denoted by X, signals the end of list.
Liked list also contains a list pointer variable called
‘START ’or ‘NAME’ which contains the address of the
first node in the list.
Only this address in the START is needed to trace through
the list.
If list has no nodes, then list is called ‘Null List’ or
‘Empty’ & is denoted by the null pointer in the variable
START.
12. Prev Info Next Prev Info Next Prev Info Next
NAME or
START
Nodes of doubly linked list have two pointers
Prev: points to the previous node.
Next: points to the next node in the list.
Doubly Linked List
13. Advantages:
Linked lists are dynamic data structure:
They can grow or shrink during execution of the program
Efficient memory utilization:
Memory is not preallocated. Memory is allocated whenever it is
required.
It is deallocated when it is no longer needed.
Insertion and deletion are easier and efficient:
Linked list provides flexibility in inserting data item at a
specified position and deletion of a data item from given position.
Many complex applications can be easily came out with
linked list.
15. Representation of Linked List in memory
Let LIST be a linked list.
LIST will be maintained in memory, unless and otherwise
specified or implies as follows.
LIST requires two Linear Arrays:
INFO
LINK
i.e. INFO[K] & LINK[K] contains respectively
information part and next pointer field of a node of LIST.
LIST also requires variable START which contains the
location of the beginning of the
list.
17. To store list of integer numbers, then linear list can be
represented in memory with following declarations.
struct node
{
int a;
struct node *next;
};
struct node NODE;
NODE * start;
Representation of Linked List in
memory
18. Operations on Linked List
Creation:
Used to create a Linked List.
Constituent node is created as and when is required and linked to the list
to preserve the integrity of the list.
Insertion:
Used to insert a new node in the Linked List at the specified positions.
At the beginning of the Linked List
At the end of the Linked List
At the specified position in the Linked List
If the list is empty, then new node is inserted as first node
Deletion:
Used to delete node from Linked List.
From beginning of the Linked List
From end of the Linked List
From the specified position in the Linked List
19. Operations on Linked List
Traversing:
Process of going through all nodes of a Linked List from one
end to other end.
Start from very first node towards last node, it is called
‘Forward Traversing’.
Concatenation:
Process of appending the second list to the end of first list
containing m nodes.
If the second list has n nodes, then concatenated list contains
(m+n) nodes.
Display:
Used to print each and every nodes information.
20. Traversing a Linked List
Let LIST be a Linked List in memory stored in Linear
Arrays INFO and LINK with START pointing to the first
element and NULL indicating the end of List.
Traversing algorithm uses a pointer variable PTR which
points to the node that is currently being processed.
i.e LINK[PTR] points to the next node to be processed
PTR := LINK[PTR]
It moves pointer to the next node in the List.
21. 34 6000
67 7074
56 9090
45 X 500 10100
START
5020
5020
6000
7074
9090
10100
PTR
X
23. Details of Algorithm:
Initialize PTR or START
Process INFO [PTR], the information at first node.
Update PTR by the assignment PTR : = LINK [PTR], so
that PTR points to the next node.
INFO [PTR] gives information at second node.
Continue updating of PTR until PTR=NULL which
signals end of List.
Traversing a Linked List
24. 1. Set PTR:= START [ Initialize pointer PTR]
2. Repeat steps 3 & 4 while PTR ≠ NULL
3. Apply PROCESS to INFO[PTR]
4. Set PTR:=LINK[PTR]
5. [ PTR now points to next node]
6. [ End of Step 2 Loop]
7. Exit
Algorithm for Traversing a Linked List
Let LIST be a Linked List in memory. This algorithm traverses LIST, applying a
operation PROCESS to each element of LIST. The variable PTR points to the nod
currently being processed.
25. Traversing a Linked List
Info Link Info Link Info X
START
1. Set PTR:= START [ Initialize pointer PTR]
PTR 3. Apply PROCESS to INFO[PTR]
26. Traversing a Linked List
Info Link Info Link Info X
START
PTR
4. Set PTR:=LINK[PTR]
[ PTR now points to next node]
27. Traversing a Linked List
Info Link Info Link Info X
START
PTR
Repeat steps 3 & 4 while PTR ≠ NULL
28. Procedure to print the information at each node
Procedure: PRINT (INFO,LINK, START)
This procedure prints information at each node
1 Set PTR:= START [ Initialize pointer PTR]
2 Repeat steps 3 & 4 while PTR ≠ NULL
3 Write : INFO[PTR]
4 Set PTR:=LINK[PTR]
[ Updates PTR]
[ End of Step 2 Loop]
5 Return
29. Procedure to find the number of elements in a Linked List
Procedure: COUNT (INFO,LINK, START,NUM)
This procedure prints information at each node
1 Set NUM := 0 [ Initialize Counter]
2 Set PTR:= START [ Initialize pointer PTR]
3 Repeat steps 4& 5while PTR ≠ NULL
4 Set NUM:=NUM+1
[ Increase NUM by 1]
5 Set PTR:=LINK[PTR] [ Updates PTR]
[ End of Step3 Loop]
6 Return
30. Searching in a Linked List
There are two searching algorithms for finding LOC
of node where ITEM first appears in LIST.
First algorithm does not assume that data in LIST are sorted
Second algorithm assumes that LIST is sorted.
31. Algorithm for searching an ITEM
SEARCH (INFO, LINK, START, ITEM, LOC)
LIST is a Linked List in memory.This algorithm finds the location LOC
of the node where ITEM first appears in LIST or sets LOC=NULL.
1. Set PTR:= START [ Initialize pointer 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 points to next node]
[End of Step 2 Loop]
4 . [Search is unsuccessful] Set LOC:=NULL
5. Exit
32. Algorithm for searching an ITEM when List is sorted
SEARCH (INFO, LINK, START, ITEM, LOC)
LIST is a Linked List in memory. This algorithm finds the location LOC of the
node where, ITEM first appears in LIST or sets LOC=NULL.
1. Set PTR:= START [ Initialize pointer PTR]
2. Repeat steps 3 while PTR ≠ NULL
3. If ITEM > INFO[PTR] then:
Set PTR: =LINK [PTR] [PTR points to next node]
Else if ITEM = INFO[PTR] then:
Set LOC: =PTR and Exit
Else:
Set PTR: =NULL and Exit [ ITEM does not exists]
[End of If structure]
[End of Step 2 Loop]
4. Set LOC:=NULL
5. Exit
33. Memory Allocation: Garbage Collection
The maintenance of Linked Lists in memory require some
mechanism which provides unused memory space for the
new nodes or mechanism is required whereby the memory
space of deleted nodes becomes available for future use.
Together with the linked lists in memory, a special list is
maintained which consists of unused memory cells.
The list has its own pointer.
List is called as ‘List of available space’ or ‘free storage
list’ or ‘ free pool’.
34. Assume Linked lists are implemented by parallel arrays
and insertion and deletion are performed on the linked
lists.
The unused memory cells in the array will also be linked
together to form a linked list using AVAIL as its list
pointer variable.
36. Garbage Collection
Some memory space becomes reusable because a node is
deleted from a list or an entire list is deleted from a program.
The space can be available for future use.
This can be achieved by immediately reinserting the space into
the free storage list.
This can be done only when linked list is implemented by
means of linear arrays.
This method is too much time consuming for operating system
of a computer.
The alternative way is as: The operating system of a computer
may be periodically collect all deleted space onto the free
storage list. This technique is called ‘Garbage Collection’.
37. Garbage Collection
Garbage Collection is carried out in two steps:
Computer runs through all lists, tagging those cells which are
currently in use.
Then, computer runs through the memory, collecting all
untagged space onto 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 the CPU is idle and has time to do the
collection.
Garbage collection is invisible to programmer.
38. Overflow and Underflow
Overflow:
Sometimes new data are to be inserted into data structure but there
is no available space. i.e. free storage list is empty. Programmer
may handle overflow by printing the message OVERFLOW.
Overflow will occur with our linked list when AVAIL = NULL and
there is an insertion.
Underflow:
Situation where one wants to delete data from a data structure that
is empty.
Underflow can be handled by printing the message UNDERFLOW.
Underflow will occur with our linked list when START = NULL
and there is deletion.
39. The Scenario
You have a linked list
Perhaps empty, perhaps not
Perhaps ordered, perhaps not
You want to add an element into
the linked list
48 17 142
head
//
40. Adding an Element to a Linked List
Involves two steps:
Finding the correct location
Doing the work to add the node
41. Finding the Correct Location
Three possible positions:
The front
The end
Somewhere in the middle
42. head
Inserting to the Front
There is no work to find the correct
location
Empty or not, head will point to the
right location
48 17 142
START 93
43. Inserting to the End
Find the end of the list
(when at NIL)
Recursion or iteration
48 17 142
START
//93
//
Don’t Worry!
44. Inserting to the Middle
Used when order is important
Go to the node that should follow the
one to add
Recursion or iteration
17 48 142
START
//
93
//
142
45. Insertion into Linked Lists
START X
Node A Node B
New node N is to be inserted into list between nodes A and B
Linked list with successive nodes A & B
START X
Node A Node B
Node N
Node A points to the new node N New node N points to node B,
to which A previously pointed
46. Linked list is maintained on memory in the form
LIST (INFO, LINK, START, AVAIL)
The first node in the AVAIL list will be used for new node N.
The nextponiter field of node A now points to the new node N,
to which AVAIL previously pointed.
AVAIL now points to second node in free pool, to which node
N previously pointed.
The nextponiter field of node N now points to node B, to which
node A previously pointed
.
47. Insertion into Linked Lists
START X
Node A Node B
New node N is to be inserted into list between nodes A and B
Linked list with successive nodes A & B
AVAIL X
Node N
Node A points to the new node N
New node N points to node B,
to which A previously pointed
Free Storage List
48. Insertion Algorithm
Insertion algorithm will use node in the AVAIL list.
Therefore all the algorithms will include following steps
Checking the availability of space in the AVAIL list. If the
space is not available i.e. AVAIL = NULL, then the algorithm
will print the message OVERFLOW.
Removing the first node from the AVAIL list. Using the
variable NEW to keep track the location of the new node, this
step can be implemented by pair of assignments.
NEW:=AVAIL, AVAIL:=LINK[AVAIL]
Linked may be empty or not. Also Linked list may be
ordered or not.
49. Algorithm for Inserting to the Front
INSERT (INFO, LINK, START, AVAIL, ITEM)
This algorithm inserts ITEM as the first node in the list
1. [OVERFLOW?] If AVIAL =NULL, then: Write:
OVERFLOW, and Exit
2. [Remove first node from AVAIL list]
Set NEW:=AVAIL and AVAIL :=LINK[AVAIL]
3. Set INFO [NEW]: = ITEM [Copies new data into
new node]
4. Set LINK [NEW]: = START [New node points to
original first node]
5. Set START: = NEW [ Changes START so it points to
the new node]
6 .Exit
50. Insertion into Linked Lists
START X
(New node N is to be inserted at front)
AVAIL X
AVAIL:=LINK[AVAIL]
Free Storage List
NEW
NEW:=AVAIL
67
INFO[NEW]=ITEM
START
LINK [NEW]=START
START=NEW
51. START X
Linked list with new nod added at front
AVAIL X
Free Storage List
67
52. Algorithm for Inserting after a Given Node
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. [OVERFLOW?] If AVIAL =NULL, then : Write: OVERFLOW, and
Exit
2. [Remove first node from AVAIL list]
Set NEW:=AVAIL and AVAIL :=LINK[AVAIL]
3. Set INFO [NEW]:= ITEM [ Copies new data into new node]
4. If LOC =NULL, then: [Insert as first node]
Set LINK [NEW]:= START and START:=NEW
Else: [Insert after node with location LOC]
Set LINK [NEW]:=LINK[LOC] and LINK [LOC] := New
[End of If Structure]
5. Exit
53. The Scenario
Begin with an existing linked list
Could be empty or not
Could be ordered or not
4 17
START
42
6
54. The Scenario
Begin with an existing linked list
Could be empty or not
Could be ordered or not
4 17
START
42
6
55. The Scenario
Begin with an existing linked list
Could be empty or not
Could be ordered or not
4 17
START
42
56. The Scenario
Begin with an existing linked list
Could be empty or not
Could be ordered or not
4 17
head
42
57. Deletion from a Linked List
LIST is a linked list with a node N between nodes A & B as
shown in Figure.
• Schematic Diagram of deletion of Node N is as shown
in Figure
58. Linked list is maintained on memory in the form
LIST (INFO, LINK, START,AVAIL)
When a node is deleted from LIST it will immediately return
its memory space to the AVAIL list. For easier processing, it
will be returned to the beginning of the AVAIL list as shown in
Figure.
59. Three pointer fields are changed as follows:
The nextpointer field of node A now points to node B, where node
N previously pointed.
The nextpointer field of N now points to the original first node in
the free pool where AVAIL previously pointed.
AVAIL now points to the deleted node N.
There are two special cases:
If the deleted node is the first node in the list, then START will
point to node B.
If the deleted node N is the last node in the list, the node A will
contain the NULL pointer.
60. Deletion Algorithm
All the deletion algorithms assume that the linked list is in
memory in the form LIST (INFO, LINK, START, AVAIL).
All the deletion algorithms will return the memory space of the
deleted node N to the beginning of the AVAIL list.
All algorithms will include the following pair of assignments,
where LOC is the location of the deleted node N:
LINK [LOC] := AVAIL and AVAIL := LOC
These two operations are pictured as shown in Figure
61. Deleting the Node Following a Given Node
Assume LIST be a linked list in memory. Suppose location LOC of a node
N in LIST is given or the location LOCP of the node preceding N is given
or when N is the first node, the LOCP=NULL is given.
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] [ Deletes first node]
Else:
Set LINK [LOCP]:=LINK[LOC] [Deletes node N]
[End of If Structure]
2. [Return deleted node to the AVAIL list.]
Set LINK[LOC]:=AVAIL and AVAIL:=LOC
3. Exit