minnay
no
Tln) 2T(%) + Om)+ on)
salaztiin s best injlementaluen
possible
Nok- Randes piust
g
Cuick soat nd þluot sclactien becawk fresabilut,
ts almost Close to
om)bt
that beat aug Cese tne mat m creaxu
uht is
Smallest elamu
n 9(n) tme
T)= TS)+ T)t On) t 9n)
Case com pae
to
0 AL2,3,4,5]D32,4,S]
whch is thue ?
d)C, =C2tn
L L,2, 3, 4, S .. hJ elmts
Lyn,m-, n-3 elemts
C C Cm. to Set L L2 wng lists in Asc
Kth Smallest elemnd in dshinetelenut
ponhtion
Smallet
elemt
hétum (a )
(0 ln)
te pantition (a,t,b)
lj-,k)
Tr)T
Kon Small
cle i K>1)
T)
TS)
T(3)
BC TC Kh Smallest
T)= T2)+n
= t(M3)+n
T(n)
-9)
Tn) TYS) tn
Ta)= T(M)+ h
loc TC Kh gma llest
Tln) = Tn-D+n
T(m-)+n
T(m-3) tn
J-)
29--2o24
Max- Mn Alyo
a,m] nelemenh
Max & min element o ag
method l
1o 8 20s1s-s|12 TI8
Alyo May min(a,m)
max= min = alh;
falis2 isn itt)
m-l mux= ali)
times
min = ali
astun Cmax,muin)
# Comþ to ind mw min tun
Best Case : (n-)
nst Cu 2ln-)=2n-2 cnd cd
Case
4 M-4
2 method-2) covnp
m: even 1 2 3 4 S
20 55 15-s218
|2
(pains)
max l0 max=20 15 18
min =8 min,852 2
etunn
3n2
2 3 4 S
8 20 515 -5 30
maxlo max,= 201S30
min=jomin,Ss
-5
m-*3
Alyo Max Minla,n)
fortt-3j tsn tta
max
else
nex, = a, min = 4L
l
mex max l
max>mex E, mex minl
min mun
minl<
else
max min aLi
DAndC max hin
RJ anay of m elemeds
1| a le
Ce h,max, min)
Max Min
Dlide
max min(mtl h, max, mi
Max Min llmmax ia)
>max) mar = max)
amaxt
min minl
Algo May Min (e h, max, min)
ar = min = a]j
else i (l==h-)
max = eaJ, min a |2 )
else
else
/ Diude
Maxmin(m, mex, mun )
Max min (m+,h, maxl, min
I/ Cen qen
(maxl y max) max mnax) ,
minlmn) min- minli
hatn l ma min)
m l,a, 8o o) mod 4
2cemp
mCI,4, 80 4o) mod 2
m(5,, s)md G
2 Com 20
m (3,4 m(sc3o) m(3i)
m(,2,d 4e) l cum
od m element
Tln): #{ Cemp to ndmaxmin
Tin)=
2T2)+2 m2
T(n) = 2T (2)+2
=2 [2Tlz2+2+2
= 2Tt) 2+2 +
= PT()+2°t 2242
2k T()+2k t24...42
9kT(k) + 2k*-2
"tn-2
Max Mn Bc AC
2n-2
Alyol
Algo2 1 no dd 3Ch-1)
t n is þowta 2
Min ComP best case
least ufs
Max comp bound
[min
cu
min comþ in costc)Cemnst in
Cass
Cemp)
(9: (Ohet is min Com to ind max min eg loelements
m-l= l00-|= 99
(9- lohat is com, to find
mumin loo element?
#
(9= ohet is min comp to find
mex mn
nin n elematsl
in oost case
2
h32
mexmin of m element
is max com to fnd
what
aray og m elmilo
0- what is Te to nd t4 lecdey in
at wtch is great
Leacey s element
aLit1] to an]?
) (nlog)
9 d) 9(n)
2330 Qo
4
6o 20So a li]eadn
alt]>all me eleet
lest elems
ead
dl
prnt (a In), an)
forl i-nl
a [n]
; 1--)
iftatJmax
Om eloment ulich u mitn
shat is Te to hotunn
drstnet
maximm moN minimUm
element ?
a) ollogn)
al to 8 36s7 419
3< 1o JOnt 3eemts
hotum mddt etenen
algo
m-l
Sated
Seal
0= mt)
ritun(m)
Alyo
else
natn n)
rstinn (-) I| un Suc Seaneh
2 3 4
15|1o|12|15 |20|22 |25]3o|3s
6 lo
natn (-)
X nst resent
in ng
Te o Binany Seane :a(log)
> wc 2 Avg Case
> Bc TC
Bin: Seanch
stiaight Bn Seanck
(min hec)
tte)
Search
Aotwn l-) Unsucc.
else
RBS ( m-1,);
RES (m+1,)
ele
hotunn m)
BCTCco0)
T(m): TC of Bin Seanch
T(n)= 1
T(/2) 41
in loc/Ac
Noke sha
lecase
ecense suinston call
No esetia elusee Stack spce 2eqine d
Tn) =S
T)+t
Binaag Seaneh moe Sesnelh
eat vatu
(x< a[m]
else X==a m]
rctum Cm)
lmyt
else >aIm,]
l=mt
else
rcturn tm
TC to Seanch elemt
>ohatis 6CCuence
| 2 3 4 J
Sonted
) Comporeto
the Code
mtT
t mtt
etse tmttatm=
else
ratunn lm)