0% found this document useful (0 votes)
168 views131 pages

19CS050 Shegar Dipti Sunil DSA Journal

Uploaded by

dipti shegar
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)
168 views131 pages

19CS050 Shegar Dipti Sunil DSA Journal

Uploaded by

dipti shegar
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/ 131

SECOND YEAR OF COMPUTER ENGINEERING

YEAR 2020-21
TERM – 02 (4 SEMESTER)
TH

Data Structures and Algorithms


Laboratory
Journal

Name : Shegar Dipti Sunil

Roll No : 19CS050 PRN NO : 72021322D


Class : SE-Comp-II

Batch :C

Subject : Data Structures and Algorithms Laboratory

Subject in-charge : Mr. Sumedh Dhengre

1
Index
Sr. Experiment Experiment Name Perform Submission Page
No No. date Date No.

1 A1 Consider telephone book 18/1/2021 25/1/2021 6-14


database of N clients.
Make use of a hash table
implementation to quickly
look up client‘s telephone
number. Make use of two
collision handling
techniques and compare
them using number of
comparisons required to
find a set of telephone
numbers.

2 A2 Implement all the 25/1/2021 1/2/2021 15-25


functions of a dictionary
(ADT) using hashing and
handle collisions using
chaining with / without
replacement. Data: Set of
(key, value) pairs, Keys
are mapped to values,
Keys must be
comparable, Keys must
be unique. Standard
Operations: Insert(key,
value), Find(key),
Delete(key).

3 B5 A book consists of 1/2/2021 8/2/2021 26-33


chapters, chapters
consist of sections and
sections consist of
subsections. Construct a
tree and print the nodes.
Find the time and space
requirements of your
method.

4 B6 Beginning with an empty 8/2/2021 15/2/2021 34-47


binary search tree,
Construct binary search
tree by inserting the

2
values in the order given.
After constructing a
binary tree - i. Insert new
node, ii. Find number of
nodes in longest path
from root, iii. Minimum
data value found in the
tree, iv. Change a tree so
that the roles of the left
and right pointers are
swapped at every node,
v. Search a value

5 B11 A Dictionary stores 15/2/2021 22/2/2021 48-56


keywords and its
meanings. Provide facility
for adding new keywords,
deleting keywords,
updating values of any
entry. Provide facility to
display whole data sorted
in ascending/
Descending order. Also
find how many maximum
comparisons may require
for finding any keyword.
Use Binary Search Tree
for implementation.

6 C13 Represent a given graph 22/2/2021 1/3/2021 57-62


using adjacency
matrix/list to perform DFS
and using adjacency list
to perform BFS. Use the
map of the area around
the college as the graph.
Identify the prominent
land marks as nodes and
perform DFS and BFS on
that.

7 C15 You have a business with 1/3/2021 8/3/2021 63-72


several offices; you want
to lease phone lines to
connect them up with
each other; and the
phone company charges
different amounts of

3
money to connect
different pairs of cities.
You want a set of lines
that connects all your
offices with a minimum
total cost. Solve the
problem by suggesting
appropriate data
structures.

73-8 D18 Given sequence k = k1 8/3/2021 15/3/2021 73-81


<K2 < Kn of n sorted
keys, with a search
probability pi for each key
ki . … Build the Binary
search tree that has the
least search cost given
the access probability for
each key?

9 D19 A Dictionary stores 15/3/2021 12/4/2021 82-91


keywords and its
meanings. Provide facility
for adding new keywords,
deleting keywords,
updating values of any
entry. Provide facility to
display whole data sorted
in ascending/
Descending order. Also
find how many maximum
comparisons may require
for finding any keyword.
Use Height balance tree
and find the complexity
for finding a keyword

10 E21 Implement the 12/4/2021 26/4/2021 92-98


Heap/Shell sort algorithm
implemented in Java
demonstrating heap/shell
data structure with
modularity of
programming language

11 F23 Department maintains a 26/4/2021 10/5/2021 99-108


student information. The
file contains roll number,

4
name, division and
address. Allow user to
add, delete information of
student. Display
information of particular
employee. If record of
student does not exist an
appropriate message is
displayed. If it is, then the
system displays the
student details. Use
sequential file to main the
data.

12 F25 Implementation of a 10/5/2021 24/5/2021 109-116


direct access file -
Insertion and deletion of
a record from a direct
access file

13 MINI Project 29 Design a mini project to 24/5/2021 1/6/2021 117-131


implement a Smart text
editor.

5
Pege No.
xpt 0t(Aroup-A) Date

NameShegar ipti gunil Rollno 10CS050


Uass SE-Comp-I
BatchC
Subject DSA Dodi9 O13r5

Aim.Consid e teleghone booK database o


olientS. make use oa bah table impementation
o QuidKIy \00P up dient's teleph one ymmber make
Se o tùo collision hándling tedhniaules
USe

COmpate them using umber Com parlsiong


requi ed to find aget onumbefss
heory
Hoshing
At is atechyique that uses tewef kRAL COmparslo
and seardhes the olement in On)time
nthe DOst (se inOltime in the
avecage ale
Hashtbible 1e C table used foY stDiing
ecords
Hash funcdon
he position of A ey inthe @rNay is
aien' by fundion m) Cafled ahash
functin
Hosh tabes axe elidient mplementa tiol
KelgaeYiuy data"stIIULYE astYauye
sometmes K0DLDN ( Iaskodiati ve array
6
OY ymap
functions
ypes of hash
Division method
s_dopendant
hash function
Snthis the o a diviSIon iA
pon tho remaind fy

Hash =eyosize the iash table

2) midSQ1aYe_method
n this methdd firstluKeu is Saua Yea
he mid paYt_ ho gU|
the imdex
ey3Jo1* 310=96T2 0
h30= 6middle 3digits)
B0gt folding me thod
4nthis meth ed tho Keu is divided into
sepa ate payts byS1ng some imple
exatio ThOBe paYts Ar (ombin ed
to YCdute hash Ke
ex ecoy of 12 44sS12 it will be
j Agdedinto paYtS24,65,512
fter dividiotho pas t (Ombing hase
a vts by_addinh. i
HKeu=12 4eyt65 s 61
Digit Ktradion method'
An this S0me dgis ar
tofom add Oxtradtad from RO
ocaton ia hash tabe
multiplicatlog nethod'
multigll K K by_constont
7 rangel©,D
aConal PArt
Page No
Date

hultiply this value by MtaRe thofloo


thoe30 It
what is COLLTSION
Khere3 a possbillty that wo Keys nesutE
in same Value whn appliedthe Bash func
Ahis situation wnere nguoly
yin8erted Reymaps
toCin alYeady gcupied slat in hashtable"
is (alled collsion
(oll ision goludionechniaieg o
thee ls axoblem d rollis IOn tha it
Cdn behanded bu follcwing LedhniauNO3
(Openhashing(Sepdrate chai ing
llosed haaHing |Ope addreigirta)
1uneaKpbbing
a)othdit chining wrth withaut
eplaice2t mont
b)pith chainng Leth A uithout_ieplaceMETt
QuadraHa
Naubl e haIhi ng_
Unear probing
inearpSObing. ceardh3 the hah table for
me losestpllowing nee ocation
insectstho nuw Kuy hoe ohen collislon
occ UYS
Alaori th m
STAAT
8
bfor 8ey use division meth.od to fnd
its addre in the hash table,
h(Reu) Key o M
eCcA the slot is alyeadu oCupied
th en,mDNe to the neXt Pmptu
higher ind ex
td Trate he hash tabl)e asiit is
YOund youbithit h end c
has h table then Go bak to 0
stayti n tabe
C)NDO
Quadyatic frooi1q- y O12/

9 t 1S an Ope addreuing sheme


ohexe De looK doY 0th slot in
h e i th jteraioa i4the qiven
hash yalue x_Colidg in tho hdh_
o ble.
t hash he slor ndex computed
ing hash fundion
o4f slot hashlo is fulthen oe
lot hgsh Dosis fu
then tuhash 2¥2)hs
o otlhach hach ()4 2 2s is
full trU hash6)+ 36
o This Hoess1S epeated
all fhb. Vajus Q tor
Pmtslot is
unh d0
OUnd
9
PegoRo
-0r0 Date
AlgoYith m A
Ta)STARTT
64nitalluuge division_mahod to tnd
its addros in the hash toble hfke
Rey °o M
4oyingtanceififthere is (ollision the
8eaNadvati Cpyobing Hi(kay) =(Hoh(Koy)
i2 oM
d v e nafter sl ng guadratic pYbbing it
tho (ollislon_pes ktsthen qO to thd
indexA e the aboie foymuNa

ConclugiON
He ledynt 0oabout hashing hash fun dtionE
mplementatlon 'e hash tables 0nd
ditferet (ollision hesp tfon techniques

10
11
12
13
14
Page No.

expt. O2(Group A) Date

Name' Shegay Dipti sun fol no90so5


ClassSE Comp- Bctch
Subject DSHL

immplement all the fundtions dictionars


LuSinC haghing handle collisiok uSsi ng
ehain ng with without Yeplacemert

heoxy
idionary An UnNdered etdee (ollection
ie
aota yallks used to stoY e datd alues He
a mapStholds euU Value gai ey is
ualue S gYDid ed in dictionaru to mare
i t mo pptlmsed gten didilodarieR are
mrle merted' apith hash tablez

eatng o didionars n puthon_a dicdionary


Can be eated usig urly bYace plaing
seaMNCe e e e ts0 in it
/2
Picb=:Hello 20orld"
nseytinq in Ationars we can add new olement
in didtionar u bu ng Key as acubsCV1 pt
siqni nq,ita vald e
e def insertlke,key value
seA Ke yalue_
Seaxdhi nq in ictionaru4
15 usinqf
using. in L chn hech wh eth ey a
Keu oy ists n the didionaiy euYnits
Valueif peleat
e y d e f i n d (dicb keu).
1 Key n dih
printldictlkau
ese
fHat Nt found
Nel otin g a Ke in dictionar

e delet ea Keu sina 2


con fun cUo
putho )
)de) Ry word Can be tw ed to
replace dolete the keuRre9et in
the dudona
de) id
pop Lan oe delete a R Uaue
16 poNOs ell
e ermoved-Val Pico pop
HashiNg
-At is citechnque taat uses fewe KRY COmparslo
andseaNCN ES tne olement in On) 0time
9tlme
n the Ost (ase inOltme in the
avesag e ase
Hashtbble is c table used toX stDYing
eroKds
Hosh fundüon'
he position_of cu heu in the oraY is
aenby Afundion caed a hash
fundiD
Hsh tgbes axe elidet imoementathon
stYatuYe
Keideiay data"sstru duYe a
SOmeHmes RaDIOn (& aAkociative arr
17
Collisions=
sitauation 10 which hash funtioa
WturB the sam addre3(Rau) PO more
than d recoYd: f collisio o dUN the
t shDald be handled bu
aplue ng some tehniGu E collision
hardli fechniqmos
18
Page No.

a)0penho3hing (chaining) dhe collision aye


gtoy ed autddde tgble
Dwithourt hedacement We itoduce
additional ield oith data i e: chain: when
(Olision occuYS UStOYe the_ond colliding
data bu neaY pxobing method 4he addka
thisu data is stode d Loth first colliding
oXement Inn chaintable 10thouut
Oplacemet(ongido olemant 13,2
3 6L loO Wn h fundin
RU mod 10 We itoe ClemeAt in
hdgh able
Andex Nata Chain
66

2With Replacement, an previouS method


h ad disadvantge De
Sng th
t h e holh uñcdo o0 avoid.nfanina
LWe meth od this) (onsidethat
Omeats ' 8 2 31 5 , 2
e uOction Kuy mod O
45wi be s0ted Samo.
ooreuious Method egt dnent
ehOyeaNe Oalreadu. is 2.hirt
19
stored
stored Ot
o
epdce2h
ShusLDe
nd ex g to n o t
aCant plab
shift 2

haim
Ondey Dota
O
TB1
2
2 -
3
S

-
-

20
Page No.
Date

(ondusion o
tence De implemente undo o
didionak anghhig (ode is
implenentrd compiled

21
22
23
24
25
Pege No.
xperiment no 5 (roup -B) Date

Nome' Shega igtiKunil Roll no 19(CO50


Class SE -(omp |Batdh-C)
Subjedo DSAL
AimA booK Consist s chapteis Chapters
onsisT osedions Setio (on8ISt
subsectio. (onstvud a a tree and print
h ndosind time SPace rGIu Yements
oyay mhod
4heory
A tye i s a set cnodo such that
th nOdo ave aOYentchild
Hlationship that satisfies the follooing
f 1is not empty has a Sped al tree
caled the y0ot that has no panent
dhe ro0t Y T has a set oehildyen
Lwhich aYe a tents t o subtYee o¥mau
haye no other chldyen
Yees are aenerallu used to stoYe and
represent:datal d hlomdhico order adh
Ade m a contoin so me yalue conditon
a separable data sttudiuKe or d yalue
itsOwn
-Poth-4t refey to the sequence a Nodto%
tvavdle d to reach a nodo romkont

Rpot 4he top-MOst node o atee is talled


26 the root etree there is only one fodt per
tree
ont Jm Date
29
ayent h e PXedecessOX anode
s called its arent atheroot e
e ee nas Qot Parent

h l l d - h e Suc©ssoY Of a node i s
CCul)edits child
o a t _A Ode having no childkenL
IS cal ed a leaf
Subtree Subtee presents the
descendants e a n o d e . t Can be
pmptu,d single nod0 O a yo
whol s n g l e

treeD rtsef
Visiting AefeYS to checkinq. valu0
C nod0 (ohen (ont o PS On_
nddo
hov e 4 t nekovs to 4enerattol 0
Yod e By daau t use lonsidor
Oot to pe att evel
Depth' h e depth a node
epresent helevel twhich i1is
phesent
Heignt Ahe heignt Ctree is
thedepthof it outest 1edfnod o
dyontages ot trees

eTeec nelect stuctuval rdanshigin data


oSheu0Ye used to nepresen- hiendrchies
O PrOvide didet
Ineertian searchi ng _
27 DVeyexrb alldoinq tomoyesubtres
Lbith manmUm o
Puge No.
Date

olloeing basic operatiou d a tree


aYe

oSeardh indsa specitic acde a tree


o I n s e t ghe veru. tiS
tinserion KEates
the tree he Oth er inseytions are done
At speci fie Daton
Pseudocode T
s ear Ch toY node tohose child node is to
inserted f his nodeis àt eyel1,dhil d
node is inserted at level i+ 1 only if
theye aYe nchildon nod e A aku
tree
2 ink ew n doto the nodOthat
becomeg t's paent node
Og1217o
Travers al 4here AYe tuDO tupes eaverS aG
depth iYshi EHth tirs
Depth first p Traversal
eoYder AVerso Cl parent>|eft =right nodo
4noYdex traversaleftzpaxenthaht nodo
Pastoxder traversal=eft ight>pne ent nodO
BYeadth first travers.C
achnodnode on aevel i s taveu Edbefore
mouing On h e neYt leye

28
Date

90
xOmple-0

1D

Breadth first travetsa0 10 5,15 ,4,1,1g


Pord)10,5 9,15,114

PostordeX L9,5,1l,10,15IO
Snorde- 5910,1l1610_
Conclusion'
Me leur nt the ConceptS tree its.
ApaatioN and pYopetieA:h e
pYoa1aM Das implem.eted stiESStull

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
~'I- pt '. \'6 CCi'fbUf - CJ Page No.

t( t

8tru ~

e~ thoi

tex .
l ~ c
\ ,') 0 O
(2_ 0 \J \
57 ~ 0 D
~ [i d.ici.ten~ mo.tr\x "t QK! 6~ 0
8
()
~~c_e._ -:-:r- - '
TOO ·

•.

, \ Df " bou (s
e_ta

C
[ 'f~ i f' ' ed , · · 1 • ,

I ot ~ rt •

58
Dat'J

" I

V S\

'n'oo lJ '( s. .
\ . CC\\\ \f To

-
59

---L --
60
61
62
Page N0
Date

expt15(Group- B Rol no' qCSo5 O


Name shegay plt) suni Batch: C
classSE-(omp-T

subjecb' DSAL
sever
im uOu have a business oith
OfficeS ou Voant to lease phone ines
t o (omecb them up with each othey
and the phone Compans_oharge difterent
AMOUts money td onnbd diterent
pai (s of cities o Loant aset CL
ines that connects all youY o(EE
utth a minimUm tota cöstt Solve n
fhe piobem hy suggesttng agpapriate
data '_ctructue
heoru-
reedy Algorithm
|dAY eedy is an alaprithmic paxadigm that
builds up a solution piece Du_piéce
ghoesi ig he ne Kt plece that offeVSalwOU3
he mOSt ODVIOUS and
bene fit t fiods he immediate
Overall,o
aloba lu OpHmal Solution
botimiation for SOme
pxoblemgbut
ess-than-optimal may find
ADrme STOnes solutrong t
other problermg
63
Pageo.
Date

POpexties of a reedy Algovithm


DAt each etep the best ocssible daoice iS
tonea and after that only the sub-voDen_
S Solved
eedy algovthm might be depending,be
on maiy cholca Butt cann ot ever
aepe id Nq uon any chofces TUYe
neiq theX nsub-psdplems solutithg
9 he nethcd a storts with a tof
goes dD(ONreatt nq gyeedy thole e ina
gertes thenrodute Öa ch e the aiNen
pTobleM toeven smalle One

Yimum_Spannin
mins mum spanniNa tiee (ms T)is a kind
sUD qraph oan u ndirecbed a rapn in_
oHich the ub-aiaph srans orincLydes
ol the nod0s has d minimum total edae
1peight
NY
Prim's Alqovithm
Prims alqovthmn has the follousl ng_propertie3
heedges in the sabset come
mimimuM cpannlng tyee alpnux fbim a
2 4 e tree
qrogg hetee unn it spans all
h érttce 0 he1aph
64
Date

added to the ree at


is
.co edee that (Yoss es a cut I{
Overu step minimuM Q any
its Delgnt s the
ut(oneeting
edAe cressing the
it to a VekteK_ Gdpn

Algorithm

beain with any yert exwhich Uou thinK


Oud be suitd ble add it D tha
tree
Find on edge that conneds Any vetek
iAt th trée to ans vertex Tthat Ish
0 tree.Note ot L don
haye to tom udo
3 ctop oben 1-Cdges haVe peen
ad dodto he treé

COnduson
nderstocrd
the concept baslc
Spanni ng 2to fH nd tha minimUm
Astance BetWeen The vertcel
raph in ata Stru dturKe

65
66
67
68
69
70
71
72
xpt 18(Graup-D Date

Koll no.14CS05O
Name NM ptt shega
UassSE-Co mR Batch C
Subjecb psAL
AImiven SegNeoce
k=K1k2M K
Nsort ed Keug Oith a s eaYch Poba blit
the binayy
I foX ach Ke ki Build least
Seaxch tree that has the
(oSt
aven the access probability OY edch
Reu
heory
Optimal Binary seardh Tree (OBs T)
An 085T is a binayy sFarch tYte ( 8ST)
Jo which the nodes aYe axtangd on
Nels sudh that the tree os
Ymiimum O

fos better pieseatati oncOBS T we wl


conside xtend ed binaH4 Seardh ee"
whh nave the heustored at their
ter nal nde Suppose n RaUS KL, K2 RD
R
AKsTOKEd at the itexnahodol o
binaK Learch t ee t is auS Umed
that h Keus Ar aNen in soY ted
OXd er so a t K\K24
Qxtended BST_s bbto ped n An
BST b Adding tom
ach its suessCr
mia ndesanpdes og
Ades Q
73
indiccte An the JolloLin
JigIre
Pege No.
Date

Du sauare
Generali zation
P P6

92
Binaru Sarch
tree
124
ktended inarySrarch treg.
he tminalnode i0 the extended bnaYU
tee that is the left suCESS OY h klcan be
iterpyefed as eprelen ti ng dl Ro valUe
thart aYe not Stored ahd ae esthan
Slmilartu the terminal. node in the
extended fee hat is the ight sureSS V
k pYesetS Call key values not
Lgtoiin he ttee hat dMie AYeater han Kn
he teYmiAad nodo that is Ce sses betueen
K and ki-Ua an iaOrder trONersal Oprelent
A Ky Valu not stored that lie
batwegh Ki Ki
Blgovithms
Me hove the foll owincuDrOCeduYe fo1 det erming
74
CompuTERoOT(IP19B,

PROCEDURE
beain
foX =0 to n do
C
foy m=0 ton dQ do.
foy 0 to (n-m)
w )EOiAD+pjtq)
find cli) and ) Lwhich
miimize the tree (st
ond

he tollowing function builds an cptimal


binars searda tyee
fuNCHTON CON TRLTOR(Ri).
beqin
build o e intanal nde N abeled
RC
nen
buid a neweaf nde N abe)
olse Fd(i))
NCONSTRUCT6R(P i
YN is the left child
build a new leaf
else iodoNabeled
75
CONSIRUCTORRktÁ
s the igt
dhild hode
end
Pege No.
Dihte
COmplexityr fnalysis
The algorithm equi rea On2) tme ofh
stOfage Sherefore 0s ereas es it UI
run out cstoY age even befae it YUAS Qutt
time he stovage na dad Can be
dduced by almost half bu
mplement idq tne op aYmaukas u0 arauk
Cocksion
his pycqyamgives LS he Knodledge
OeST ytemded binar search tyee

YOS

2e0r

76
77
78
79
80
81
s

_, i
ee 'c. ,_

82
Pag9N::>.

r ~ -r - r- ---==-::C---- -
e~ \J d fu at
\.s o e eorch

tho 1(I \Je~t-e-Y A ~ en

*eve 1) e . lS
~ -1s a\ a n ~ __ .,
e e e "'<&t- -t( ee ,s

C ·
\
'I
0
.- ' t .
• I

,
• • •
....

~ ero ()cl
~Ub. -tv:ee
ht
83
~

' 2.. an
f;;0 ("t '
tree f>'(mrts

-- \1l-- left cu.bi: r~ -

II f,~ J RI Qh± -- te+t 8otai:1oll ·


1~1:-i e ,t'\ ,s--t -two vOto-t-l o~ a '(Q s\ n~, 'i2 yotcrb'DN
I cu\cl i\rQ_ (\_Q_i t two ) ot0-t1 o ru a'<@ d av b\ -e
I ~ o:ti ~ st d 0\ 1 Ye e e\ "'-t · .
wh

voi ' ,
I
I
j
.
.
0

84
ht-- YO
ef-t rotation
~===---=======c-=-=====::::
Pag9NO .

Date

h ee Wt 'oe reyn e
\(\ \e-f -S U

ote1~ a' 0 ,

,o\lIT\ Of

en .
O'< \1°\, m ', -
f\&e, t :-
uU- €( \ ~
ew ntde
85
~ \e + - 'ne1

h-trotate

~d+'
86
Data

"l: - L
;:: - - --:,- -_ -=- - --i::::=- ---=- ----C:.... ---::.. I - .,;::.. ·- C:

'-

r
~ . .
II

II Cb f\
II
II

II
II

. I •

j .

, I

87
r
88
89
90
91
Name Shegar pipti sunil Roll no 1q CSO6 O
Class'SE Comp-I Bath. C
Subjech Rata 8trudureg and lgorithng
aborotOY
Experiment no E-21

Aim: Smplement the Heap shel| sovt algorthm


jmplemeoted in JTaVa demonstrati ng heap lshel
cdert.a stu.dure wt nmodulavrtY oproQrammiD
anguage
YO
he oYy
oHeapSort AlooYithm
1eqp soYt IS a compaYISioN-bdsed sovtlng technique
bas ed on Binaru heap dat.a struUure 4t Jis simlhy
o selection sot ohe re we first ind tho
maimum
elementand pl ace the maximuM eement at the en d
Lwe repeat he same YOCeGs fOr remuning o
ement
oBinary Heap
A hedd is aComplete binayu
yee
binavy ree elements aYe HIPed eveS0 a complete
fom eft to Ylght {huS he bottom bu level
be completelufled Ims level may not
Oxde su) tHat yalue in a aXe stOr ea n aspeclal
laveater (O gmaller) than thepareat node is
ChildreA nodfs. he formerisValues in its twoo
and the later 1s ealld as max hea p
(Culled min heap
92
why qrNay based epYeserttatidn foy Bingv
Heapb
Sine B)nars heap is a Complet e Binary Yee
con be &uily repre&ented ag arvayànd
dCL based epesnt ationis spare eicient
h e 0AYent node is sto èd at hdex
then th eft child can be Caludated
by 2 and yight child by
2 + 2 (when indeystarts at oy
oHeap Sovt aldoY ithm for sor ting 10 1nCreasi
OYder

Puild a mox heap from input data


2 At this poi t the lagest item is
the root of the beap-Keplate it stored at
ast tem heap ollOwed with the
the cie h0 ap b
bueducina
8: Pepeat above eapit the YOot
stepS Ae4 uit1 size
heap 1S 0edter han
oBuild a Heap-
lHeapifu POCed ure co be
lnluif ts dh1ldien nodoOre apliedto a node
tPs a bottom up orde heapitied, so
praeSS
XOmple
93
Anput clata 03,5
Joy
be nump ere in brackets epres ent he jndice in
he aYY CUY epresentation o data
Apeluing heapify proredure
to indO

5(3)

ppuing heapHu proceduve


t0 nd ex
he heapfy pYOCedute Ca\s
tse- ecutsiveluy to build
eap i top dokon manney
O Working of Heap Sort -
Sinre the tree satisfies MOx-hea pYopertyUhen the
Largest itempstored atho Yoott node
Sw ap, Remove the rOot el emnt and put at the end
he array ntm poition) Put The tast item Ot
tyee
Cheap) at the vaCant_lace
94
emOVe" Reduce the Size, ot the heap by be
4Heapify Heapity the Yoot elemeat cgain so
that be have the highest element at Yoot .
55 he
he prOcess is repeated untilall tho temg
of theist aYe sorted
Aime (omplevity
WOYSt nAldq(n)
Averaqe nlogn)
B t nta(n).
SPace (mplexity:A
O Applications Hea p sot
K sOYted aYYay-
aY gestOY smallest ements in an aYYau
oCondusion
eearntnt heapsort ulgorithm and
pYOCLYQm
implemented on it was execuuDed GuLCCeS
sfully

95
96
97
98
Name Sheday Pipti Sunil Roll no D50
CUGss SE-eompL Batch C
Subiecb 9ata südueg Alaorithm aboYatory
Xperiment n0.(hroup F-23 1

m epor tme0t maintaios a student infomatlon


h efile eotaing Yo nmbename division and
addvess AIlow use toadd delete informati on
etudont Pislay infox matio c_paYtiaddy
hmplogeO f ecoraostudont Cdes not Cocists
O appOPYLaTe messQeis dis playcd tis
thenhé sustem daplays the studeat daballs
Use sequenHd Hileto malttain data o

Sheox
Seauential Organization
hie tupe ofile orgoniza tionmahás TSmsiemo
he TSmA kcheme ie ndex scqMentia0 memoYU
laces scheme 1S a ind le o1gcnization
n which ecordbe_YNanged gngq ulindo
Can
SUYtacE
qg Corsldes th iKangemeat studont s
oovdin uhicM qulindey S AsUYfaces aree
UL ed

99
Name RollMayk&loulinder|surfocel
Record no
numbeY

AAA 40
BB8 &0
3 36
CCC HO q0 2
5 2 2
DPD
FEE 50 +8 3

NOUD i we oont to find YeoNd e Voll no


Othnwe Can seax ch it baued n he
Lculinder hat is 0e will tfrst seATch
thOx
uMindonumbe 2tnen we willma Ko th
SeaYch based On tho
surfaCe0henwe
IEach at surfate 2 e Cylinde,then
dasyed xecor d Can the
the
tack obtajnd wrthin
Adotag esCqMential oXganizaion
9
4DhesËQueatäl
t0imp\EMENt RleoYganizah ba ls simple
(2 t is suitable fo small
database applhcattou
(ASi14isadvantages
dot abas s osequentHad then organigation
atton-
Ho be non- evyhuge then it urn
0 u g e then urnu OUt
OU
e o r

elicdent 9 techinique foXYeti


d o i d e a t

eUa
a the humber
surface then muotrack& Ore mOYe pn he
ldtt ple disk aceR
100
moy rNquIvd
basic apeyattons hat can be_perfoY med on
seauentioal f|e_OYganigafon e
O Creat e 4Update
Ca Sispau Append
B) Delet séadh
Dreate -
yoid EMP_(LASS Create )
chaY eh y
strea m seaHle
3eghile Open maDAT iosinios
binayu
do2
Cout ntter Name
nRecordsname
COUt\nter emplbue1d
0n Aecoxdk.emp-ld
Cout &noter Saláry
OnYzheCOY dR.alary
/then LoiterecoYd containinq in this datd in fle
segfilewYitellchaY")Acovd,sizeQ.ROcOYds)
(out2n Do uoU LDant to add mye
CIZh
reoYd2
Lonileldh
seqfile case
Use must entey tho doiyed ata tho
ho strudu yeCOS dg
in memberS

101
2 isplay79020

Void mP_CLASS : DisplayC) SB


Fstyeam seqfile
1 tnm
SCqileopen("EmP DAT,iOS 0Osout los:;
binaYy)
postioningle pointe in fleat beginmin
seeeseckg(Oios beg
Cout\NSheontents e file are Zedl
ead tho wCords scqlueniiallu
whilescqfle régdérdlchav) FRecoYds,
sized (RcoYd))) 2
4(RoCOYd empid = - )
Cout nNome ReoYde name
(oLut nm ID ecords.1a
Cout n Saldry Rord salav
Cow2n

Condusion
Ahe prqyam as execudtod suceutullu
and we DeYe abe Tbaeneate dog) yd
Cutpuds

102
103
104
105
106
107
108
Expt 25 (Group F)
Dato

Name: Shegar ipti suni Roll ho19CSos


Bath C
14CSO50
Cass -Comp- L
Subjecb DSAL
Hm.Smplementation ol a dived ac(ess tile
-Insertion and
deletton
a heoYd rom a duved6 aceK He
heox
YD9
le ovganizgti on
e bxgani 2atuon_onsuYe tha t
Yecotag CNe
avalable foyPiOreSSng 4t iS Uged to
doneimoe an uient e
OY oach bae elation OYGOn12atton
D2y9/
upes e oxganization
-Sequeitia a(SS
9ndexed Sequentleal acess
Pired ccess e
ived ccess Fle'-
t is aso KnoLon
elati ye fle as random
stod in dive Olganzation 0accesstoY
AI FEOYd
ROYd _aye
aYe
(DASO), sLch atcesS Stoyage
record dont q hard dis . deulce
delce
peod
they axe ugdat ed to þe Jhe
109 badk in ame direddy gequential becaul
becauie
0CctiOR LUN) tten
tte n
Page No.
Date

Aupes diyed access ile o Yandom


aCCessOYganlzation,
N
Random Hce es s
Oxani3aton

Qivect kddnouin9 Dyectory Haahin g


0OKup
Tiveddeaddrsing
heye are two type o recoYdR hat ae handled
Hed math recovd Uuable length recoYd

2iyedovr_ loohup
n this Scheme ho indoX fnY tho_polnteys to tha
re(O du I6 madnia ned AheCirLO baCRS_@hs
methcd is that t eauirek moe disk.Aey
than cukec addes methad
a)Hashing
4 the echnique in tuhich hmah Key ix ohtained
hsna Some sutable hah unctidn rOCord
OCor
is laced in th0hah talble wth tho
Lalp e this haah _Ruy
OperatioY onOiredb Hccessile=
Narig operatioY hat can be perfOrmed
on diyedb access J e ae
CYeate
AnsPyt a rcoYd into a file
110 8) 9eeTe e cOYd om a e
Date

pdate a ecord

Condusion i s e ired
Hence we dearnt what
{operctons
Aces Jile its tupeX
Rahd on i

ArOtO900

111
112
113
114
115
116
Name : Shegar Dipti Sunil
Batch : C
Roll no : 19CS050
Subject : Data Structures and Algorithms Laboratory.

MINI PROJECT

Experiment no : 29
Experiment title : Smart text editor (using JAVA)
Aim : Design a mini project to implement a Smart text editor.
Theory :
To create a simple text editor in Java Swing we will use a JTextArea, a JMenuBar and add
JMenu to it and we will add JMenuItems. All the menu items will have actionListener to
detect any action.

There will be a menu bar and it will contain two menus and a button:
1. File menu
• open: this menuitem is used to open a file
• save: this menuitem is used to save a file
• print : this menuitem is used to print the components of the text area
• new : this menuitem is used to create a new blank file
2. Edit menu
• cut: this menuitem is to cut the selected area and copy it to clipboard
• copy: this menuitem is to copy the selected area to the clipboard
• paste : this menuitem is to paste the text from the clipboard to the text area
3. Close : this button closes the frame

117
Methods used:

method explanation
cut() removes the selected area from the text area and store it in
clipboard
copy() copies the selected area from the text area and store it in clipboard
paste() removes the selected area from the text area and store it in
clipboard
print() prints the components of the text area

Program to create a simple text editor:

To create a simple text editor:


• First, we will create a frame f titled “editor” and apply a metal look and feel and
set an ocean theme in it.
• We will add a text area and a menubar with three menu File, Edit, and Close.
• The “File” option has 4 menu items new, open, save and print.
• “Edit” has 3 menu items cut, copy and paste. We will add an action
listener to all the menu items(using addActionListener() function) to
detect any action.
• We will add the menu items to the menu and menu to the menubar using add()
function and we would add the menubar to the frame using addJMenuBar()
function.
• We will add the text area to the frame using add function set the size of the frame
to 500,500 using setSize(500,500) function and then display the frame using
show function.

Here is how the functions of the menu will be invoked:


• On selecting the cut, copy, paste and print menu item the inbuilt functions of text
area cut(), copy(), paste() and print() will be invoked.
• On selecting “save” menu item, a file chooser will get opened which will show the
save dialog after selecting a file the filewriter(buffered writer) would write the
contents of the text area to the file and close the file writer and buffered writer.

118
• On selecting “open” menu item, a file chooser will get opened which will show
the open dialog after selecting a file a file reader and a buffered reader would
read the file and set the text of the text area to the contents of the file.
• If the “new” menu item is selected the text of the text area will be set to blank. If
“close” menu item is selected the frame is closed by using the function
isVisible(false).

119
120
121
122
123
124
125
126
127
128
129
130
131

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy