0% found this document useful (0 votes)
10 views17 pages

Unit-Ii D AND C Concepts

The document discusses algorithms related to divide and conquer strategies, including sorting methods like merge sort and quicksort. It outlines the principles of breaking down problems into smaller subproblems, solving them independently, and combining the results. Additionally, it covers complexities and performance metrics associated with these algorithms.
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)
10 views17 pages

Unit-Ii D AND C Concepts

The document discusses algorithms related to divide and conquer strategies, including sorting methods like merge sort and quicksort. It outlines the principles of breaking down problems into smaller subproblems, solving them independently, and combining the results. Additionally, it covers complexities and performance metrics associated with these algorithms.
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/ 17

Divide and Con 9utr

umal plam
DandC a vêm PAobm

Smaller 8ubpADblma o 3ame pe a


( ai vioded n

OnqUnal PAobum (Div DE)

3hae Subpoblumi a 8owed ndspendntty (Con@Vre)


aL
Ju So uau oblaund oSmalliy Subp4oible ma
Soluon whwu(CoME E
Com bun d

ictoal upsen ta uo

Siy n
Poblumn

Sub Poblu
m 2 o
(Subpuobkmio
Sy a

9oulon t
Subpwblum 2
8oulo
SuhpLoplum

2alu on to ke
Not Dividz a/nd Con 9pur chrau .Sutt.
n wich eark ub Puobwns
Paalll Con puto on
Con be 80 wed Sumullano duily

+On-, n
Fg 8wn

Sou on
n> 0pp di vide and Con 9ur
oun

.+Gn

Oota .ta

+0n-)
an-j
So lion dot a t

ula in n:2
n:2

)+I Returen a
ACn)- aH
hueren
Mo2, r& , ,d
Sowe u yn 9
Jo tund d
d (n):"
Jn):
(n)=I,
- 2 , b-2 ,
SuL d
d
=>Case
3 Suh
22
a b (

Jurn Conpluu t o
8wmna Len of
)
wn hesS
Gmnal ulo uen Y do and Con 9jueY
TOO
n) 83ptmt or
TOn) o T ( ) di vidn th

mo PADbum
Runm
ip sty /b Combumun u
wm
Subpobum 8onbon

No OrdY o a oTn) dpendu on ta. Va uus

1e Cons.lan.b. a O n d b a n d e o1 dr otousth

hna ysu o amd C un qNasui's e orem

whu o >o Un ALLUT en Co


T
l a um
aLb
d
Tn) E a b
(n ogn)
ab

tY wm p or Duvidu and Can 9ucY


Bun) 2eodch

3 C c t Sort

leop Sort
5 Multipcahion o lage un gexs
6 Cloc e t paun and Con Ver ul PLoble ma
BunalSeaxch Callud as
dicYeas e b1 hal algtm
lgmi ma
Sor d
A (uunt olaor t m oSeacunq n a

nud Search elment Calld a KEY


Anay elumnb mt be m Sorhd oid (o und
woTksby 3 Con di usns had to be td

Semchui 9 a

(i) Compa kEY AmJ


Lmddla elumant

i match ocCYS
aua
Stp alq on tt
ELSE

4 kEYA m
upe at th Seackh pLoCOA Auut Si ve y

i h lyt Sub au a

FLSE
(tu) KEy AmJ
Aupeat te 8eatch pAoum Cusi vely
Un HhAght Sub auay
Pi ctoni al upus,en ta bon
hm-, AmJ, m
ALo
8eauch keu it
3eoch he i kE? FYDmJ
LJlo
eocam p
KEY 9 %,
Tnduc
A 30 11 98
1- A:0, u- m
m: Ltu
KEy?
ot8 LF
m- 4
LEy >An
Seasch n RSide
98 0
m
mH, u-8
KEY
m-136sb FJ
LEY>AmJJ
(Seath Rsidu)
106
T-3 mH (T) ,u:8
m

T)
SToP

&
8 ún
in Gkey - A mJ, sbp He algayithm amd a
th
kEYOwn d ot m) lo Co Lon
Algovithm non Re Cursive J
Alqm hm BsSo.n-J,)

o, n-1

whilk ( e u) do

m /]

un m

ebse k e AmJ)
L m-
eke i k> An])
mt1

based on 8lanolald Ne tho d 7


Mathe ma te al maysu
Cun linq Baato operakon)

Lp 8t nlthe number oelumun )


eom palua on
opesakon = Con paus on)eallud 3-way
a
Bosic

do es nwt
launa REy
3. CalCula wOrs cas ethe ala w hich eon
(made ( ) amd on thus
No me CompoL 8on
Com palu m Qlay s dividud each wm Sublaa
(n)- Cworst (L 1)+ n>

rJht
Amu u quises 1ov uft/ made wi'H
Sub a t Cmos st (1 = idd elmont
n e Coon paluaom
when n>)
madle

Nas& theore m.
Sowunq m
CuwOTst h) : Cworst La) +|
RR
e
map h wih Dand

Tn) aT (%) j (n)

d- o h)>1 = on Conslant
a , b 2,

a b
d
>1= Case ii matches

T Cn) n logn)
Cn logn)

( log n)=> wrst ease um


TCn) Com puiy

Adwan a 2
8eoch
Tum Conplau y o Bunaly Best 8eae hum 9
worst
alg or itm
Best AVg di adwan lgt
o (logn)e (ogn) t must be m
&or lz ol ordu
Mq Sayt
Con gu
que
applcaucn oDivi de
omd
Pendeet
esoupliom o n- by dividen
Sos Lx qLVem aay

wo halves Ao -amd A
m to
Th
urSivey amd merqun 9
SSorlun
nq each othem
Sorid one
wo Sm all 8or d avUuug unto a
Suin 9

* PStudo Co o

Alqoritm Murgesont (Alo. ..h-J)

Copy Ao.. b Bo
.h-t CLo
CoPy

Nurg &ert(e lo.. g-)


a)_
urg(B e,
70 70 &y
Alarithm Hax ge (BePJclo9alo Pr1)

o
whe b t <P and

B ciJ

elue

Coy 9-J Ak- PH9-3

RLp+-
Copy B .. P-J

Jee poun l r , as inhialged t pont to te s E


n

allays ben 9 mer9d

Jhe euman Poumz cl ale Coon ald and Hhe Smalll


that He
them LS adcded nuw alay a
elument u m Cl ned
Smalluy
o
* he
Jhe above Stp 1s upeat d until one of ke
txhaus td. and then The maune ng
umaun
aua
ekmun o the athe auay t
Copu d o nw auay
e 2
1 o l 5 o bo
A -3
n3 46J
3/

1 23
c1o 6
7 0 do2oo -12)|

C30 lo-g.os 60

Bo
n -0

C1 B 10
L50

AO6o A60
o30

A2 70

3 bo
A
odo36 10
A

2
70
bo
1o 1 20
35o
Mate maleal amat
arge Sovt algm1m utn Si ve Cal ai
ma de

Ruunen Ce Rlan

n>r Mn)- M (h)+ M(/%)


*

Cn
u m lim
or Comburmg
by t &ublak oo Sub at
tu8orlad 8ube
ut Sor li

8owe RR by Has hi eor em


Ch wkich n
O ,b d n) =

m
d Polunoma al or
O
n d 1
2ease'u mat chuJ
Mn)Ce (ogn)
nLogn)
Mn) 0n ogn

Tet
( boed
n>|
Mn) H % ) + mung (n)
MC) o n
Callalun 9 mn9e (n)

C om poli S on
botCoperauon
Cca ct l Con paul gn u. modi.
at each sup
which tte t laL numb er o e s . m
ooll
8tiu hCded to be ADCANd u. cdu tu d
ola

n Com pau,m
CmE
morq

NO RCurena. Roluon wu lun as

Cwors ()= Cooc (na+ (n-)

8owe

d n) =
n -n" la ke.
hghast dag
o 1
a b (a = 2 C e ii maktku)

Coorst (n) = © (n" Log)


(( Loqn)
oor stn)-
o Cn loqn)

Conpl o exq Soy u

8 est aveo 9e.

oCn Loga) |oh loyn) logn)


PatOn Phase
ort
uicl Sort Pai ion -ecchang Sort P kaae

Merg8ort divides t unpur s elemomE accos dum

theu posiu U +he a a

o tkei Vaue
divides em Lcoydun9
9uick sorb
ulcl
bu
ala on
n-placCe al oy tRn
ten
hut a 8able alqon tm
Dejn oMoy PA o . n -1
elwmen ota tvem
LA Ouns
Ls aci ewe Ls Pantt lon

elumen b beore Some


aSoa uen ooe all
8maller h a n
on S l pivot localin )
Phae posih all tta
and
OT eual o P i v o t elunont
lkan 8 an t A LsJ
ewmun posi

A- , AlsJ, A S3"J
.
.

An-
ALoJ.
pivot elkmont élumen z
elumenB lus
on A ST
un tke
poSihon
Sr tzd allau

e Sub allays odReelumon


C o m unu 80r lonq
amo olow vn sS
PALcedun.
C o n 9 u

PAoceduc
mm
a elmint catld
a pivot elumunt,om
P i ck
Pivot elwmont s he
he 9ivem auayNormally
tn St ocaion elemenE.
dona b4 SCans
2PatiLon
ne rom t u un deoc ed i
stabs wi t the Second elwaont
Scan
Scam 8kups tha eunan hat o3A Smaleer

Than
am the pivot Gmd 8bps onnst elknunt
Pivot elunen l-

*igt b un duze e d J

- 8 l i rom lost elwoon

eleman +Aat o a l than


gCom Slps te

pivot amd Sps n elnentE pivoE


ewwnt
3 8pPun Scan &bps, 3 saton aMAe
COse t i i Soap i J , J * cen unu
SCan n PCAJ

A:P al a
P 4PP
i Suap AiJ A J

Caselti) L So ap pivotelwnent eund ALJ|


al ole2
al ae
A 7P
<P
eunent A|
3 w a p pivot

No pivot element i n i Posi hion n ta


ST d lay NOw the L y PaH on n
io Subduays
Case ii) i - j J Va ue povn &d by i+ju
C al pivot e unont n chan
A and pivot ekauntJJ

A all
a P all al
P

Algonthmn GuckSort S )
pe
b o n o

( Y)
bownd

split posilbön
S p a ticin(Af l ) /s
a a

uick Sovt ( n SL.. s-)


Gu Ck Scnt (p S Y )

Algon tom paLlon[n f.. 1J)

pea
until A Lij4>p
Jupeot ieiH
ApeatjJ- wntil A ] P

Sunap (A Lil, A)
/undo lost Suaqp
wun i>
&oas(n I , ALj
AjJ)
Suwap (h SJ,
Aliwn J
o7CT)

P5 97
3

97

3 97
o3
P

3
L2
24317)

p:3

3
23 9

S41(T)
S

Sord wst 2 3 5 1 8

You might also like