0% found this document useful (0 votes)
5 views6 pages

Heap and Sorting by Counting

The document discusses heaps, specifically binary heaps, and their properties, including completeness and the heap property where each parent node is greater than or equal to its children. It outlines the process of inserting and deleting nodes in a heap, as well as the algorithms for maintaining heap structure. Additionally, it touches on heap construction methods and provides examples of heap operations.

Uploaded by

shreyase991
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)
5 views6 pages

Heap and Sorting by Counting

The document discusses heaps, specifically binary heaps, and their properties, including completeness and the heap property where each parent node is greater than or equal to its children. It outlines the process of inserting and deleting nodes in a heap, as well as the algorithms for maintaining heap structure. Additionally, it touches on heap construction methods and provides examples of heap operations.

Uploaded by

shreyase991
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

Heaps amd Heaps ot

teapDrtfoniA gtooa be detmed aa Binay tree

-e
heap

with Keyt aeijnd to itt


ts noday,one Ky p node, proidec
2030Y
the folloeding teoo condittens,are met:
1. Tue
torj3_, bimary +e te esten4sall
complttie, all ts levels are ful enpt Posstbly te
+he
lagt (eVa he ony sone itmost leawy be
issis
2.The
ne paretal dormimamce e Kay
o
heap propety
to 4le
cach mode is 0 enal'
ts chdre
enarnpe,Belo tree is
hep
10

.
Heaps

123 4 31
Tndn

oseE S to

TpadarPrepa
e<e

4
etistseacty

The

also
A node

heap
root

elemat im the topdow,


A
of
heapy
cn
~modes
ot a

heap

be implentd
leftto-higt
be n t
heap
heap

frt
hep
oneessentay ompte
Tts heght is equalfo

conidhed

pociied
eK
LlonJ

alau Comtoy its

as
coitth

am amay
atL ts
largut

by
fashio,
bimary tree

elemnt

)
descendants
rece hding
is

ocer taut Ln)


e ar< le
6)
positony
cvddren
i
Ky t3 te ar{ Paha poso 1
2 amd 2l+1 4r7d
Lnta))es lbim-post om -
par<^d a Ky T Fposthon i C24i nwL be pocitien Li/2l
Congt
Folowin hsues ghos otrov.hle-
ahtap t he
dhe list 2,1,,c,T3 .
te
head

tomparistons vityiy
puental doinamee.

Aso: Cr)
W
A
:
otpt Ln/]
for
HenpEottoUp (
/Comgruet aheap
heap
ai L
Cl
C1.1
A
i4-
from ele-meés

heay
by

dowsto 1 do
a
the
o~donalble t
ary
botton up algoro

EGi'v-HC
heape falye
coile not heap
ad 2* S
armd
do

2L thee are two


childreo
1t41 Ej+) j<-j+1

heap etrue
dels e CE]eHLJJ;

Tn cnplnt:
E 2(h-i)=
h-1
2(h-i)2=2n-oq n ))
Follocdmg fiswes shoo,imseniny a lkey (16) mdo te heap
contetedCim he peiow earple).The neco Koy is Shtd p
patet it is mot lages than
via a Sap eith its nti

its pahent (ois in he root).sos r

newnocle
7etel

aFollowiny

ey
heap
ats
nee
. fçree shou
k to be
T\e Kuy

I
hich te Saules
tpata
0
eletiry the
delei

0h
deltd
~ee
is
is

e
roo's
sppal
eay
coits
from
te layt
heipiied" by echamgong
lareS
doirane eqrheet s
chldrer uml the

Sašsfied.

(blte q)
Maninm Key Dtion
Stypi.Enehamge
fon
oots Ki
4he
becseee e
h
hey si2e by 1 by satRfy
teat kko te

down ttetree
Stp. tre k

stp3: Henty" ere Smalles


ee did t t- h bot-o-
sortn.
Heasont
corkrabom
a follocor,
a heap fo
Conttut
idale bon c 2oj
St.(Heup connttrion
dltioApy te oo
st2i(mani
n-1 m to e
Ssb earay 2,9,,6, S,8 y ay fok
SChep conutvuafo)
(1)29 1622s
(1
2
21GS
G

6 S
1) G 2S
2&GS 1 2l
6 2S 6S 2

2 2.6 [oro
2

(
€EEE0e0 2
dest

deete

()
X to detee

(S to delte 2
oAolu dulukion
delet Finaly
,6, S,2 Ae
unigue lentt
Sohtingb onretos pdtad elenen
wrie elemnb 02

Sotig e lents G2,31,84,9,19,tt

AvayACO -.s] 123289244 je 3 elemehehe


62
.Ceeh\as elennt
Iihally ConntCI 1 ehise is 1 ham31
t pa izo ContC 2 2 Trleses
t Pe in1 ConndC 4
coznt[J
Aftus pas i=2
pau i-s cont
C
Afty
ty pa i-4
cOutC1 24So|2
nu ete @oundC

|
3

3{ |4
d

62| 29| 6e
Avvay slo--s) ACo..neí

S Compio
Copdsio-o
ConSohk
Comtnsoht
pasiion
coun
ohdha6
--1
eleeo
sot eel
nonoeehea
hdy
/Tnp0-4-5 do : A's

cotCeO
dernenl

n-
for i40to
4eetodo
ieo n-2 to
do
n-1 do
Cnfo forj<i+1to
countCt14
ACi]AC]
Cont Cil<
i] cotCn+2
else
oto
cont
n-1 do sCCowntLjALSg
for ie
rturS
Tine co-npeity m2 -[10
cn)= Ss1=
n-2m-1 n-)- (i+a)+1]o
n-2. n--1) = n(m-)
Enanple' Comoles sOng e anray

a Frequeey
Arr ~oln
and Distibukiontaele

11 1213|
2
Frequeniu Jnno
Distribtionhw

Dlo..2)
22
ACS]-02 |1]4G
AC4] 4 24| 3 | 12
Al)= 137| 2
A=1212s 12.

|S
Aolz 13 2

Algosikm: Di stibutionCotiry Sot(ALo,-],,2)


Nsets a arrra -ers o a \ienit ~argelby
Tnp. A- ay ACOm-2) i beeeo lanndl
/ onep sCo,1,^s
Arro dy
mon-letaiy
elemel enst

tor j&o to eu-telo bCJEo


/limhal-reeny

for ieoto m-1 do bCACT-JDLAC-d+1


forj1 to -1do pLu0C -{teey
jeAC]-4
sCbej1]<eCn

You might also like