Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Name - Poathmesh Sanjaugao Nfarp Reg. no.

2020BCS02
Page No. Roll no. BIy Date
************ ********* ********** *****

Psactical4
Aim Tmplement BincrsL Seasch and ind
S-leps tahen bu pbO0dam

Theotu Binany Sean ch s 0 Seaschto algorihng


Used in a Sostd aSG bu enecdedlu dividing
Oividirge
he Seasch inlesvau in halPhe Tdeof
of binca
binc
Seunch i to ure the inkbaocfonth he aoqu
Josed and ecuce ho ime Complo to O(Logn)

Aloosithm binasu Seasch (int al1,int be10tend,iri


int mid
Count= (ODnt + Fo6 ASsignmert Stod
iEend b e ount Countt f o Condiuyc
mid= (beg t endl2 3
CoUnt Count t D92fos Asianndtd
if (a Lnmic vo
Count Count | f o Condfion checs
Kehonmid t1
Count=(ount L s Fos enko
elreif (a[mid]<vod)
cound Count t . Eak Coneitfon check
Teuan binaxy Seaxch (amid+Lench al
Count( oontti FO6 eman ste

k **** *********
else
sefuon
binasy.Seasch( a, beg, mid-1 , val)s
Count=Count + 1 . Pos seurn Stat

eoen-15
Count = Count+1ubo. . Fot Tehuen shedt

Anollsys
ASSume Aosay Si20 to be
ThesePote TCn)= 6lgn
.TO) OClog h)
Poogsam
##include < stdio.hY
fnt binasuSe asch (int a [3 , inh beg, înt end ,nt al)
io mid
TP (end beg
mid Cbea + end )/2 5
P Ca [mid] == val)

geusn d t+1 3
else 1 (a Cmidl<val)
sehven binay Jeasch (a, mid + 1 , encd ,tal) 5
e lse
Cetutn binasgSeas ch (a, beg , mfd-1 , tol)

etusn 1
Dal
Page No.
*** ****************{ **************

main
int a IL1425,80 404L62,41, 10
int vall=L
iot n ST20OF (a)/m220f La fo)
iot Xer binckuJeaxdb la OD-LVa)
psintf U Thoelemendc of ho are
Pos
psin f " In flemento be Seaschod i -%cva
iP (ser = -1
prini n fleme rhat psered înhe as 3
else
peinf n Plemes în presest at ecdpostion oPatau
6etusn 0
Output
The elementr
Ihe of asa Oxe 14 25 30 404152 9
Elemodto be eash
Elemai1 pxeie otSpoation of axau
Lonclu.rto
Pso I eliroinater balF oP the 1 Paon rther
feaxchingby OSngho 6eulE of each Compastron.
Lonr emplouf KeruAive appuhacb which yequiser
Stack Space
k k************* % *( %****%**

You might also like