Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Pracico No.3: Binary Search Algorithm Implementation in C++, Lab Reports of Computer Science

The code and explanation of a binary search algorithm implemented in c++. The algorithm is designed to search for a specific number in an ascending ordered array and returns the position of the number if found. The document also includes some improvements and explanations for better understanding.

Typology: Lab Reports

2020/2021

Uploaded on 12/21/2022

vishwajittidke
vishwajittidke 🇮🇳

5 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Pracico
No.3
Dote7/t/22
Atim
Ne
o
pnoqnom
fon
Binan
5tonch
wone
Reau'ned
Java
Onltne
Compilen
501
Progeom
Code
include<iostncam>
usin
namespace s+d
int
ain)
intann
[i0,mum,finst
lastmiddle
cou
Enten
to
Elementslin
ascendinq
Ondee):
fonlio,
i<loi++)
Cin>
ann11,
Cout<<'lEnen
lement
t0
be
5eonch.
Cinz2num
as
middle
(insl+
las/23
while
(fins<
last)
?f(ann
[middle<num
else
S m
ddle4t
else
1f
(aon
[middle
num)
COut
\The
numben
<<nume
found
ot
Posilitn
<émidd
le
+1
break
else
lost-middle
midd
le
(finsB
last)/2
Cinst
lost)
Cou4<<nThe
number <numce"i6
nc
found
n
9'ven
Annay
COu<Ce
rd
netun
O
Out
put Enlen
lo
elemenislin.oscending
onder):
12 3
45
67 3
10
Enten
Element
o
be
seanch
The
numben
5
found
at
Pos1Hon
5
pf3
pf4

Partial preview of the text

Download Pracico No.3: Binary Search Algorithm Implementation in C++ and more Lab Reports Computer Science in PDF only on Docsity!

Pracico No. Dote7/t/ Atim Ne o pnoqnom fon Binan 5tonch 501 wone^ Reau'ned^ Java^ Onltne^ Compilen Progeom Code

include

intusin namespaceain)^ s+d

intann [i0,mum,finst lastmiddle

cou Enten to Elementslin ascendinq Ondee):

fonlio, i<loi++)

Cin> ann11,

Cout<<'lEnen lement t0 be 5eonch.

Cinz2num

as whilemiddle (fins<^ (insl+ last)las/ ?f(ann [middle<num

elseelse^ S1f^ (aonm [middle^ ddle4t num)

COut (^) \The numben (^) <<nume found ot <émidd le +1 Posilitn break else lost-middle

midd le (finsB last)/

Cinst lost)

Cou4<<nThe number <numce"i6 nc found n

9'ven Annay COu<Ce rd netun O

Out put Enlen lo elemenislin.oscending onder): 12 3 45 67 3 10

Enten Element o be seanch The numben 5 found at Pos1Hon 5

Conclu4ion The (^) nequinement ton a (^) binon9 deonc +o (^) be

penformed s^ +hat +he dafo should be sorhd n

Clocendinq onden

Abinan seanth con be^ imolt (^) mentcd

tnen usin an Henattve on

necunsive apprsach

DitecIASSMAte 7I Page

Oulput: Eatn^ 1o^ elemeals^ lin^ ascradinq^ onden))

123 45 G73 9 lo

Eaten Elkment^ o^ be^ seanch

The numben,^ SS^ found^ at^ Pasiion

Result

This alaanithmn^ Ards^ 4he^ pasiida^ otaarge

value uithin a Sonecd anea

Concluslaoi The aequicemeot^ on^ a^ binaey^ 6eaech^ tobe pentonmed is hat the data should be 60@ted a ascendinq aden Apinany 6eanch caa be implepmearo edhen uslaq an Eeaalive an nccunsice oppnaoh