You are on page 1of 5

XHEAp

wisthot gersertay je ts loes .

n re9
rop,ie elomeutpe n othhid vne
Fav veryStubtre, dee abornant at the e2ot
hesmallosit areona aelonauis in u

HHo tpresa,tton a
hean (or any eP
Patnode : CoJ V nteger disn

Pa
aren node at ACi]:
Left chilLA r d e at Ali]: A2tiJ
Right child de at AlJ :
A( 2it2j.

CGhEider a A:6,9,1?,63, to,/?, 79,82


3 , 31,?23.
9ar Rea

( the rerrs
2¬+ 3-

(6 eemen in chile
12252S)+2 is less than o
6 t a l pathek

Pero inde (nhoos) miaht e


HEAP CCe
las-Hean A loka BT t t h e max haae zpie
ornent sored Preafor than
doraantloveR
tha elorrentsYd
ngte
ered bo t s chidre
sts chidre
eual
ther worde, Tor QuenSltre, the lepnent
undhal elernenss n Eubbe

emanas be inserted in mac-hca-t103E

We pead0 EUa the


elemerts osiisy
Th asa rp
ho oPer lurho chiLcurekm,-

S
P chaat the au-ot
nthetre
ORT

Jhan
When weree q glement, edo
ieplonewt mtoiet
west er chld nede thx p
wth the.
chldren nd su it wth dhe
Cme o maintain unsqns_(nrep
eke ossibter
grtaler7 repeat
etocesS tl
hs
get ananohap
roahly be O(loqn)
2/o3/a Surale nkereen wost ase -O[ leqn).
nale
Ingneral, o(h°heihi
move than haf the olegnents
C/t e u e neoc (logn eahorlag.
Boo node n Beto takes2l).
Opamtns o Insartng 'n
olemanst ruildl un 4he heanlteth
ma min he

"e tot, fora hosn ith the


edLas
no Rgdos in the (ast lavel Lior in the
range L Cn/ 2) t1) n C)= n

Tott Op Hr Swnp op+n


rt 1.ot 2.1t G:24 . 3
level
n f
L:0
T (h +2
R
oln)
OCloqn)
A haar a r e t hrorar (ony vislatad a t loth
DATE

BuildHeRp (A) WorRs in On)rather


than o(aloq w).
eaine SinelA)
dr oHEAPY (h, i),
Cnd f r eeatryag
re direety
Na. Gntora nados pr whieh m9hoapi
Su n werst Ga : Ng-
nheobs neh gre aecont at haighb Ch-i)
Coxl n2C),_
frer h.lorn
ctal p S n i o o n ) Cn!2)_
on)
Fo wost ase- Qsrey shud be in rterse

der He ae has rege ekoumang. 5 24

adegt

BOtLD-muN-HEAP A).
haae8ige: sheA)
for ftoor heapsza/2_darraLal
MoN-HEAPFy LA,J
end o
ED
QNHEAPIFY A, i):
lestehil4KAl2t]

ght Child A l2 t23


minlndeg 2it;min Chld LotChild
Cright Chad lfeChid
min Chil Hght Chis
mn indaa 2¢ta PTO
DATE

ACAC:J>vnin Chid)
S a ACI, A Cminlnder)
MIN-HÉAPIFY LA min lndoe)

Bter vesion

N-HEAeF (A,i)
Lefe
C2i+ lnA))
ndclit1, Lef Child = AC2i+1], miChih: ltChila
righ inrda lotLrsa
2it 2 ralh)
HhtChild=AC24 2], rghtL,der= lzt2
traht Child t LfeChid)
manChild kght Chitd
minl bdoz
Trdos= 2&oht Tdee-)
elun
CAC)2 min Child)
Swep ACIAininTrda])
Mw-HEAPLE 1:0,hialrder)
aND

You might also like