Sorting Dsa
Sorting Dsa
DB
Sorting
* Mege cost-optimized sorting also a
3 Divide
[3 4]
e
1 2 4 1 5 2 6
R
, , , , , , , ,
Entaration
o -Lett
?
sotoz
Pocode
13 x
high
1
1234 tow
Muge Sort Carl
low high)
>
h We mageSort (are low mid) ; , ,
01 2 34
"Call , midt ,high
"Carr low ,
mid , high);
3
,
Poomerge
code-merge Car ,mic hight
-
loo ,
3 1 ,2, 4 1 , 5 , 6 , 2 4
,
Ex , ,
3
tempS, Rightd
,
012345678
-
while (left mid 22 Right high)
4 5 6
1 ,1 , 2,3,7 2
,
, ,
5678
if Call (left) are (right)
01234
#31 eleE
left+
(Right) ;
· low mid
midt high temp add-
Right t;
for remaining portion after comparision
-comityo-
Time
while (left mid a
um"
Hein w
3divided te-
mp add
I
left
Car (lotS);
It ;
Sightt ;
temp,
get sorted array in
Snow we
in original all
should place
fol (i = low +high)
Sarr(i) = temp (i-low],
3
ot :
Section
*
-Eselect minimums & swap 3
1)
:
-N-2
fo
S
(i = 0
min
; icn-2 ; itH)
= i &timeity : Ont]
for (j i =
= jtt)
j(n-1 ;
it (arr (j) <all (min]) min = i
3
Swap Call [mins ,
aer (is)
3
othela
ab
* Bubble sort Sush mat element
Takes an
if on
& places
* Insertion sort -
its want
-
order
Best-0 (nE
worst -O(n)
worst z out
& Avg
Best 3d
Patterns - Nested Loop
for loop
"
inside the inner
print
"
(3) *
simple rattern
(n) observe symmetry Captional)