20191cse008
20191cse008
2o19lcséoo&a BRaikunrah
ASsignmont; ol
what is an algohithm ?
of wnam biguauk insthudig
an algouthm
a n algomthm is a Seauence
eavied
a
40 Solvinq a PYoblem, i.e foY olainir9
Oud pul foY any leqitimade inpud in a finide arount o
Hime.
fx Plain tha thm wih an exam Pie?
plopeyles af an
algovi
PYoPevilies of algohi-thm
Inpu: 9hould accept 0 o nole inputs
oul Put: 9tould pladuce a least one out pu
9hould tasnAfo1m he
esfect IveneNs: evelu instlution
S.stop
PSe Udo code
8P gin
indpud a, b
9um-atb
PYind Sum
END
A019lcs¬00Ra
a. i 1,Sum-0
.foY i1 is -n
Sum:Sun+
S pispiay sum
6 The Space completiHy 0l algo1ithm is on)
fabhon
vek urn a
Onlya bo th
situation siHuatlonA
uap Poind Ho
Pnclement
MIN 1o
is Sy led.
Reeal
edil is ff(ntiJeAlimin)
ReSiet ion son LA n] iminÍ
eument of
find the micdle
ue
Value end-Valuela
elemd fourd.and
indey u
tuin cnd-Value= mitle
I f mi dd le-
Ve with
Olucmon!,cau
hi funtdion
R 3 1f midd
le >
stat -value
aiHh Stat-valae
.Cau the fund jon
eunands
Stepy1f middle <
midd le
dRSexH.
Bin suoNh
SO 11ed elument
oUdPue
ovWCiT to aN[n] ovey he atyy
See 1Tlerade o n t Pledesso I
eumnt
Compaut th cuwent mfDl
i1
sralle y than pye d ecessov,co
i f tho key is r o e ke gveadey ewnoat
ae
eumentbefove
t oothu Lements,
9 Pace fov the Swapre d e
moke
Position P Ho
with hupof
8olqicseoRO 4ths
a nead flow diagyam eXPlain
algov ithm desion
and aralysis PYOceAs
DiscuA) tha Vbrious91ge o/ algolithm des190
ond OAygi
osatys usro
low Chod.
mettad the PYattetn
pecide on:
Compudatio ral miaN.
eXat VAaPPlaxcinale
sloving agoVithm 8
Hechnidiue.
Desim an algoYihmk-
PYove covYecnesk
0
Aral 920 tha alSothm
code Hhuaugot t
ugdeslandi proble eduuuy do
uncevstand
tht PYoblem
www oy ina
N Phase on
CChino wOVd geromiC geavence.
Voad in tha vefevenre
9cauhirefo
uht rfor
o8hond
Desclibe ha 6landd algoli thm for find irg he birty fotm
Of a posiHive decimalinte jern
a) ergtish
|a pseudo Code
iy form vepRenla!ion Algo/ithm
o)Tnpul num beY
oV(i i-1,iz:0;i--)
PY inkf t1d ,ali])
hd fov
end.
slyukuye .
Aexplain the vaiaus linian dat a
tha dak a
elumonts
eljatenct tinkud s
Acolled ion of linked ist 1one fo Y
euh Yer le) ,tat
adjacent. 4 o He tistA verlex
Co ntain an the yeylice A
wei ghledphb wlh nombe 1) assigned lo fdp
tha
gvaphA ov d igaph)
malii r Ctun be
glaph.an
adaund y
adylnt
jacenty toode of
yepekndethi YOw ,Co
, c o lmn
lurmn
veHer
of a laph, evely
list Yepvogntal ion may eithel contain
eitha contaln
Pn ad ja CenCy The
.The rude
rede ray inkad istist
a role objett tisl. This inked
tisl. his
veprOKnded as
d
H elevencey Ho a unkt
inked
to tfo
thouau Wont
Wert
a aljalendo
aijalent
d ata ov Ho
ta ale
llsB au rodes
Provides a
TD de.
Po9e
Qdja(enCy 5el mitigaBe a few o he challerges
h diHeV ent slead
thad irele
excep foY th
the adjacendy lis
verdiCs is Plovided
01 a tinked ist; a sel of adlang
SPDlgaph
aVe of en Used tov
adjacenty isl and se rodleb
bekween
o.1 th few ConnltionA
9019LcSCao&a
Define yeeb and thi eYmirolotieh Used in tees. i
a linked i61 nglead o
R a tYee dala Styuutuye Simil to
nert rode in d llniai PuGhion,
he
each rode Poirdiq 9imply to Saa exan
rodes TYee 18 exan Ple
ple o
o
of
eath tode poinda to a numbe Ve i9 auy of Yeh owPteynlire
0f veh
ron- ntaV dala sluudu ve. A dVee
astubiare in
a glaphial folm
ht hi
znthi eYayehial
evaYchial roduve o
a Rool Nooe.evely
1ee ave aloot
must aVe a lon!
RooTh fivslr ivst rode is caluled
node tink,
eluween any two rocb
betueenany two
Connutiq
eleIn tvee da strutiuve,the
N rode tha Ve
/e w l be
will inun
roX inuum
be rot
POunt al chi ld
rode iS caued
descendan ol any
T l h i rnde nhich is
estimte he ro of times
rode
fincl acbl40.3y) bj aPplying uclid) folnula
mithod in an algoYHhm
ionA i don in ecicliat douwn do
Rudad indet oVm mn (m,D
bassed o nchutkirg consecutIve
8cd(m ,n)
anb lucidb algyithm
inpul a-60, broy
oulpul gcd t6o,3u)-12
60:8 IR (2 ((0 -2yau+1a)
3q:120RO [Bu 8X1240)
phn Reroindey R 0 the G is
thedivisiov. b in1adt eawations
ComPaven consecutive indegey chukirg indgel algovithm.The eucliads
foVmu la wil takes les comput e ime Because ind egey 4goYithm
lwe sould uVe do ChOLR uhYe two Aumbe ale gettire e ame integeys
Hele we aYe indu he gcd o Hwo num beln Sam ple way
dividirg.
in bt
&a19LcscaaeoVunnirq tim.
3How does inpud Si3e and
one meaSuye ho input i'g
the most foYmou gen Se thi gi1e of
Pnpud Si3e- în of a
rathl ne implemendali on
measuved
ed in vefeven ce toa
tuyiq
Qgol ih m. compuley
instludion
Hat a
looking ao sirgle
sirgle
unaigime An opelal lion is a sime
bers togethi
Y, ol
looKI ng
10mg.3ucha d i n g lwo m deleiminte
taue inan aYyay ave used o
mttod ayunts
SShow holw Opevaon cowmnsand 8 p
count
.deleymine
tha
OfendionA
ime o a PYagram
10r Ret .lwoNe and aveYoge ease
Ho bel he metod to i noralysiae
s t r c tion
of
NThe mtod is one instfufto
SteP.count at time> one
utfod ,we Coun htime compteat4
ha time compiezity
agovithmîn his we will ty to find
eX ec inq -fotm Had
0 agovithm.
algoYithm 4o peybIm sauenceliel seTdh
SuPPOse ha ve
we one
9uf
SuPPose
the
he
e than we will tYy lotind out
atound olHime ekan
Ho
ime compieTity of thi s algovihm.
do Sml gorted 1istuhich feads
8egtCa3P he wovst case igabig
But if youy in fot is gau to blq sorfed
|to Compleeityof (otn). times ancd since
Ond y Gna
is t. the algovithm eXecutes Hhe inne V foY
elumok ths algoYithm Hetmirals.
t don' tave o swBch
hao' y he aveYoge Ease
eoge coeIn compulalioral Compleaitu
,
doThese
Biq-o roialiond
Omaga rolaBions
dimeor
Thuarotalion. uPPeV bound of the Yanni
rq
the
?4 ePesend Complexeity
S9-09rolal fonb
gives he
woVst co9e
the aigorí hm
g t h m . T h U A Hg
an eondi hion
is in Yevelbe Yst Caseb.
diny wOYS Cases
u h n he inaut elemuntsi.e
eXPlatnthaSami
by
Owth 9
whal 1s 0ldeV g1dut inCfêns
in CYeos ecuvjon
auso
sn. ex
10HoY log n,niognand time Yeav Yemart fofnthevalue of
cvease
This
of nn-Thts
value ofn in
ns abhthe Value wih he increag e
ekehauiol of algovihm
behauiolof algo. ovdel
olde of gYouwth.
8 TowTh.
Callld
(alll d
behauiou y is
Ctarge inthe
h
nlog n n tog n
The
h tavgok
lavaek Num
10 ChQLk
Whoatht Yan elemnt
an algor
ithm
wte
ite an ago
ave distincu
elwmenLA
araysid ot
P'nPut elumuna
eothk of distinek
Pudftul
d declou an aay
3 Tntiau3e an aay
dislinet e lemunth
4. eau o funttl0n fo ount
i1o 1
count vauahle and indiau3e
|9. pecladu a
end
ComPut irg/1 boran ce, jes
sev
algovithm fo
wYie an
Qun
algo1ithm