You are on page 1of 25

Dote

Page No.
EXPERI HEMT

Aitw
rmptemeht S e-tLetiOtusore Bu-bb(e Sore, -Tr,sertion sore,
sere, CLUiCFv Herge-
Heap gore qhh0W a-L cc data— Stru-ctU>-L

S o cot-ce code

// Sore
# include iosereatYL>
usinæ namespace std
void se.UoEionSore Cine h) C
For ( inc co
0
=1
For C J++)
(qrrcjJ < Qrr c m'ih-jdxJ)
min —jdx 9

swap C arr Crnih-idxJ , qrrCü);

void— CihC qrrCD iht h) C


ech Cint 1=0)
l/
cour << qrrLiJ
couE ehdl

ihE main C) C
ALGORITHH FOR SELECT10N SORT

Set MIN to
lìsf:
SHQp AH}) v a.bz
Zncrernerrt— n /M 'to cterneh-t-
S Repeo-t On•til i.8
Date
Page No.
IhE = 3, 1,2, +22 J ;
ìnE n = sizeoç (Qhh)/ s)zeoÊ
(qrhC02),

Selectien Sore h),


SorteeL Qhha&l l/ '
prìhEAhra Carr, h )

re±ühtv O

// BUûBLE SORT
ÌhcLude
usine- name-cpacesel >

Vou bubbleSenE Ciht qrr CJ òhEm)C

f-Oh C J =O ;
( QrrCìJ > Qht-Cj+lJ ,

Void- prinEArra&- C ine art CO, InE n)


for C ihE )
qrrLiD
CouE encu
ALGORI THn FOR BV$BLE
èegih BabbleSorf: C

L t-7 lìsf=
lìs{ cì+1D
end
ehd Soh

end.
Dote
Page No.
ine main C
ine qrrCJ= l, g, 4, 2J,
sizeof Carr) sizeotC C QrrCOJ)

bubbleSorb Carr, h)
cowe<< " SortecL Nn

prinE/Qrhqy-Carr,

returrc o

1/ ZNSERTIOM soRT
# include <icstream >
usinth namespece std

void—ingehtie-nScrE Cine , ine n) C


Fer Cjnt-
Int Kew= arrcü;

while (j qrrCJU2
arrCj+lJ -z qrrCÜJ,

Qhr Key)
ALGORITHn FOR RTION soPT

rf- lé firs%-elemert-, if t-etarh


Pick hex-t elemer±—
compare e!ernefr+st +%eJ soHcd sub-tÈSE
4 Sh)œ QJ-L f%e- elernefls sub OSE
f} cun VOJJ-U- be soHerL
nseh+: the vaJJu-L,
6 R-Lpea± un+ìC lise IZ SOHcr&
Date
Page No.
vo)cL frìnEAfiÈQiJ C QrrC-0
Per c ÌnE e = 0 '
coaE QhhCi-) <<

ìnt- mq)n
ì ne QDhCD 4,23
n = sïzeee ;

Sere (
ìnser+ìen , h) )
c.-cu-E QhhCIY- \ h

prinEA rray c QFU n )

return o

// tlERCAE S0RT
# ìhcblde- <ìOGtreorn2
usino- namespace sto ,

ìnE m ÌnE È) {
void- mergeSere—C ine arrCD

;
in-e LLnIj / RC/)2J
HERGE SORT
ALGORITHrl FOR

_ SORTC am, kea, )


if beg < end-
See rn)ct (beg-Eenl) / z
—SORT com, Leg/ mid)
CORT ( / +1 eoU)
HEPOE SORT C end D
end of if
Cnr.L
Experiment :
Date
Page No.

LCU ąrt C z- + i-l


CJ=o; J < nz ; 0++)
RC/) = qhhCm

cc«nł

3
etse
arh Rqp

uhue U) [

uhț,le
Experiment

Dote
Poge No.

い 加0鬯 sc の ( を 4 な コ, ト工
(ユ
な く
の{
ⅲトm = 工子( 一工) / 2
me e50ゎ
去Cqrrt 工ル
mergeScr& ( Qた/ m+1/ r),
merge ( 0の
に/ 工/ m , れ) ・

亡「屮 ( あと0な , と の
v比p た ){ 〔 〕

( と ~ =0丿[ '<のノ早丿
乙 くく 乙くく
0吐ー 〔 〕

こ0 eれ
- (く と

を ル= 5冫 ト) / s /=00 み ( 4 な Co」丿ノ
, eo 戸 ( 0 わ

m erg eso に

く50 たとe 市 q
00ーく たた
Q

4ダ ( 0 ー わノ
p 戸n士れわ


eゆ 0 )
Dote

t/ CVICk soRr PageNo.

ìnclude <ìosfream>
asìny namespqce sta ;

ìnE partì+ìe•n-Cine QÈhCJ,


inE int- high ) [
pìvo+ = LhìghDz

ÈCCqrrCjJ < pìVOE)$L

Swap ( Qhr CIJ ChìghJ)


hetahPL ( i +1)

Yoìd- quÎcRSor±- Cine qmEJ / 'int hÈgh)C

int pi partitì&n( qrrr hì8h)


quÈc8SorE C lois/ pi -L),
qUÈcKSOH-C qrr , pi +1 , hjgh))

Void- prinEArraee C ìnE , ine h)

coue qrrtIJ
ce UE endL
FOR QUICK soRr

1 Choose {be highest jhdex val-ue hag pivo+.


-rake two voria61eSto po)sp-Elek Qfid right- of (ist eXcl-udih3
3. lef+ points +0 low •index
4. r)9hE points to -fhe high-
moverighE
while "a-Luc Lb PJVOE move (ef-+
7-- skep5 6 dou swap (epe and
teF+ right , is pivct
Date
PageNo.
/nE main [
ìnE 3, l/ g, f, 23
SizeoÊ Cam) / sizeoF
CqrhCoJ)

%uìcKSchE Carh O , n -l)


couE serted ahrQéL : \ h
prìhEArhQt&
(qrh, h)

return o'

11 HEAP SORT
# include
QSÌn9- marnespace st-ct

heap C QrhCJ ine i


iht targesB

Cr < h QrhCrJ -p QÈh C (argebt


(qrgeSE¯

ÙELTA@ suap ( arr CL), qrh ;


ALGORITHn FOR SORT

HeapSoh+—
euìld max Heqp Cart)
For i ¯ leng+hCory) 2
Skop C
heap —s)zê
Max (Orr, ID

(ctrl o Heap
h eup —size Cam) z lenal})
for I tcnalb (om)/2 1-0
Nax HeapiJt$ (arr, D
Date
Page No.
heQpiA}-Cqrh,
3

voìcU heapSoÈE C ine / ine


Cint h/2 —l
Carr , n

F-ch C ine n
swap Cqnt- co] ,qrr ci));

heapify- CQrr o );

"Oid- prin+A rhQY- C int QFECD inE tb) L

For C ìnE
coU± arrri)
11

endi)

tnaih () f-
QthCJ= C5/ 3/1 / g /+,2 J
ì ne
(qrFCOJ))
sizeoF Car» / Sizeof

heapSohE Carr, h )
"axHeapif'8(am/ )
tj8h.Fti)
L ? heap— Size and- CLJ > QrrC?J
targes& L
elSe
largest d
R ? heap-sizeCarra > orr
largese = R

suop Orr Clqe90-tJ


Hax heapiJy C arr, IQr9LDED
Dote
Poge No.
Cout Z< Sore Qrhqg
prjnEArrqy- CQhh, b ) ,

returtu o
Dote

Page No.
EXPERIMENT

Aim
rmplement- the Search in
hashih method

source code
include
# include < StT1h9 , h 7
# include <
# )hcLude < std lib•h2
usiny nQmespczcestd
define -SIZE 20

ine hoshTQb1eCNKIX-SIZEJ)
void Hash T qble ( in& Keg)
int index 1<0.8 rt0(-SlzE ,
C hash Table CihdemJ I
ihd ex Cihdex +1) •Z nAx-sjzE

hash Table Cindex) Rey

int- SearchJnCof-tqsWTable CihC Reg) {


index Key_ V. "AX—SIZE;
WhileC hashTa61eCindex ! = Røy) C
jhdex (index El) X-SIZC
LindexJ
return —l)
DELTA@
ex
Experiment :

Date
Page No.
inv maih ( ) {
memseE ( hashTQ6(e , SizeoF ( hqChTable))

For ( i —o to

i ht- search/<eys (o, g 203


CJ
for C In-e 1<3
) index search-Znto HQCh-TqCleesearch-Reg CCJ-.))
if ( index I
COLE Found f' << seurchK Cil << " a-E index
index endl
else C
<< sear nod endl

3
return— o )
Dote
Page No.
EXPERIHENT

Aim

Creake graplv and perfortyu DES


and ges vetsao
Source code
# include < st-dio.h>
ihcü.tde <

st-rueE C
iht desE
st-rue &Ncde nexe;
J;

Struct
struzt- OstNode he-ox;

Struct— Ctraph— C

int v •
StrucE AdList-e arra%,
J)

StrucE Ads Lis+Node neMAdjLisfNode (ih€ duty) C


$frunE Adj List-Node n ewNo de AOLls&Mode ma.Ltec

Csizeaß Cs&ruæ AdjLis€Node)'/


nebJN0de deg€ c dast ;
DeqNode —2heX& NULL
ret-urn new Node
Expertrne

Date
Page No.
Strur-E GraphL ct-eate Graph (ìht- V)
Graph Cstru,ce Groph+) tna-UocCsÌzeoÇ
Cstru-cEGraph));
Û hQph V V;

= AdLìseK) malloc ( sïzeof tsbtu-ct AdJLisE));

fÒh (int- È
8t-Qp)v
NUL
L)
he+üFtugmph

VOìcL d.-d.d-EdguC Strt.& GÈQPb graph.z, SFC int- d-L&D


Sf-ru-.ee adnCLiSfMecle neu$Nede = new LÈ5ENodeCd-zt)'/
...7 —-7 Q rhQY h.Lac(

ahhqg CShCJ. z heuNoc(Q)

h e UNode newAc!j LisENode Csrc);

newffode --7 nexe graph-- hy-ac(


—P q ma • = newNod.L

V0 id. phinEGFQph— C Ohah qrqpb) 'C


ìnt v ;
F-Oh ( V —O

Sfraz& Adj L/%/V0de p Crawl = 9 rapL h-Lad

phintf ( t' A (Oacehcce tÈse Of- rertex Ted hh v', V)}

printf ( p Crow/--9 des+);


p Crau I hexf
3
ALGORITHM FOR EFS TRAVERSAL
C Breadlh First— SearChD
I, rnitiaUzc ml noda +0 rady sinle CSTATUS
hocla A in QUEUE and chQhOC stn-üu
WoitiD$ stale C STA TUS z: 2)
3. RepcczEStep 4 QfhdS UDULQUEUE İS emp9—
4 Removc Ehe EronE nocle N op OUCUG Phocuz N Oha
(he Statü OJ N to C sta.,Qğ_, STATU5 3)
chqn

Add QUEUE CLII 06—N


ih skQdy (STATUS D ond chOhgc
10 ibc CSTATOS
CEnd step 3 ıoopJ
5 Exje

FOR OFS
DFS C Depth F İnçe Seqrch)
2 :nitiaüze alL node tö hecıd$ sta..ü C
2 Pusb starting hode OhtD STACV changc statü' b
wajtihg- 5tQ.Ü C STAT VS
3. ReperE Step 4 and step 5 UnHL empty
Rop the top Node N Of STACK, N and chany
b The proce&ed C 3)
Pu5h onto Stock ÜL tbe heighbourv$ N thQE UL
ih reod% senle CsTATVS
fbe Wortih9 StQ.f:cC
Qhd chonoe fhLÜv
STATUSz 2)
CEnd step 3 Loop2
ExıE
Dote
Page No.
print-p Cs' 'j)/

voicC bFSU Eil C struce Graph traph-,


ine V, it)E V15)tcd CJD t
Visitc.d CVJ = /
pr)nEf , V);

s fruc& Ad(/LE6N0de pCrQwC= trapæ -9 QhhQt4


C rJ-
While CpCraid[)
c vC5ifeU Cp Crawl-+ desE = = o)
DFSütiL Cgrqph- , pCrQldC—9de"
/
pChQÅJ[= p CrQl.Jl--9

void DES C St-rue Oraph graph— V)


C graph --2VJ
For C d= O) 1<9FQph V ; )++2
rlsiteZ =o
DFSUttL v, visited)'

void BPS ( st-rum Graph graph v) C


Visited- C graph --2 vD )
graph v ;
visited CiD = o
Page No.
itt queue C8rqph vJ/
int- front = o

visited C 10 = /
queueCreahJ

C re-ah)
ihE CC
= queue CfronE)
printe C
FronE +4
St-race LhsfNcde pCraj•JL= grqph qrhQ/ CuJ. h-ß-ad
C pCrQiJl) C

C pCr-Qi.Jl desfJ = / t/
queue Crear] pCrQwL
rear

p CrQb1L pCrauL next

ihE main C

struø-E CopapE graph— create G cv);


qdcL Oz ) '
Qdd Ec(9c Or

add , , 2)
Dote

Page No.

adcLGdffÜCgrapL / 2, o ) /
add Edge C 8rQph 3)
add C 8hqph 3, 3)

prin& G raph- Cgraph)


prihtf- c 't DBS troversqL store-ing from vertex 2 'l)

prihEA C BPS fravcrsaL seartirtff vertex 2 \n 'D/'


SFS

return o

You might also like