DS - Practical - 1
DS - Practical - 1
SR. OF OF PAGE
NO. PERFORME SUBMISsION NO.
RS
Program to implement 21/10/21 21/10/21
binguY SecULch
Sincony seaLdnis secndh alaonith Bnat ods
the posihon o a tnqet vaee uithun sonted unau
Binunu Secacn_companes the thqet value to the middle
elemenE o the anau
if CaLi keuy)
Thenpanint Elem.ent
tOund
Laq
3n t 5
cIASSMAte
Dete
Pugo
20 +oLEL
inme camplexuhs 3n 5
a Lmid = keu4
then aq
pnint elenaent found.
5 ifCaCmicl> key)
then set high mid-
else
loL mid
flaq=o)
paint Element not ound
Concusion
n this paachca we enned hoo)secnching
aethods linean seanch and bincy seanch and theia
thein
imple.mentationcnc cuqoatha
File Edit View Git Project Build Debug Test Analyze Tools Extensions Window Help Full Screen Search (Ctrl-Q LC
linear_search_assignment.c X
Miscellaneous Files (Global Scope) 9 main0
scanf("%d", an);
printf("Enter the %d elements of the 1ist: ", n); 1/Taking in the elements of the array from the user
18 for (i = e; i < n; i++)
11
scanf("%d", 8list[i])
13
14 printf("Enter the element you are searching for:"); //Taking in the value to be searched from the user
15 scanf("%d", &s);
16
17 for (i 0 ; i < n; i++) //Linear search
18
19 if (s == list [i]) //Checking if the value of s matches any of the values from the array
26
25 if (i ==
n)
26 printf("Given element not found in the list") ;
27 getch();
28
linear_search_assignment.c
:\Users \AkRoz \ source\repos \DS> l ink.exe linear_search_assignment .obj
Microsoft (R) Incremental Linker Version 14.29.30136.0
Copyright (C) Microsoft Corporation . All rights reserved.
C: \Users\AkRoz\source\repos\DS>binarysearch.exe
Enter number of elements
11
Enter 11 integers
5 10 12 21 27 30 52 77 78 89 91
Enter value to find
89
89 found at location 1.
C:
\Users\AkRoz\source\repos \DS>binarysearch.exe
Enter number of elements
11
Enter 11 integers
5 10 12 21 27 30 52 77 78 89 91
Enter value to find
10
10 found at location 2.
11
Enter 11 integers
5 10 12 21 27 30 52 77 78 89 91
Enter value to find
125
Sorry, Not found! 125 is not present in the list.
4:40 PM
Type here to search Desktop 30°C 10/30o/2021
Page No
YouvA
Dato
20uOLL
Linea SeaxchDay Kuun
sEgSCAKCECLC,NITeM)
Einclude <stdio:h>
VOLd
Secrca
a t a a l 20S13e Sige S
Eatez tne s3e
Eater 5-elewents 3
o O,<5,1t)
ScenCZ &cATCiD,
oYiO ik S F
b<5,2
seahch ag+C))
2 -F
2 2<9
painEECElementou HÉ3
a t .dTncdesi)
2 3 3<5 V
Cies s13e
pmintCGiven Element nat
faund"
Lizra Chaanit
2040Lt
SORT
5 o12 21 27 90 S2 -7 73 89
Isuadexo 23 SG 78 9 1o
LO
L
When Secmch E 2
loaatim 12
8 fotund a t
LhenScanch=10,
OJowndat at loccdi.on2
LOhea Seanch=1 2 S
scanf CY.d"aseha Ci
93int C Entethe vaulue to seanch \n
aunt C d", seanch)
low a O
hiqn n-
micl= low +hiqh)/2
Seanch- S9
cohile CCElo )-Tue
iCcounau Cs] 8 )
ie, if C30<89)
lo S+|
mica CGALo)/2
=8
Cancuy Ce3<8q)
i,e C148)
DLd= 19/2
tohile CG<=lo -
iC89<3) -False
else fCaiauC9= se.cmch)-TLce
else f CEq 8 ) Taue
39 ound at lacahion Cnid +) L
Reseanch)= 0
uhile CoE10) T
ifCancu CSJSro)
C30 <Ie) F
else f C30-=ICo)-F
else
hiq h =S- =
u
mid =4/2=2
tohile Co4= H ) - T
rf 2 lo) F
elsei G2 = lo) -F
else
high 2-1
while CoL=) T
ifC5< 10)
low= O t =
mid (aD/2=
uhile CIZE) T
if CIO1o).
else i ( o : o ) T
lecobon (aaid L) -2
0aheh 125
ohilo Co4a to)
IC.3o<125)
latw
Cod- 8
ohle CG<=lo) T
1C78<125)
(MLcd a )
tulaile C<1o)
rCaS125)
Jow 9+ 1O
CAL [o)
Lahile Cfo<- LoD
C 125)
Jow
(at'd 10)
cohile CU<EI6)
loopfeaminated