0% found this document useful (0 votes)
32 views

Dsa Assignment - 2002711

Uploaded by

Shrey Mahajan
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)
32 views

Dsa Assignment - 2002711

Uploaded by

Shrey Mahajan
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/ 6

NOma - 1sbka

ou o,20024 (Kog
20024)
dos cSe A2
Subje DSA
ASSgnmant-2
17 Elabotole
he doRdure for Heab Sett.
Heap Sed iS gne f the Sing algotthm Used te
oarge aa GS+ 0f elamets in odo. Heapsot algaki-thm
wotare
e era 0ftha tdea
tencepstS callad Heab te 9n this
eloments
Sotn
Stirg algorithm, we se Max Hea to ist ef
awarge in
hDecending. &tder. Qrd Min Heap te awange is+ elaments
ASceroting do
Ageeith m Heap SS olgeAthn -s odarye a Bst of elements
in asending odv a folos

SteI- Censtouct a Binary Taee twith given ist+ ef Slamerts.


Steb2 Jsansføem the Binaxy Tee ite lin Heap.
S-Heb 3 Delete the d0ot eltrrerrt fem Min Heap using Heapify
mhed
t e Soseol Bst.
Step4- tit he dotoseol elament ite
StebS: ebeat he Same until Min Reap betemu empty
Dissloy e Sosed ust.
Ste 6:
Compleity of Heap Sot Algokithm-
werst Cose: O(n Legn)
Best Co4e:
0 (nlean)
ase : 0 (nlegn)
Average
Enample 82,90,l0, 12, S,+4,Ss,23
-
(onstutt a kead uth given s + 0t urs9tteol
numbeano Conreet ta Max Heap
(99
Heobify

S+ f rumbod aftet Heab tonreed +o- Max teap


no
e Oehse deat9o) hom tte max Heabfe- dalete ot
theadd be Scwabheo Cuith last hecla (2). After
to dol ele + e
Los to be haby to make it max
Heap"

Heapy
(to

Ste 3- Delase anot (82). Ss Suwap i+ wth lagt hsola Is)

HeapifY
4

us+afte Suopping, 12 SS 19,23,1S,t0, 82190


Step4 Delade zoat (1) Plon he Max haap. Se, pwap i+ tD)

Heapit

tis+ et numb®t ofAN Swapbing, 12,SSlo, 23,1. 19, 82,9o


wi4h lost neodo Cs).
S+eb S Delese eat C), So Swas it
Heabity

ist of40r Swopbig 2,IS19,23) SS, 4, 82, 9o


12 (lad0de)
Saep DeLele a9¢t (23), Swa it ith
Healpi Cis

aften Scoapbing» 2,lS10 23,SS,11 ,82190


Se 4-Delse o9st (1s). Swap it with s+ hede lo

Deteue oDelede lo, Empty


a f t e Swappiry 1o,2,1S,23,SS, n.82,9 1h
whonere max Heab becemas Embty, he Us+ get Sereol
Astending odltk
inkao
2) How ts- inget an olament o the Vginnirg 0f
example
Bst E«þlain the þaoteduke Cuth -he halp of an
Inserdion at he beginning f U8
TTEM)
Agotithm DNSERT (TNFO, LINK, START, AvAL, inthe bst,
9huS algoEhm inseets TrEm as -the frst hele
then wle: overfL ano Ext.
LOeflsu? 9f ArAL = NULL,
2 Kamer Arst nBdl fom LIST
AvAIAL
Set NEW ArtIL arol AvAlL UNK [AYAL
neuw data i nte hew ohaoe
3 Set Tfo £NENl: TTEM [cepes
[eus nadl hew points te siginal
4 Set LuNK [NENJSTART
firs+ nodo.
S S e t START NENI Chong START $e it bints te- he
hew neole

6 Exit
START

NEW
Ex pbese
Suppese the tst Sou 15 is to be addaol te -thu beyinning
bthe geamctdy us+. gborre ha TrEM 4S, TNFO TEST
aho START GEOM
NSEIRST (TESTLI NK , nEOM AvtL, TM£m)
Sine ArAL+ NUL, tontaol is tdoans-fevmedb Step 2
2Ne 9, than ArML LINR 91 lo
3 TEST 19] 45
4
LINK 9 5 TEST LINK
S* CEDM9

Exit Ali9 2
4

t8
84
18
8 100
AvAIL o 3

62
4
1 .
(S
16
15
&3) Dis Cusd tha dota Staucuwee opekatiend en Doubly
dnkeo dist
peationd en Twe cwoy LiS+
Delokion Suppese tue aagiena lecodien Lo c ef a nsde
which is + be dileleod f9m cirulo ist
N in Ust

DE UTWL (TNFO, FOR, BACK , START, AYAL , LOC)


Delete hede]
Cet FoRw , FOw Pain-e neale LBACK ILOc : FOR w [Loc) .
And BAk, bat peinet hda [ FoRN LLOC)), BACK TLOc]

nect ds AvAIL Lst1


9Retun
sek FofW [LOC]: = AvAIL ano AvAIL: LOC

3 Exit
tol
Mpole

anod
Inseign
oc 8 Subpeve wt dl iven the LOC
Sube)
lecatiend
aye
A

f adyacet maolas A andB in LIST and


A ano-
want Tjndet blwn hodes
a giren reM ef nfokmatiem N.
t viable keob tack ha lecotion b7 new
nde
TrEM)
LO¢B,
Alge:- TNSTHL (TN FO, foRw, BACk, $TART, AvAIL, LOCA,

9 f ArAIL =NULL then wtHe: Oyerftsuw and EuT


LKomeve nede foom ArAIL UST anol Cepu new data inte h
Set NEW:= AvAIL, AvAL: FoRW [AvAIL],
TNFO
LNEN]: TrEM =

3Inset noda inte- Ust| Set fORW [LocA}: NE W *

FORW CNEW} * LocB

BAcK [Loe8 NEW, 8ACK [E]: Loc A


=

4 Exit locB
loc A
NODE B
yNDEA

NODE N x
TNSERTH NODE

heotdor toaebsal
in binary tes
algotithm fot
84) Explale an

algoti-hrn se a vobiabe PTR Cþairdet)


toorevdal
ghe baeDkdor
ghe
will Cen-taun he Co-hien 0-f h a N CukAmtl
nsdl

which
he left thiloB 0f node
y
L() denotes
being Scanneo
be child.
anol R(N)
olonse he right-
-loavtrda in biray 0
7 eveob
PR preordot
R D(INfO, LEFT, RICHT, Rot algnithm
does a

Abinat
travoal
uy tea Tis in mLmoy'
dhe

openation
PROCESS to
eoch oF
hotol the
t T, an
emboaaeily
ned.An
adde efnadobkay
STAck is weol to

iri tialie PTR:J


Iritio Pulh NLL gnts STACK, ane
ET TOP1, STACK Ci1: NulL ano PTR' RooT

fipply pr0ceSS to TNFO LPTR]


4 Right thild?)
Sf RIGAT TPTRJ¢ NUu,then: [Posh en STAck
RIHT CPTRJ.
SetToP: ToP41, grol STACK [rol]
TEnd ot f StucuR"J
6 Lept ckilo
f LEFT [PTRI# NULL ,han
Set PTR: EFTIPTR]

ELSe tPoP foern SACK]


Set PtR: STACK CroP andTof ToP-1

TEnol of Sb 2 lsoh"
6 Eit

You might also like