You are on page 1of 5
lLinear And Binary Searching LINEAR AND BINARY SEARCHING Linena Seanceie, to atic _gath eleoment of an array is checked in Order from ower bound bo upper bound until the item is found or the upper bound is ached + Peedocode fnomple For indey s £ to 50 IE nomes Cinder = “Aman” Then Pint * Found” End it Ende . [a Seanceme, —____ Rucpose of using bisory seat ding WE there are 10240 elements in on _orray Wen to aordr spcile value | teaus comporicon witl_be made bub binary scorching can do ame tach io by bine ond Css conmpicions: Sxploinchon of Birary Searching nee DARSosacosoa Question : Pick “Present if bo ws 19 the onay We Find the mid value Cose 1+ QDoko is ak nid position ose 2 + Doto < value ak mid psihon cose 3+ Dake > Value at mid position ee Pode Ps fetes besos fs fe] u 60 > 47 So aM the values tit cRement’ © ase aot cequited aa So aM the values tit cRement’ © ase aot cequited IP the value tequired 15 > eid value then Lowesbound + midpaint +2 So ekment 89 ond 10 is cok ceqpical IF the volue fequirel 15 < mid value then Upperboand midpoint 4 bo= 60 Priok Present Preudocde Exompht Uoperbound 2 10 Rowerboany 2 Wekufound « Fale Nok wbst 2 False While valuefand = False AND Notisist = Folce Midpoint s Lat (pgerboor?d + Qownsbad (2) tf Rong * * ») VE Numbers C midpoist = 60 Trea Voluefound 5 Tuc Else IE twumbers C midpoint) < Go Thea upperbord + midpoint = 4 ase Dower bond « Midpant +L Eadie \E Rowerbound > upperbound Then ae Mee Ten Notinbst 2 Trac nate Snait Enducbile. IF volecfard 2 True Then Reink + Pesent * Ele Park * The velue is od- in the Od” l€ngtl Epic tab on erry ceeds to be sorted befare 0 bicary search ofgpritinen wor be sel? + Wr doese’t check every volne + Re oidpoint is the middle clement, not the oumericel volue + When the higher or Raver clhmants of discarded they wil nat be higles [Souses clement + Metight discord the wbce pe one fedking Re INOTE : ArtreweT Ouestrow 28 and 42 (c) Cd)

You might also like