0% found this document useful (0 votes)
11 views8 pages

Basic Algorithms

The document discusses two main searching algorithms: Linear Search and Binary Search. Linear Search is a straightforward method that checks each element sequentially, while Binary Search is more efficient but requires a sorted list. The document also includes examples and pseudocode for both algorithms.

Uploaded by

ankur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
11 views8 pages

Basic Algorithms

The document discusses two main searching algorithms: Linear Search and Binary Search. Linear Search is a straightforward method that checks each element sequentially, while Binary Search is more efficient but requires a sorted list. The document also includes examples and pseudocode for both algorithms.

Uploaded by

ankur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
© Basic AMaorithrns Seavehong:- Seavehing is a brocss of find am element Within the List of efermunts stored av any arlr ov “eermclaredty. vamdemby - = Seavching fs ctvicled ante uo categories Seavehing I Lintay Search v ° Binayy Search ey . sequemtial Seareh 4 Limeay “Search is the basic and Simple rethed of Seavching - 2. Binary “Seaveh takes Lesser time to Search an slemudt trom he Savtecl List of eLoment - Lineay Search i= Im Dineay Search, we access ead, element of om avrey one Ley one Sequembiolly amd Sex whether is chestved sherk cy not - it A Seaveh unig be umsucerssfut 2f at the 2lorments cle stved ekoment arc rot we accessed amd the found - Lineay Seaveh Algevithen?-4. 4 4 4 2 Of AIM, goto StehF * AALAT=% , goto stp he hta Goto step2 Print element % found at £ Print elemunt not found » Exit 2 NO wa @y @ WAP to Lincay ov Seqtumbiel Search br 4 chosived elemumbl tr a Set of, n-nuwervs « Pregram — thincludle < stctiorh> Void mame ) int w, 1, foumdzo, Gstrumlers [20] Seaveh_ elomwal brint$ (Even the numlzer of, elormumt in the array ")) Seamf(" Zl", 20) 3 Prnt$ ("Enter Soc number 0); fov(ieo; idn zat? Seam$(* Zid, Q Listnum bens Cidys Primt$(" Evter the Search lemme” Scamf (" Tk", % Seavth_ eek fr(teo; 2onj; itt) uf i Listnumbers PL] == Search element ) Foumd = 1 ; : 5 4 C-foumd.) printf Search allemnon 2 Jou L dhe prints (Search elomunt ts net found "): 3 @ Op? Evtu the snunnbser ca wlorrants th the ainras u Evter 4 number to Qo go 4o Enter the Search elemunt 20 e Seaych elemmunt 1» foun . 0 Bimayy Search — Binary Seavch is the most popular Sedych allgorttrmn: 9+ is ofticient amet alo ome of He amos F Grmmorly used techmiguss Yak ts used + Solve problems: > Bimavy Seaveh works only ma Sorted Set of eDormonts: To Use’ binary et He Gllichm anust First be Sorted: > Binay Search As a Sash Search abgeritryn with ram Ha Conphexity of OUegn)- 3 Binay Search algorithm wevks om the prvapte of Avide ama Conqui- Din Seasch Algeriion ——— Binayy Search Alger fan) - Uohite Geos hagh clo mid CC how + high ) WH Ve ALMA | bee yvetum mick | oo VIA Tmid] Bouse mick + 4 whe | | Nieygh Grmic- 4 Le ryedun NIL @. Exanmble? - Q, Find focahen ef Vekue 14 - [ie 4 [a] 2¢ Bt [a | [a ee ee © tow > frst osihion =} Lew = 6 High» Last position > high = ¢ Mie one Se : es Vel4 | ALmAd = 2¢ = \4726 high = wid - 4 Sele Q) lowe , Upglew High = 2 Mid = OFZ = Ved , ALmid] = 14 Ve ALmid 14 =AQT4I (4=!4 So eloment 14 £4 feud at Lacatin 1 - 28. Find Qocation of Value 14> ee aa See — to i]s ue] 42.) 44 ° Dart ete se lLoweo High= ¢ mid - ot bia = ott > Ve, mid =3 SB veu4, Atmidd> 2, > 44726 DB ow smid+ 1 =B3+2=4 Dmmd-4to os Faget DVve44, Atmidd= 42 > 44742 D> Baw = ancl +4 = S44 2G, lowsé , high = oy Mid: 6+ C = ATrmid = 44 ACs =44 AY 6 pesihon we hare 4y- OE, Q wAP +o Binary Seaveh fev a casived element Via Sek ef n-ne - Pap yan * _ th inclu dle Wahike C first Ce Rast) t A Carvey [mide J < Seard,) Sivot = midde rd elre if Carvey Cmidelle J== Search) 1 brntt ("Zd Founck at Location 7, b\w", Seendh , riddle +1) > breaks 5 ne fost = middie-4 > : middle -ivstt hasty | LC fst 7 hast ) PMTEC’ Mat focancl | Hel fs not present 2 the List.\n", Seoweh) * Ortbet ey te fests eae aummet! we member of ekamrents 4 DR See Re ® Srrkenedon-bo Freak. 9 Ente 5 inte ger> [e835 Be7 Yo Sie Ente vals +2 find Bo 30 taumd at Location 3. \

You might also like