0% found this document useful (0 votes)
14 views15 pages

Ece Notes

ECE NOTES are indeed quite beneficial.

Uploaded by

stakeup05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views15 pages

Ece Notes

ECE NOTES are indeed quite beneficial.

Uploaded by

stakeup05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

5:43 b X M" DO Yo)5 l 17%

X Selection Sort - D.
geeksforgeeks.org
GEEKSFORGEEKS

Selection Sort - Data Structure and Algorithm Tutorials

Selection sort is a simple and efficient sorting algorithm that works by repeatedly selecting the smallest (or
largest) element from the unsorted portion of the list and moving it to the sorted portion of the list.

The algorithm repeatedly selects the smallest (or largest) element from the unsorted portion of the list and swaps
it with the first element of the unsorted part. This process is repeated for the remaining unsorted portion until the
entire list is sorted.

How does Selection Sort Algorithm work?


Lets consider the following array as an example: arrl] ={64, 25, 12, 22, 11}

First pass:

" For the first position in the sorted array, the whole array is traversed from index 0 to 4 sequentially. The first
position where 64 is stored presently, after traversing whole array it is clear that 11 is the lowest value.
" Thus, replace 64 with 11. After one iteration 11, which happens to be the least value in the array, tends to
appear in the first position of the sorted list.

Swapping Elements

6425 12 22 11
Position to hold Min ele
Min element

Selection Sort

Selection Sort Algorithm | Swapping 1st element with the minimum in array
Second Pass:

" For the second position, where 25 is present, again traverse the rest of the array in a sequential manner.
" After traversing, we found that 12 is the second lowest value in the array and it should appear at the
second place in the array, thus swap these values.

Swapping
Min eleme

11 25 122264
already sorted Positiont
next min

Selection Sort

Selection Sort Algorithm | swapping i=1 with the next minimum element

Third Pass:

" Now, for third place, where 25 is present again traverse the rest of the array and find the third least value
7:03 0 D o Vo) 5 l 5%

Bubble Sort - Data ...


X
geeksforgeeks.org
GEEKSFORGEEKS

Bubble Sort - Data Structure and Algorithm Tutorials


Bubble Sort is the simplest sortingalgorithm that works by repeatedly swapping the adjacent elements if they are
in the wrong order. This algorithm is not suitable for large data sets as its average and worst-case time complexity
is quite high.

Bubble Sort Algorithm

In Bubble Sort algorithm,

" traverse from left and compare adjacent elements and the higher one is placed at right side.
In this way, the largest element is moved to the rightmost end at first.
" This process is then continued to find the second largest and place it and so on until the data is sorted.

Recommended Practice
Bubble Sort
Iry It!
How does Bubble Sort Work?

Let us understand the working of bubble sort with the help of the following illustration:

Input: ar] = {6,0, 3, 5}

First Pass:

The largest element is placed in its correct position, ie.. the end of the array.

STEP

01 Placing the 1* largest element at Correct position

i=0 60T 3 5
4 4
i=1 06 3 5

i=2 O36 5
Sorted
0 35 6
Bubble sort

Bubble Sort Algorithm: Placing the largest element at correct position


Second Pass:

Place the second largest element at correct position

STEP

02 Placing 2nd largest element at Correct position

i=0 0356
3 5 6

O356
Sorted
Bubble sort

Bubble Sort Algorithm : Placing the second largest element at correct position

Third Pass:

Place the remaining two elements at their correct positions.

Placing 3 larcopenIn Appent at Correct position


5:45 b X" Do Yo)5 l 17%

X Insertion Sort -Dat...


geeksforgeeks.org
GEEKSFORGEEKS

Insertion Sort - Data Structure and Algorithm Tutorials


Insertion sort is a simple sorting algorithm that works by iteratively inserting each element of an unsorted list into
its correct position in a sorted portion of the list. It is a stable sorting algorithm, meaning that elements with equal
values maintain their relative order in the sorted output.

Insertion sort is like sorting playing cards in your hands. You split the cards into two groups: the sorted cards and
the unsorted cards. Then, you pick a card from the unsorted group and put it in the right place in the sorted group.

Insertion Sort Algorithm:


Insertion sort is a simple sorting algorithm that works by building a sorted array one element at a time. It is
considered an "in-place" sorting algorithm, meaning it doesn't require any additional memory space beyond the
original array.

Algorithm:

To achieve insertion sort, follow these steps:

" We have to start with second element of the array as first element in the array is assumed to be sorted.
Compare second element with the first element and check if the second element is smaller then swap them.
" Move to the third element and compare it with the second element, then the first element and swap as
necessary to put it in the correct position among the first three elements
Continue this process,comparing each element with the ones before it and swapping as needed to place it in
the correct position among the sorted elements.
Repeat until the entire array is sorted.

Working of Insertion Sort Algorithm:

Consider an array having elements: (23,1, 10, 5, 2

First Pass 23 110 5 2’23 1 10 5 2


Second Pass |23 1 10 5 2’1 23 10 5 2

Third Pass 23 105 2 110 235 2

Forth Pass 10 23 5 2 ’ 1 5 10 23 2
Fifth Pass 1 5 10 23|2 ’ 1 2 5 10 23

Insertion Sort
First Pass:

" Current elemnent is 23

"The first element in the array is assumed to be sorted.


"The sorted part until Oth index is : [23]

Second Pass:

Compare 1 with 23 (current elemnent with the sorted part).


" Since 1 is smaller, insert 1 before 23.
The sorted part until 1st index is: [1, 23]

Third Pass:

Compare 10 with1and 23 (current element with the sorted part),


Since 10 is greater than 1and smaller than 23, insert 10 between 1 and 23.
" The sorted part until 2nd index is: [1, 10, 23]

Fourth Pass:

" Compare 5 with1, 10, and 23 (current element with the sorted part).
" Since 5 is greater than 1 and smaller than 10, insert 5 between 1 and 10.
"The sorted part until 3rd index is: [1, 5, 10, 23]
Fifth Pass:

Compare 2 with 1,5, 10, and 23 (current element with the sorted part)
Since 2 is smaller than allelements in the sorted part, insert 2 at the beginning.

Open In App
5:47 b X" Vo) 5 16%L

X QuickSort - Data St. :


geeksforgeeks.org
GEEKSFORGEEKS

QuickSort - Data Structure and Algorithm Tutorials

QuickSort is a sorting algorithm based on the Divide and Conguer algorithmthat picks an element as a pivot
and partitions the given array around the picked pivot by placing the pivot in its correct position in the sorted
array.

How does QuickSort work?

The key process in quickSort is a partition). The target of partitions is to place the pivot (any element can be
chosen to be a pivot) at its correct position in the sorted array and put all smaller elements to the left of the
pivot, and all greater elements to the right of the pivot.

Partition is done recursively on each side of the pivot after the pivot is placed in its correct position and this
finally sorts the array.

{10, 80, 30, 90, 40, 50, (70)


Partition around
70 (Last element)
{10, 30, 40, (50) {90,80}
Partition around Partition around 80
50

{10, 30,9, 40}) {) (90}


Partition
around
40 {10, 30)
Partition
round 30
(10}

How Quicksort works

Recommended Practice
Quick Sort
IryIt!

Choice of Pivot:
There are many different choices for picking pivots.

" Always pick the first element as a pivot.


Always pick the last element as a pivot (implemented below)
Pick a random element as a pivot.
Pick the middle as the pivot.

Partition Algorithm:

The logic is simple, we start from the leftmost element and keep track of the index of smaller (or equal)
elements as i. While traversing, if we find a smaller element, we swap the current element with arr[J.
Otherwise, we ignore the current element.

Let us understand the working of partition and the Quick Sort algorithm with the help of the following example:

Consider: arr] = (10, 80, 30, 90, 40}.

Compare 10 with the pivot and as it is less than pivot arrange it accrodingly.

Pivot

10 80 30 90 40

10 <Pivot +Swap 10 with 10


Pivot
10 80 30 90 40
Quick Sort

Partition in QuickSort: Compare pivot with 10

Compare 80 with the pivot. It is greater than pivot.

Open In App
5:57 0Eb" o Vo) 56
LTº 15%

Q height and depth of a no..

swap data

12
11

before deletion

The depth of anode is the numberof


edges fromthe rootto the node. The
height of a node is the number of
edges from the node to thedeepest
leaf. The height of atree is a height of
the root.

https://www.andrew.cmu.edu »course

Binary Trees - andrew.cmu.ed


About featured snippets Feedback

GeeksforGeeks
https://www.geeksforgeeks.org» h..

Height and Depth of a node in aBinary


Tree
25 Sept 2023 - Height of a node K(of a Binary Tree) =
Number of edges in the longest path connecting Kto
any leaf node.

Discover Search Saved


6:40 M&$" 9 Yo) 50 g%

tds Towards Data Science X

Array Linked List

Strength Random Access (Fast Search Time) Fast Insertion/Deletion Time


Less memory needed per element Dynamic Size
Better cache locality Efficient memory
allocation/utilization
Weakness Slow Insertion/Deletion Time Slow Search Time
Fixed Size More memory needed per node as
Inefficient memory additional storage required for
allocation/utilization pointers

Linked Listsvs. Arrays. Easy to Visit >


Understand Guide | by Hermann...
Images may be subject to copyright. Learn more

Share Save

ARRAY LINKEDLISTS
1Arays are stored in contiguous
location
1Linked lists are not stored in
contiguous location
Linked-List Array-List Winner?
2 FLxed in size 2. Dynamie in size. Dyanic memory aocation Stasc merory alocafos lallocated
doced duirg nun fmso ng onpia tiTHl Depends
3. Memory is allocated at compile tine. 3. Memory is allocated at run time
4, Uses less memory than linked lists Masory sa gPows ard s k s as Meroy sie is set wfo the amay
4. Uses more memory because it stores ode eleeets sre crstestemond is crened in iocks of memory Depends
both data and the address of next node
5. Elements can be arecessed easily. 5.Element accessing requires the Fiárg the r ctenerts soquires he
nction to frsveese the iet usti ths
Eerments in an aay can be
traversal of whole linked list indsed les arxyutinil rssching Array-Lit
value ha been neched Olnl ut vu in constart tme On
6 Insertion and deletion operation takes 6 Insertion and deletion operation is
time faster Eciert n teertg ard deieting Easy to iert ard delete on the

data n sry svsain nCNOe n isa porfd Alsn tees tme to Linked-List
eposon later elenerts wen an
s GeeksforGeeks mesory
ndx i t e tenond

Linked List vs Array - Ge.. Undefined


Introdution To Data Structures Linked List Data Structur..
Array Vs. link list
Arrays Linked ist
SASIS roa
Fised se: Reúzing is expeesive Dytanic size ARRAY LTNKED LUST
cOMPAREsON
Inilios and Deltins ae Insertiona and Deletsneefficient: No
lcient: Elemerts ane uaally shefting Beske tts cbtet stoa Itis enorderet set
Rardoaconss i., efficintindexing No randomaxoess faad ruar ef cata campring a atabe
7Not suituhe So operatkns roquirin rarser et ceta eres
acoesung elements by ndes soch as
sorting
Speised turing Na reed to speiy
No nemory waste if the aray is full oe Since mencey is allocaed dynamicallyfacc
alwstfull; otherwise nay realt in to or noodj here ic no waxe of neary cecaricn ant kdatng eeation
Och eImory wave
Seuacntial asos is faset |Reoon Sequautial acocs is low [Reoa: Eleeats Sge acete tsert, locoton b toet pessan ansged
Elenents in contigous teory not in corigucus memocy locations) alocand datng corple uring ru me.
tire
Lecture Slides ByAdil Aslam
Order ef the Sered cTSethvey ored rordosy
Medium enerts

Lcessn e ret or rercerte Seoueetaly ssee, e.


What is a Linked List? Li... erert #CCEIBd, ia, Soecty Thaverse stating frsn the
the array isdx a fre rede in the t by the
bocriot penter.
Array Lin ked i t Inurticn and Slow rwiaty as Casar, t t ard utoast
Ariry is aoleti af ciectts o serilrLirka List is an ndrod olottnof sitng rered
da tipe deness efthe sane rype, ikh ae Genert

Arryip Lirkal List spets ogential Ascess Seasctig ry warh asd inas sar ar
easet
akg t ades, lke anoj far le
dietty nalrkad li, e ba sqaetay oercts

*
Discover Search Saved
6:43 O M Vo) 5G
LTE JT g%

IT TIME PASS - WordPress.com X

STACK QUEUE
1 Objects are inserted and removed at Objects are inserted and removed
th¿ same end. from different ends.
2 points
In stacks only one pointer is used. It
to the top of the stack.
In queues, two different pointers
are°used for front and rear ends.

3 In stacks, the last inserted object is


firstto come out.
In gueues, theobject inserted first
isfirst deleted.
4 Stacks follow Last In FirstOut (LIFO) Queues following First In First Out
order. (FIFO) Order.
5 Stack operations are called push and Queue operations are called
pop. enqueue and dequeue.
6 Stacks are visualized as vertical Queues are visualized as
eolections. horizontal collections.
Otion of dinner plates at a People standing in a file to board a
7wedding
Stack.
reception is an example of busis an example of queue.

What is stack in data structure? Visit >


Different between stack and...
Images may be subject to copyright. Learn more

Share Save

STACK QUEUE Distinguish between stack and queue


It represents the colection of Itrepresents the collection of elements
elements in tast in first out[FIFO in first in first out(O)
Ctjects a inseted nreoved t th Cjects are iserted and emoved troem drferet
sTe end caled Top of the stacka nts calied front and rear end
No STACK QUEUE
set opeation is caled Fush Operation set cperatioss caled equcue cpeaon

Deete opertur caled Foe operaton Deiete ooerats caed DeauuE.


racrte ssd ciesre t cp e nertketsc plcc st ror ind deke sie
h sack eteia fo waslags of mncry qurus there ewesage of memory spece. aks pace st free

epbonis an Studerts stardrg n aine at fes couter is an ha oed cee poiser aré atvo prter varuhlcs.
2:43 e Merny Nege n keie uec

Logest) 2éngesn
lnee s s i t ised ie hoeSe syseetiknce ieteeere
rocedt ob sharieg

Saies dcinlise at fec cuerkcy is an


YouTube Plc cor ipe
reocpte is nenpesck enpleofqee.

Difference between Stac.. Undefined


Difference between Stack &Queue
Terms Stack Queue
What Is The Difference B..
pefeitieAlincar data structure wih A liocar duta strucDure with a ondered
ondered collectica of elements that collectio of elemets chat are inserted an
are inseted and delesed from same cae end called frear jand delesed from
end calle top. her end called front.
Sie cd is used 0o insert and delete Dilerence between Stack & Qunue.
Suucture ef t one end

calledfoeL
Wocking UFO Last la Fin Ou) HFO Fst la First Cut)
tata
Principle
Variant Stack does noe hae variant Oueue has variants like cinculsr queue eae d
peiornity qcoe er n cat

Nnber of Caly cae poinner is used. It poines so for


Ia queue two differest painers ae used
font and rear ends.
the top otf stack.

etng

Undefined
What Is The Difference B..

Discover Search Saved


6:45 M D Yo) 50 l 9%

X What is Priority Qu...


From geeksforgeeks.org - d
GEEKSFORGEEKS

What is Priority Queue | Introduction to Priority Queue


Apriority queue is a type of queue that arranges elements based on their priority values. Elements with higher
priority values are typically retrieved before elements with lower priority values.

In a priority queue, each element has a priority value associated with it. When you add an element to the queue, it
is inserted in a position based on its priority value. For example, if you add an element with a high priority value to
a priority queue, it may be inserted near the front of the queue, while an element with a low priority value may be
inserted near the back.

Aviator
INSTANTGAME
INSTANT WINS!
There are several ways to implementa priority queue, including using an array, linked list, heap, or binary search
tree. Each method has its own advantages and disadvantages, and the best choice will depend on the specific
needs of your application.

Priority queues are often used in real-time systems, where the order in which elements are processed can have
significant consequences. They are also used in algorithms to improve their efficiencies, such as Dijkstra's
algorithm for finding the shortest path in a graph and the A* search algorithm for pathfinding.

Properties of Priority Queue


So, a priority Queue is an extension of the queue with the following properties.
" Every item has a priority associated with it.
" An element with high priority is dequeued before an element with low priority.
" If two elements have the same priority, they are served according to their order in the queue.

In the below priority queue, an element with a maximum ASCIl value will have the highest priority. The elements
with higher priority are served first.

Priority Queue
InitialQueue =()}
Operation Return value Queue Content
insert (C)
insert ( O) CO
insert ( D ) COD
remove ma> CD
insert () CDI
insert (N) CDIN
remove max N CDI
insert( G)
CDIG DG
Open In App
6:46 D Yo) 50 l 8%

X Abstract data type...


From geeksforgeeks.org - d
2. deQueue):

deQueue is used for deleting an item from the queue. An item will be deleted from the front of a Queue only if
there is atleast one item in the queue. It's time complexity is constant i.e 0(1).

If the Queue is empty it returns -1 in Array implementation and NULL in Linked List representation.

3. front():

front() is used to retrieve the starting element of the queue. It's time complexity is constant.

If the Queue is empty it returns -1 in Array implementation and NULL in Linked List representation.

4. rear():

rear() is used to retrieve the last element of the queue. This operation takes O(1) time complexity.

If the Queue is empty it returns -1 in Array implementation and NULL in Linked List representation.

For more details about the operations and their implementation please refer to the article about "Circular Queue"

Applications of Circular Queue:

" In a page replacement algorithm, a circular list of pages is maintained and when a page needs to be replaced,
the page in the front of the queue will be chosen.
Computer systems supply a holding area for maintaining communication between two processes or two
programs. This memory area is also known as a ring buffer.
" CPU Scheduling: In the Round-Robin scheduling algorithm, a circular queue is utilized to maintain processes
that are in a ready state.
" Inter-process communication: Circular queue can be used for communication between different processes.
" Resource allocation: In operating systems, circular queue is used for managing resources.

Real-time Applications of Circular Queue:


" Months in a year: Jan -> Feb -> March -> and so on upto Dec-> Jan ->
" Eating: Breakfast -> lunch -> snacks -> dinner -> breakfast -> and so on.
"Traffic Light is also a real-time application of circular queue.
" Clock 0s also a better example for the Circular Queue.

Advantages of Circular Queue:

" It provides a guick way to store FIFO data witha maximum size.
" Efficient utilization of the memory.
" Doesn't use dynamic memory.
" Simple implementation.
" Alloperations occur in O(1) constant time.

Disadvantages of Circular Queue:


" In acircular queue, the number of elements you can store is only as much as the queue length, you have to
know the maximum size beforehand.

" Some operations like deletion or insertion can be complex in circular queue.
" The implementation of some algorithms like priority queue can be difficult in circular queue.
" Circular queue has a fixed size, and when it is full, there is a risk of overflow if not managed properly.
" In the array implementation of Circular Queue, even though it has space to insert the elements it shows that the
Circular Queue is full and gives the wrong size in some cases.

Article Tags : DSAQueue

Recommended Articles

1. What is Circular Queue| Circular Queue meaning


2. Applications, Advantages and Disadvantages of Circular Doubly Linked List
3. Applications, Advantages and Disadvantages of Circular Linked List
4. Applications, Advantages and Disadvantages of Queue
5. Advantages of circular queue over linear queue
6. Applications, Advantages and Disadvantages of Matrix Data Structure
7. Applications, Advantages and Disadvantages of Hash Data Structure
6:49 &&"
and computer networks.

What is Tree?
A
tree data structure is a hierarchical data structure that consists of nodes connected by edges. Each node can
have multiple child nodes, but only one parent node. The topmost node in the tree is called the root node.

Google Workspace
Alexis

Worktogether
in real time with
live doc editing.
MDAD Sign up

Trees are often used to represent hierarchical data, such as file systems, XML documents, and organizational
charts.

Difference Between Graph and Tree

Feature Graph Tree

A
collection of nodes (vertices) and A hierarchical data structure consisting of nodes
Definition
edges, where edges connect nodes. connected by edges with a single root node.

Can have cycles (loops) and No cycles; connected structure with exactly one
Structure
disconnected components. path between any two nodes.

No root node; nodes may have


Root Node multiple parents or no parents at Has a designated root node that has no parent.
all.

Node Relationships between nodes are Parent-child relationship; each node (except the
Relationship arbitrary. root) has exactly one parent.

Each node can have any number of If there is n nodes then there would be n-1 number
Edges
edges. of edges

Traversal can be complex due to


Traversal Traversal is straightforward and can be done in
cycles and disconnected
Complexity linear time.
components.

Used in various scenarios like Commonly used for hierarchical data representation
Application social networks, maps, network like file systems, organization charts, HTML DOM,
optimization, etc. XML documents, etc.

Social networks, road networks,


Examples File systems, family trees, HTML DOM structure.
computer networks.

Key Differences Between Graph and Tree


" Cycles: Graphs can contain cycles, while trees cannot.
" Connectivity: Graphs can be disconnected (.e., have multiple components), while trees are always connected.
" Hierarchy: Trees have a hierarchical structure, with one vertex designated as the root. Graphs do not have this
hierarchical structure.
" Applications: Graphs are used in a wide variety of applications, such as social networks, transportation
networks, and computer science. Trees are often used in hierarchical data structures, such as file systems and
XML documents.

Article Tags:Difference Between DSA Graph Tree Trees

Recommended Articles

1. Difference between Tree edge and Back edge in graph


2. Overview of Graph, Trie, Segment Tree and Suffix Tree Data Structures
3. Connect a graph by Medges such that the graph does not contain any cycle and Bitwise AND of connected vertices
is maximum
4. Difference between General tree and Binary tree
5. Difference between Binary tree and B-tree
6. Difference between Btree and B+ tree
7. Difference between Spanning Tree Protocol (STP) and Rapid Spanning Tree Protocol (RSTP)
8. Difference between Binary Search Tree and AVL Tree

Open In App
6:51 " O Yo 5T l8%
and computer networks.

What is Tree?
A
tree data structure is a hierarchical data structure that consists of nodes connected by edges. Each node can
have multiple child nodes, but only one parent node. The topmost node in the tree is called the root node.

Google Workspace
Alexis

Worktogether
in real time with
live docediting.
MDAD Sign up

Trees are often used to represent hierarchical data, such as file systems, XML documents, and organizational
charts.

Difference Between Graph and Tree

Feature Graph Tree

A
collection of nodes (vertices) and A hierarchical data structure consisting of nodes
Definition
edges, where edges connect nodes. connected by edges with a single root node.

Can have cycles (loops) and No cycles; connected structure with exactly one
Structure
disconnected components. path between any two nodes.

No root node: nodes may have


Root Node multiple parents or no parents at Has a designated root node that has no parent.
all.

Node Relationships between nodes are Parent-child relationship; each node (except the
Relationship arbitrary. root) has exactly one parent.

Each node can have any number of If there is n nodes then there would be n-1 number
Edges
edges. of edges

Traversal can be complex due to


Traversal Traversal is straightforward and can be done in
cycles and disconnected
Complexity linear time.
components.

Used in various scenarios like Commonly used for hierarchical data representation
Application social networks, maps, network like file systems, organization charts, HTML DOM,
optimization, etc. XML documents, etc.

Social networks, road networks,


Examples File systems, family trees, HTML DOM structure.
computer networks.

Key Differences Between Graph and Tree


" Cycles: Graphs can contain cycles, while trees cannot.
" Connectivity: Graphs can be disconnected (.e., have multiple components), while trees are always connected.
" Hierarchy: Trees have a hierarchical structure, with one vertex designated as the root. Graphs do not have this
hierarchical structure.
" Applications: Graphs are used in a wide variety of applications, such as social networks, transportation
networks,and computer science. Trees are often used in hierarchical data structures, such as file systems and
XML documents.

Article Tags:Difference Between DSA Graph Tree Trees

Recommended Articles

1. Difference between Tree edge and Back edge in graph


2. Overview of Graph, Trie, Segment Tree and Suffix Tree Data Structures
3. Connect a graph by Medges such that the graph does not contain any cycle and Bitwise AND of connected vertices
0s maximum
4. Difference between General tree and Binary tree
5. Difference between Binary tree and B-tree
6. Difference between Btree and B+ tree
7. Difference between Spanning Tree Protocol (STP), and Rapid Spanning Tree ProtocoL (RSTP)
8. Difference between Binary Search Tree and AVL Tree
Open In App
6:56 G 9Yo 5 l 7%
X
Applications, Adva...
From geeksforgeeks.org - d
location of the vehicle on the route, with the next node pointing to the next location on the route.

Real-Life Application of Circular Linked Lists:

Xlaomi 14
co:ENGINtEatD WITH

Leica
Next-GSOptical
ptica Lens

Starting 2916/month
Buy Now

Xiaomi 14- Best Flagship Phone


Effortlessly capture details near and
far with Leica floating telephoto lens

"Music and Media Players: Circular linked lists can be used to implement playlists in music and media players.
Each node in the list can represent a song or media item, and the "next" pointer can point to the next song in
the playlist. When the end of the playlist is reached, the pointer can be set to the beginning of the list, creating
a circular structure that allows for continuous playback.
" Task Scheduling: Circular linked lists can be used to implement task scheduling algorithms, where each node
in the list represents a task and its priority. The "next" pointer can point to the next task in the queue, with the
end of the queue pointing back to the beginning to create a circular structure. This allows for a continuous loop
of task scheduling, where tasks are added and removed from the queue based on their priority.
"Cache Management: Circular linked lists can be used in cache management algorithms to manage the
replacement of cache entries. Each node in the list can represent a cache entry, with the "next" pointer pointing
to the next entry in the list. When the end of the list is reached, the pointer can be set to the beginning of the
list, creating a circular structure that allows for the replacement of older entries with newer ones.
" File System Management: Circular linked lists can be used in file system management to track the allocation of
disk space. Each node in the list can represent a block of disk space, with the "next" pointer pointing to the next
available block. When the end of the list is reached, the pointer can be set to the beginning of the list, creating a
circular structure that allows for the allocation and deallocation of disk space.

Advantages of Circular Linked Lists:


"Efficient operations: Since the last node of the list points back to the first node, circular linked lists can be
traversed quickly and efficiently. This makes them useful for applications that require frequent traversal, such
as queue and hash table implementations.
" Space efficiency: Circular linked lists can be more space efficient than other types of linked lists because they
do not require a separate pointer to keep track of the end of the list. This means that circular linked lists can be
more compact and take up less memory than other types of linked lists.
" Flexibility: The circular structure of the list allows for greater flexibility in certain applications. For example, a
circular linked list can be used to represent a ring or circular buffer, where new elements can be added and old
elements can be removed without having to shift the entire list.
Dynamic size: Circular linked lists can be dynamically sized, which means that nodes can be added or removed
from the list as needed. This makes them useful for applications where the size of the list may change
frequently, such as memory allocation and music or media players.
. Ease of implementation: Implementing circular linked lists is often simpler than implementing other types of
linked lists. This is because circular linked lists have a simple, circular structure that is easy to understand and
implement.

Disadvantages of Circular Linked Lists:

" Complexity: Circular linked lists can be more complex than other types of linked lists, especially when it comes
to algorithms for insertion and deletion operations. For example, determining the correct position for a new
node can be more difficult in a circular linked list than in a linear linked list.

" Memory leaks: If the pointers in a circular linked list are not managed properly, memory leaks can occur. This
happens when a node is removed from the list but its memory is not freed, leading to a buildup of unused
memory over time.
" Traversal can be more difficult: While traversal ofa circular linked list can be efficient, it can also be more
difficult than linear traversal, especially if the circular list has a complex structure. Traversing a circular linked
list requires careful management of the pointers to ensure that each node is visited exactly once.
" Lack of a natural end: The circular structure of the list can make it difficult to determine when the end of the
list has been reached. This can be a problem in certain applicatio ns, such as when processing a list of data in a
linear fashion.

Article Tags: Data Structures DSA Linked List circular linked list

RecommendedArticles Open In App


6:59 á Vo) 5G7%
LTE J

ADVERTISEMENT
X

A regular sparse matrix is a square matrix with a well-defined sparsity pattern, i.e., non-zero elements
occur in a well-defined pattern. The various types of regular sparse matrices are:

o Lower triangular regular sparse matrices


o Upper triangular regular sparse matrices
o Tri-diagonalregular sparse matrices
Lower triangular regular sparse matrices

ALower regular sparse matrix is the one where all elements above the main diagonal are zero value.
The following matrix is a lower triangular regular sparse matrix.
ADVERTISEMENT

1 0 00 0
9 -2 0 0 0
-2 1 3 0 0
3 1 -1 6 0
06 7 27

Lower Triangular
Matrix

Storing Lower triangular regular sparse matrices


ADVERTISEMENT

In alower triangular regular sparse matrix, the non-zero elements are stored in a 1-dimensional array
row by row.

At
A21 A22
A31 A32 A33
A41 A42 A43 A44
As1 ’As2 ’As3 As4 >Ass
6:59 Vo) 5G
LTE J 7%

Upper triangular regular sparse matrices


The Upper triangular regular sparse matrix is where allthe elements below the main diagonal are zero
value. Following matrix is the Upper triangular regular sparse matrix.

2 -1 -5 9 7
0 4 2 4 6
00 3 1 5
0 0 0 6 4
00 0 0 -2

Upper Triangular
Matrix

Storing Upper triangular regular sparse matrices


ADVERTISEMENT

an upper triangular regular sparse matrix, the non-zero elements are stored in a 1-dimensional
array column by column.

A11 A12 A13 A14 A15


Az2 Az4 Azs
A33 A34 A35
0 0 A A4s
0 Ass
Representation of upper traingular matrix A[5,5)

For example,The 5 by 5 lower triangular regular sparse matrix, as shown in the above figure, is stored
in one-dimensional array B is:
ADVERTISEMENT
6:59 o Vo) 56 6%

Here C[1] =A11, C[2] =A12, C[3] =A22, C[4] =A13,C [5] =A23C [6] =A33, C[7] =A14,C [8] =Az4,C [9)
=A34, C[10]= A44 C[11]=A15,C [12] =Az5 c [13] =Ag5 ,C [14] =Aq5, C[15] =A55
In order to calculate the total number of non-zero elements, we need to know the number of non-zero
elements in each column and then add them. Since, the number of non-zero elements in ith column is
i so the total number of non-zero elements in upper triangular regular sparse matrix of n columns is:
ADVERTISEMENT

1+2+ .+(n-1) +n=n(n+1)/2


Tri-diagonal regular sparse matrices

The tridiagonal regular sparse matrix where allnon-zero elements lie on one of the three diagonals,
the main diagonal above and below.

2 4 0 0 0
3 -1 5 0 0
06 2 1 0
00 1 -4 5
00 6 7

Tridiagonal Matrix

Storing Tri-diagonal regular sparse matrices


ADVERTISEMENT

In a tri-diagonal regular sparse matrix, allthe non-zero elements are stored in a 1-dimensional array
row by row.

A1 ’A12
A21 A23 0

A32 A33

A43 44 Aas
A

You might also like