0% found this document useful (0 votes)
10 views19 pages

Assignment 2

The document contains educational content related to graph theory and algorithms, including explanations of weighted graphs, directed and undirected graphs, breadth-first search (BFS), depth-first search (DFS), and topological sorting. It also discusses sorting algorithms such as selection sort and quick sort, along with examples and pseudocode. The institution mentioned is Shree L.R. Tiwari College of Engineering, which is accredited and affiliated with the University of Mumbai.

Uploaded by

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

Assignment 2

The document contains educational content related to graph theory and algorithms, including explanations of weighted graphs, directed and undirected graphs, breadth-first search (BFS), depth-first search (DFS), and topological sorting. It also discusses sorting algorithms such as selection sort and quick sort, along with examples and pseudocode. The institution mentioned is Shree L.R. Tiwari College of Engineering, which is accredited and affiliated with the University of Mumbai.

Uploaded by

tuba.khan7575
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Shree Rahul Education Society's (Regd.

)
SHREE L. R. TIWARI COLLEGE FENG
(Approved by AICTE &DTE, Govt. of Maharashtra State &Affiliated to Unive.
NAAC Accredited, ISO 9001:2015 Certified " DTE Code No. 3423" Mira

&uoxt answer tPe


an eza mple

Ane A weiguad qrauph is a speetau type ot graph wluYe each edgc


has a umelcal vaue esiqued to t.Tuis vcue Ps cold

Te wqut maybe stan , tene , or any etu meAur g

hre,tu nurerial vol a t da repreee ts t e

an eamp
a compte graph & yeuc gYaph pve

Ans Cownp ute qrapu s conneck


On unretd graph n wuicl a ch vert
to evey other

arpaCk
Were A,8 C ConneUe tD 0tLr too vertcu.
6.

Cyerc graphi

rom any node /vi HL


A qraPh conaiui ng a cloced pata cad aa woP ia
bacle to tslp porming
A B

eYe iF we stast rOm rtix A & txaveYse dern

Q3 Eplain asterenu bion dreekd & un direcRd qraph

DÝYecad qraph UndireRd graph


| edqes ave &peCpc AirerOn edq es co uot ave spec&hc cer

eopeud by arrow Not Yepre & u ay Qn arYOO

PO r cuilo cOn cpt tan be No pareet eild conupr

5 Moxe MMory Lsage compa red


to undeck gra pa
Shree Rahul Education Society's (Regd.)
SHREE L. R. TIWARI COLLEGE OF ENGINEERIN
(Approved by AlCTE &DTE, Govt. of Maharashtra State &Affiliated to University of Mumbai)
NAAC Accredited, 1SO 9001: 2015 Certified DTE Code No. 3423 -Mira Road

As An odfacen y és eA-toE is a way en o ich graph Can be


represerld wure weiyn ode A in
wn °st tot cotal nodes

A
X|X
B
X
-A B X

q1aph

6 Ep on BFS usitn n eg

Ans Breodta rst carca (BFS) is a qraph ee C91ch olqorthm


at root nod & ptores au
node
0ploYes 4ue? Unep ore
pends te g0a.
91aph

graA D E

AB, D, C, F, G
Shree Rahul Education Society's (Regd.)
SHREE L.R. TIWARI COLLEGE OF ENGI
(Approved by AICTE &DTE, Govt. of Maharashtra
NAAC Accredited, 1SO 9001 : 2015 Certified State
&Affiliated to Univers
" DTE Code No. 3423 Mira

Erptaln DFS wftn cn eaapu

DLqphu Rxst se0rch (DPS) is a graph search alqoihm


tuar starrs fon the xoot node & g0es deipRI & deeper
u l a node tha haLs no cudren is ncounroud. t e
|agoritm then backtracbs Yeing to e nocle tuat has not
Computely been aptore.
Ir s ?mpLmettd wmA stack

(6t)
B

AD, E,B,CF, GL

as Eptafn topoogial sortnq wira an caomple


Ans uar ord1rfug ot
Topoto gRcat torug g6apu is drCCHd,
2

1, 2, y,5,3
||O0|D0|| (00 I110 2
M
MALAYA
M
LA
A
A
4
2
M
A
A
2 2
A L
M
2
A M An
MALAYALAM" poY ultnan
wde wY
type ansuSCr LoMg
Road Mira 3423- No. Code DTE Certified
ENGINEER University
Mof Affilto
COLLEGE
iated OF Maharashtra
Sta&te TIWARI 2015 9001 Accredited. NAAC
Govtof. 1SODTE, AICTE&(Approved
L.R. SHREE by
(Regd.) Society's Education Ralhul Shree
Ep

tollooiug in o numbe
2 Conslder te 2) 32 ) 19 Re
CrOte a BST
I6,36, 08, N9 45,
13,Q5,

Ans

(36

32

Q3
(2at50) (2-4y)
Ans (2*a+5* b)^3 * (a-4*)^4
Shree Ralhul Education Society's (Regd.)
SHREE LR.TIWARI COLLEGE
(Approved by AICTE &DTE, Govt. of Maharashtra OF ENGINEER
State &Afiliated to
NAAC Acoredited, ISO 9001:2015 Certified DTE Code No. University of Mumb
3423- Mira Road

Eaptain pet r cluY tavexsL o a tree oit c2amPL


In post- 61dur tíaver SCu Lett subte s Tsaveiseo st)
pqut ubtre nut &tsty Yoot nod

Lupt- rlgut- Noce


HgovTth m
Sep 1:- epear sttp 2to u

SKP 3- pottorder (Tree rigur node)

saveosa
|dori D,t ,6, F ,C,A

54.89, 64,56,44, 333 4

AA' A[] 51,89, 64, 56,41 ,3334

Compaxe 54,8q ’ No Suwqp


Compave 3964

51,64, 8 5G47333

Compa yL 89 56’ swap

5t64,56, 84,44, 331


sored aNOy
fs tue uwtil his Peplat
posHon 2nd tn Ct epa &vaLe
Ans
eAamp an
ufth 40rY selecion Exptarn 66
333y 89,64,14, 56,54, A[1
89,333 64,74) 565t,
Compare
guop No ’ 4464, Compae
333 64,4A,
39, 54,56,
aP
sw ’56 64, pave Com
swap No54,64’ ompa
SLoQP No 333’ 89, Compare
333} 83, 44, 56
,64, 454
suap ’ 44
Compaxe
89,
Shree Rahul Education Society's (Regd.)
SHREE L.R. TIWARI COLLEGE OF ENGINEERT
(Approved by AlCTE &DTE,Govt of Maharashtra State &Afliated to University of Mumbai)
NAAC Accredited,ISO 9001 :2015 Certified - DTE Code No. 3423 - Mira Road

Considir an arras A= l84 ,9, 8 , 45,4o}


PASS PO S A[D] A[L] A[2] A(3] A(4]
4 1 39 q0
0
2 2 34
3 4 34 45

I0 PaM 1, Od the penrion POs of smau sr vale on


tu anray ie q. un soap A[2] & A[o)
TUs A[O] i sorled.
In pasa,fend t e p0iton POS o Ond emauetN e .

TUe Af4] is Sorted


3rd smuest val.
tn pa 3, end teponion pos ot

TUs A 2] fs Soted
etur Lme e korted.

Aqpslthm:
Selecron sort (Arr N)
&mauet (arr k, n, pos )
to N-I POS)
SRP 3:- LpLat fox 3= ktl to n (Pos]
SKP 3 swap A[] wth ar
St smau = Ax [
end of loop
Ser poS =J
end otof PF
(end oop)
Shp s '- Peturn POs
SCELLE

99Ezplaen auíck cor wltu an taa ple

Ans' Dulck sDt weTbs co

Ser tndX e rY eeme wt en array to Coc itt vaniab h

tDC =D, (at 0, fqur =n-)


staur from glt & sean array fro miguugt
Compafg each emeT pof ured by (oc
atyur)
a) contn a(toc]z a[rigu] pruor een orer pen
b) ar any pt t a [eoc] a Lrigr un tnrerchange
both
)

3 start rom st & sean Qrray rom atrqu


Comparfng eacla ch
bg loc
a lioc] >a[u]
b) at any pt îf a [loc] <a [atr barh
furerehng
Shree Rahul Education Society's (Regd.)
SHREE L. R. TIWARI COLLEGE OF ENGI
(Approved by AlCTE &DTE, Govt. of Maharashtra State &Afiliated to Univ
NAAC Accredited, ISO 9001:2015 Certified DTE Code No. 3423 -M

10 36 13

SUap them.
Sence a[toc 172 a rigur
24
36
Yéqur

Cence a[et] < a [tocJ ncream t t

18 36
rigur

&nce a[utt] < a [toc) en cxeamt t

86

Snee alut]7 a [oc] Cwap tue

36

Yiqurutt Len ce a (toc]< a [rigu encreanu w ngur


36
13
08Uug na probl vg ns ert te feuouofg valus tna hau

Avs
h(E,t) [tmodm +? ]modm

A=28
n(23,0) = 28 npd0 t0] mod I0
(3

-|

te 55
n(55, ) 5b Mod tO t.0] nod ro

55
Shree Rahul Education Society's (Regd.)
SHREE LB. TIWARI COLLEGE OF ENGINEER
(Approved by AlCTE &DTE, Govt. of Maharashtra State &Afliated to University of NMumb,
NAAC Accredited,1SO 9001:2015 Certified -DTE Code No. 3423 -Mira Road

SHp 3:

h(A1, o) = mod (dt o] mo i

55

h (64, 6) [64 modÔ + 0] mod 10

55-61 28
6

CoLC S0N
I0
h (n, 4) =ImDdip+1e]mod

-[ 55 -623
Tlo 3 4

h (roD) = o

55 -| 6728-J
2
29 730
>AfVa Af6]
2 2
BRg=
5
Vau <[U] A
30,35,yot ,29, 2s 15 []5,
, q, A Cat
3
same tor ago wrete algoi slare Btnant Ctug
atrcy given seard
Cn be can eeMenr
Q9 how 6platn 39.
2
28 64 55
6 4 3
2
64 -1 G5 -
9 =0)q0, h(
Shree Rahul Education Society's (Regd.)
SHREE L. B. TIWARI COLLEGEOF ENGINEERING
(Approved by AICTE &DTE, Govt. of Maharashtra State &Affiliated to University of Mumbai)
NAAC Accredited, ISO 9001 :2015 Certified DTE Code No. 3423- Mira Road

Mid- = 6-I 5
BLq =4L Rnd
2

A[41 < va

: we ove t rigut
eno 5

Me z 5t5 = 5
2

AL5]= Val

+ncuol <etdin

#dute Rze io0


Pu payfton (?ut a J» fu beg,twt ena)i
qule oYt (?ut a ] ,lut bl , u r end );
yotd maen ()

prntt ("

an array: ");
Pox? D, ?<n ?t+)
quie tort (art , om);
Purt( bd \t", arYCO) , h
fur parri kon |?ur a[]i?a bagu end

iqur

yiqt--)

ett (a (toc] >a


[rigur])
kmp = a [loc
a[toc] = a [riq w])
a [riq u) = Kmp

e it a[loc) <a (upt]


a(loc aCut):
Shree Rahul Education Society's (Regd.)
OF ENGINEERING
SHREE L.R. TIWARI COLLEGE& Affiliated Mumbai)
to University of
(Approved by AICTE &DTE, Govt. of Maharashtra State Road
NAACAccredited, 1SO 9001 :2015 Certified DTE Code No. 3423 " Mira

vold uick- Drt ( u al] ,ft beg , frend )


Loc

bc = parion (a, beg enol


9uick tort (as beg , loc-)
l) enc );
q u'cle- 0ra, loc t

You might also like