0% found this document useful (0 votes)
4 views

Sorting Dsa

The document discusses various sorting algorithms, including Merge Sort, Selection Sort, Bubble Sort, and Insertion Sort, detailing their processes and time complexities. It provides pseudocode for Merge Sort and outlines the steps involved in sorting an array. Additionally, it emphasizes the importance of understanding nested loops and patterns in algorithm design.

Uploaded by

Loudalasang
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)
4 views

Sorting Dsa

The document discusses various sorting algorithms, including Merge Sort, Selection Sort, Bubble Sort, and Insertion Sort, detailing their processes and time complexities. It provides pseudocode for Merge Sort and outlines the steps involved in sorting an array. Additionally, it emphasizes the importance of understanding nested loops and patterns in algorithm design.

Uploaded by

Loudalasang
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/ 6

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)

E if (low = high) return ;


(low t high/2,
mid =
, ,

>
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

MugeE right temp add (left)


.
;

#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 ;

while (Right mid) & (=


= OCNcogn)
temp add Care (right])
-
;

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

swap at mode o min mode [0-n-1)


swap
at 11 1 21 " (1-n -

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

count of lines or rows


For outer loop
no
(1) ,
to your
wls I connect them somehow
Innel focus
(2) for
11 on
,
,

for loop
"
inside the inner
print
"
(3) *
simple rattern
(n) observe symmetry Captional)

You might also like