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

Sorting Basics

1. Sorting arranges data in a particular order based on some parameter like value, count of factors, etc. Common sorting algorithms are selection sort and insertion sort. 2. To find the minimum cost to delete elements from an array, first sort the array in ascending order of deletion costs. Then delete elements from the end of the array. 3. To count the number of "noble" elements, i.e. elements whose count of distinct factors is greater than the element itself, sort the array and check each element to increment the count if it is noble. This takes O(nlogn) time.

Uploaded by

Akash Gupta
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)
13 views15 pages

Sorting Basics

1. Sorting arranges data in a particular order based on some parameter like value, count of factors, etc. Common sorting algorithms are selection sort and insertion sort. 2. To find the minimum cost to delete elements from an array, first sort the array in ascending order of deletion costs. Then delete elements from the end of the array. 3. To count the number of "noble" elements, i.e. elements whose count of distinct factors is greater than the element itself, sort the array and check each element to increment the count if it is noble. This takes O(nlogn) time.

Uploaded by

Akash Gupta
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

What is

sorting
Min cost to delete elements
count of noble elements
sorting Algo
selection and Insertion sort
sorting arrangement of data in a

particular order based on some

parameter

2 3 9 12 17 19 sorted in asc order


based on value

a 6 5 2 I 19 sorted in desc orde


based on value

I 13 9 8 12
t sorted in asc order
I t
count
of 1 I f based on count
factors of factors

Default asc order based on value


custom sort

easier
why sorting Searching becomes

Analysis
Readability

Inbuilt sort sort C


function
to
TC Ocn logan
X
delete I 2 1 4 7
delete 2 2 4 6
delete 4 4 4

TEE I

CAN 43
delete 4 4 2 1 7
delete 2 2 41 3
delete 1 I

Ans 11

a A I
delete 6 4 6 1 11
delete 4 4 I 5
delete 1 I L
Ans y
6 4 I
Q CH X X 3

delete 5 3 5 1 1 37 6
delete 3 3 I C 37 1
delete 1 I C 37 2

delete 3
ans

Order of deletion for min cost


to
smallest
biggest

10 2

10 2 2 10
delete 10 10 2 delete 2 2410
delete 2 2 delete

a
g
ca b das
Delete a a tb ctd
Delete b b ctd
Delete c c d
such a

I
a

sort Carr Cesc order

i
cat
i 3
I 2

2 4 6
lofty
H asr C n

reverse sort Carr ochlog n

int cost D
On
Ci it
for o ich
cost 1 arr Ci

1
return cost
TC Ochlogn
Sc O sorting
guy on algo space
Distinct

N G

ans 3
cant I I to Ig

ans i
ant to t I I
elem count of smaller

Yo
I
odor to

BE For
every element check it is noble
o d
int ans

for Ci o ith itt h


11 Aci is noble or not
Toon's
555 if8 Carr
jam
Cj Cars
get
i
SC O I

48 I Cnt t

b
if CA Ci ant ans t
7

2 Sort data Casc

Cnt CO i I I Y O TX i

2 5 0 3 3 6 33
to

C 3 Co Ers
ant
t t t t

sort Cary
nd g n

int ans 0

for ci o ith II
Cnt i

I if Aci Cnt Tc
ans t Ochlogn
se Ocsorting
algo
return ans

20
10
ans 3
ant
f at to f

am to s It
ans 5

ant htt s to b
ans 3

Et
cent i

Let's to
find those elements
try
where i cent

elem brew elem


if car
count i
Tc O
cologn
sort Carr
int ont O
0
if Carr o ans t

l ich
for Ci int

car cis arr Ci 2D


if i
Cnt

if Carr Ci ant
ans tt

y
g
cant 07227774
ans 0 43
Selection sort

Line

117AM
All students are in unassanged queue
Search for shortest student
in the list of arranged students
Keep doing process till whole
class is done

in Search
0 0 3 51g
i i 3
121615142
2 2 3
1311415162
3 3 3
20 4 5 63

E ma
fitfiitiity

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy