You are on page 1of 7

OMS Page No.

Date

PPS 2
Arcund Misra
21BAL05

Ans wey1

Loqic Divide va iate Smdle u arus


Lanquer when hove is 2rky oAeement
sa if0s Ma2X
Lonsbine keap__returNrq MaX_from
hem
Swb orraS nd combine hen

Psendaco sle
Int aox Ele i a t AL,iat laint Ihh) i
law bigh)
retuwn ALlowL
alse i
int mid (lou+ bgh )/2
iat Lmax hox Ele CA la
int Rrmexmox Ele CA, Midt igh
return MaX(LmaxRMax)

imeLomplextu 0(loq n)
OMS Page No.
Date

Answer 2

a Pseud Loqit Divile ond Ceaque

Pseucda coele
Poiin,_iat2_max Ss (int AC1 it n)1
1AtMaX Sun JNT MN, Stout =0,
Dd O wwrent 0 4curessun 0

Cwred s t ArL1
iECCAred sun MaNSum )1
MOK SuME Cuwvei Sum
STowt Cwre -n-0
ondi
i Ccwrei sum 0 ) 1
Cwevetsm-0

awrerd = í t l

veturn peir (stout end)

Te Camplexihu 0Ca) hecause ara_A_


trauewsad ony onc
OMS Page No
Date

LosicDiicle and Canque

Pscucda.cod
Pair ik,ial Max$S Cint ACL intn)
int maxSwm0 :0,erd-0 Luret 0 LSun=p_

COtm 0
else
Sum tE ALLL
i C Sn MxSum)
MOX SM2_CSUM

Gtout- Curvent
end iL

CSwm z0
Curent = i t |

retwn pov stout ed)

Ime complexiu DCa2


OMSPaga No
Date /

c)
Krudo code oi noradolqrih tov
MoXI MUm 5uwb orvy Sum_wowd

ols wovk in ds Scerorio

Pseudocole
Pair id,ind max $2 lias ACI id n1-
IndMaxSum:0,stout 0 prd:0,_wel D,Ls

LSuM t_ALi
tCcsum Mas Sum) /
MaKSwm cGum
stout Cwrend
end i

LSum 0
Lurvent Ei+

retuun Aav {stawt pnd


3

Tise Carpkxks 0 Cn)


OMS Page No.
Date

42 Legic all 6whunaus haicq pan-negaive


inteqos- ia he 4Y
Pseuolocoole
Vaio Max SS at ALI_it n)
iat stut4,end -0fleql:Hloq2=
Hor Li a 0 to )
if CALi<o 22 flagl=11i=Fn
endi flaq 2 -L

etsc i£ CA 20)i
loal= stot-
if Plaa2-) _

tloog=04

li anep lekiu OCa


OMS Pag No
Date

Answer3
Lagie Divich and LOnque

Pseudocde
in iNauat Cint ALI it o)i
tTLA
retun calc LA,T,O,0-D-
int_cole (it ALI id TCI, at Liat Ri-
af_Md COnt - 0

Mc L+R)/z
COunt t Colc CALLoicd)
COuat +E colcA,L Md+L R).
_Caut P1NeAT,L,d+L R)

refuwA Cow

iatpL d AC1 i T iat Liat Mid iat R){


int i: i k: cont:0

if (Arii4 ACT) T l- Ali+tl


alse Tlkttl AL+1
cOunt +E lmicd-i)

TdCanspexity hie ice rmiel-1) TÍL+1 =ALi++7


wsle Cik:R) i TIkH ALjt+1}
for i L to R1
AL11 TCi1
retwn (ont
OMS| Page No.
Date

Answer 44

Legi Pivide ond Conqer


Dividle probem ito Smalle swbphhes
Conauer Seluinq Subprobem vsidqvewso
Combing Sinqsauhion ot swbprolons to
aei soluion dov aviqure prd

Divide detices in submotricesd si N2:N


hen colewcteValues qiven be low) eursivey

aet b af tbh
Cd Lgh cetdg of+h

ablafg ced h are all euh modeices_ia e


ScOnaro

Peudo cocla

Stoving resut in C[7[


MMC AÇI1 BLICI L )
tor i 0 N
tov i0Ho N
CLL =0_
for k-0 N
C lt: ALilk1*KII{1

Compenh OCND

You might also like