Adobe Scan 23 Nov 2024
Adobe Scan 23 Nov 2024
Date
VOUVA
Scalat.
Exbrmpe. AddiNon
cf too vatiobles::
ADD SCALAR CA, G) addiioo
Algonthm atithmeic
Petforn
WDescnption : Dumbebs
YotbioblesA ondA
IlInput:To Scolat
IlOukput: vatiob)e C Which holds the addiion of A
C<-A +B
etutn C
int aCnli
for (int i:o; i<n it+)
Cin>> ol]
Spoce Coropleityi
roblem-Soluing usingdotqComputet
to bold emparaty equiTesNhile e
oo Aino cesut
papgom_ 15S in eceution.
M T
Page No.:
yoUVA
Date:
A Natioble pabti
It iSdependent on the inpus Size.
It incudes memoy forr recuksion Sack, mefEetenced
VabiableS ebc
AlgonthmADD SCALARCA.B)
Descoipion:Petforrn atithne+ic add ition Of two
Dumbets
Input Tuso Scolat uatiables A gnde
/Qutput: vatiable C ANhich holds the addition of A
lond
C<-A + 8
etutn C:
numbeS
addition of two
SCalat reguires one
The to bold the cSult
location
algomthm 1s Thus
Constant the
Spoce Cormplexity Of this
bence Sp)
is as followS:
The pseudo - code
ASymptoti cuppet ind The asyra ptoti C The ezact $sym ptoic
k qiven by biq (owet bound is bebavior is done by
notahon qiven by orneya HhiS tbeBa notatior
Dototon
definedas
definedstis
Hghdestbound
T+ is
and tocoet bound and hhest bound is he
ppet ourd apJouek bound onon bes t of all the Wost
ppet hound oco alqoithm l's the Case imes that the
algonthm s he
tnount ofeast omeund oF aloithm Canaxe.
-most ime megured
-Hme eguimrd
Grrophia Example fo
fxample Biq- Theta
Gmophic foeomple Grmaphic
TmeY
fen)
no
C49cn)
aassMate
Date,
Page.
-Rabin Tesb
The Pse udoco de fo milet
T a" mod n
Composide "
solution:
step 1
- 2X 85. Thus
p 341 kE2 and q85
step2 X 2 Cqivên)
seo3= 985 mod g4: (9") x 2° mod g4
mod
ELx81g2 mod 34|= 8)9 2 mod 341
Sep 4
29 ood
Noo E 256 1
Conguet Maeinum
22Eeplain
prove
Divide
that is
and
cormpleeity is 3nl2-2 algonithm
LDivide ond Conquet apprnach hos thee Stens at
each leve) o£ recuSiooi
Divide theproblenn into numbet o Smallet uniks
called subpmblenS
Conguet (Solue) the 5ub-poblems meCut8ively
Comnbine tbe Solu+ioos of all the sub-prblemj int
a Soluion far the omginal poblem
mocimum and Minimumi
Let us conSidet [inmple poblem that can be solued
by the
diuide and Conguet. technique:
YOtVA
he blemiS to
valucLO a sct of
tDdthcDirnunandLiDiDum
n elccobs
Explonaticn:
9]Stroight MapMin requires 2(n-l) element Compabison
in the best ovetage and ewoonst cases
J By real izing +he Compotison of aci] mak is folse
imjpovement in o algonthm Cao be done:
yOUVA
a) Letps (n.aCl
af the problem
QLj)denote
atbitaty inShance
JiSt (ot).
Hete 'n'is the no: of elemenbsS the
ond Ne ate in+etestedin Anding the mairmum
minimum of the Lisk
Qnd
IF he iSt bos more han 2 elemen&SPhas to be
dvided into Smallet iAStonces'
WalueS 99 -5 -2 15 31 44
Tree DiagTom
M W
Page No.
YOUVA
Date:
19.&. 9
5
1.548, -5 L6.9.5o,-9
4 6
L2.33, -5 3.9.,2.28
Compleeity i
T Ten) geprcóenbs S no. then the mesuling
recubt ence relation iS
T¢n): T(Co12]+TCn|2]+2 n2)
1
nEIK fo boa
IWhen n is
q_powet
integek'k dhen
OF 2,
pasiive
Tn)= 2T(n/2)+2
32 (97(ol4)+2)+2
=4T (nj4)+4+2
+E 131<k-)K2i
=2k-1 I(2)
=2k-1+2K-2
tbot
9)Ezeploain metge Sort algorithrn ond Sho)
Libs Cormplezeity O(n logn)
AS Anothet eeomole of Divide and Conguet
invesigoteq Soochng algomthm thot has thenice
popetty thob in thÇ Nonst Cose iBS Compleeity
isOo lagn)
Ne 0sSune thooughöut thot the elements ake to b
Sorted in nondeoreasing 09det:
Alqomthm foor mebge dorti
if clow < high )+hen I|IA thete ate more thon ane
lelement
1.10
1.5
45 6 9lo
1.1 66
Fiq: Tree of calISs o£ Metye Saart (1.t0)
M
Tin)=a
2T(n)9)+ cn nz1,Ca constaot
Tin)= Sa
L2I(n!2) + cn nz 1.Ca conStant
Page tio
YoUVA
Algonithm DAndcep)
£ Smal(P) then retutn Stp)i
elSe
andonte
Di£fetence behween Las- VegaS
J8)
catlo algorn'thm
monte Catlo alg0mthn
Las Yegas Algonithn
Aspecs |may prduee incog
Aleway S Corecb
re[uibs
Corsectness
Non-zeto bus bounded
zeto cettor pmbability Can
on
porohalitl: oflenbé meduced)
both Cosirecknels
Randonizatia AfecbS nuDtme bukA£fecbs
not corecbness Qnd vntime
Role