Dsa UNIT-3
Dsa UNIT-3
SYLLABUS
Lists
https://www.geeksforgeeks.org/types-of-linked-list/
Circular linked list:
GARBAGE COLLECTION
• Together with a link list in memory a special list is maintain which consist
of unused memory size. This list which has its own pointer is called the list
of available space or the free storage list or the free pool. The OS of a
computer may periodically collect all the deleted space on to the free
storage list .Any technique which does this collection is called Garbage
collection.
• Garbage collection usually takes place in two steps. First the computer
runs through all lists, tagging those cells which are currently in use and
then the computer runs through the memory, collecting all untagged
space of onto the free storage list. The garbage collection may takes place
when there is only some amount of space or free storage list when the
CPU is idle or no and has time to do the collection.
• NEW AND DELETE
• https://www.javatpoint.com/garbage-collection-in-data-structure
Garbage Collection
• Garbage collection (GC) is a dynamic technique for memory management and heap
allocation that examines and identifies dead memory blocks before reallocating storage for
reuse.
• Garbage collection's primary goal is to reduce memory leaks. Garbage collection frees the
programmer from having to deallocate and return objects to the memory system manually.
• Garbage collection can account for a considerable amount of a program's total processing
time, and as a result, can have a significant impact on performance. Stack allocation, region
inference, memory ownership, and combinations of various techniques are examples of
related techniques.
• The basic principles of garbage collection are finding data objects in a program that cannot be
accessed in the future and reclaiming the resources used by those objects.
• Garbage collection does not often handle resources other than memory, such as network
sockets, database handles, user interaction windows, files, and device descriptors. Methods
for managing such resources, especially destructors, may be sufficient to manage memory
without the requirement for GC.
• Other resources can be associated with a memory sector in some GC systems, which, when
collected, causes the task of reclaiming these resources.
Linked stack
Linked stack
Linked stack
Linked queues
Linked queues
• Each node of a linked queue consists of two fields: data and
next(storing address of next node). The data field of each
node contains the assigned value, and the next points to
the node containing the next item in the queue.
• A linked queue consists of two pointers, i.e., the front
pointer and the rear pointer. The front pointer stores the
address of the first element of the queue, and the rear
pointer stores the address of the last element of the queue.
• Insertion is performed at the rear end, whereas deletion is
performed at the front end of the queue. If front and rear
both points to NULL, it signifies that the queue is empty.
Generalized List
• A Generalized Linked List L, is defined as a
finite sequence of n>=0 elements, l1, l2, l3, l4,
…, ln, such that li are either item or the list of
items. Thus L = (l1, l2, l3, l4, …, ln) where n is
total number of nodes in the list.
• To represent a list of items there are certain assumptions about the node
structure.
• Flag = 1 implies that down pointer exists
• Flag = 0 implies that next pointer exists
• Data means the item.
• Down pointer is the address of node which is down of the current node
• Next pointer is the address of node which is attached as the next node
Example of GLL {List representation}
( a, (b, c), d)
When first field is 0, it indicates that the second field is variable. If first field is 1
means the second field is a down pointer, means some list is starting.
https://www.geeksforgeeks.org/generalized-linked-list/
Example
Why Generalized Linked List?
• Generalized linked lists are used because
although the efficiency of polynomial
operations using linked list is good but still,
the disadvantage is that the linked list is
unable to use multiple variable polynomial
equation efficiently. It helps us to represent
multi-variable polynomial along with the list
of elements.
Sparse Matrix
• A matrix is a two-dimensional data object made of m
rows and n columns, therefore having total m x n
values. If most of the elements of the matrix have 0
value, then it is called a sparse matrix.
• Why to use Sparse Matrix instead of simple matrix ?
• Storage: There are lesser non-zero elements than zeros
and thus lesser memory can be used to store only
those elements.
• Computing time: Computing time can be saved by
logically designing a data structure traversing only non-
zero elements..
• Representing a sparse matrix by a 2D array leads to wastage of lots
of memory as zeroes in the matrix are of no use in most of the
cases.
• So, instead of storing zeroes with non-zero elements, we only store
non-zero elements. This means storing non-zero elements
with triples- (Row, Column, value).
Sparse Matrix and its representations