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

Java Program for Linear Search Algorithm, Lab Reports of Computer Science

The java code for implementing a linear search algorithm. The algorithm searches for an element in an array by iterating through each element from the beginning until the desired element is found or the end of the array is reached.

What you will learn

  • What happens when the desired element is not found in the array?
  • What is the purpose of the linear search algorithm in this Java code?
  • How does the Java code implement the linear search algorithm?

Typology: Lab Reports

2020/2021

Uploaded on 12/21/2022

vishwajittidke
vishwajittidke 🇮🇳

5 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Pnoctical
No.2
Oatc
G
22
Aim
VWiHe
o
pognom
for
Lineon
5conch
5o1twaoe
tauiced
Tova
Online
Compilen
Poognom
Code
Public
closs
Lineonseonchi
public
StotHcnt
lineanstanch
(int
onra
yC1,nx
int
n
Onraj.length
fon
Cin
iO,
i<n,
i++)
F
ConnayC1
)
petunn
3
netunn-1,
3
Public
static
void
main5tning
ang
sC3)
Tn
onna
yL1
f2,
4,0,
9,
int
x
1,
int
nesult
linean
5eanch
(onnaj
x
fCoesult
=-1)
Sjstem.out.pnintlo
C"Elemenl
nol
found'")
else
Sy5tem.out.printlh
Eleme
nd
found
at
idex:
psoH),
Output
Elemen+ou
nd
ot
index:
3 e
Conctusion:
Linean
5canch
is
ave
simple
5eaeehing
a40nih
m.T
cycles
+hmough
he
elemenls
unHl+he
9utyis
aund.
pf2

Partial preview of the text

Download Java Program for Linear Search Algorithm and more Lab Reports Computer Science in PDF only on Docsity!

Pnoctical No.

Oatc G 22

Aim VWiHe o pognom for Lineon 5conch

5o1twaoe tauiced Tova Online Compilen

Poognom Code

Public closs Lineonseonchi

public StotHcnt^ lineanstanch^ (int^ onra

yC1,nx

int n Onraj.length

fon Cin iO, i<n, i++)

F ConnayC1 ) petunn

3 netunn-1, 3 Public static void main5tning ang sC3)

Tn onna yL1 f2, 4,0, 9, int x 1, int nesult linean 5eanch (onnaj x fCoesult =-1) Sjstem.out.pnintlo C"Elemenl nol found'") else Sy5tem.out.printlh Eleme nd found at idex: psoH),

Output Elemen+ou nd ot index: 3 e

Conctusion: Linean (^) 5canch is (^) ave simple 5eaeehing a40nih m.T cycles +hmough he elemenls unHl+he 9utyis aund.

clASSMAte Page

Paacicol No.

Aim Woite a pnoqnam fon linear 5eanch.

so-tuoaee Nequined Java Online CAmpilen heon incan 6eaech is a5equenfio lseandhing

alaaiaithm wheme westant rom one end and check evceny elemeq offhe lisl un he desiol

elemraE is fauad

Alganinm sbepiTnavense he amnay 54p Mateb he keyelemeat uith anayee

srpaTEe ekmat is fauacl, hetuna h

inde x posiHor 4t heenm element slkpAI£ kyelemendt is not ound,ndunA- Pnoqaam Cocde

puble class Linean Seanch i

public satia iatlineanseanchlintaneayl,int z)

iatnEaoma leng

fonini=o, in, itHL

Elaeas i]sx

neunn i DeHino-1,

publicstatia vaid mainlstaing anqsC1)

2in annayI1e 2, 4,01,9t

iat x =

ot aesult= ineanseanCh (anay x

5ysam.oulpniaHKCclemaal naf faund");

else

ystem.out.pnintlaEkeaen found atindexithsu

Ouput Flemeat found aB indax: 3

conclu6 (^) iom (^) Linean (^) seanch (^) 1S a veoy (^) simple (^) seanching (^) ayordho- t cycles throough the elements untIthe gueny 15foundh