Uploaded by Khandare Dipak Dhammveer

19 Heap lyst8729

advertisement
DSA through C++
Heap
Saurabh Shukla (MySirG)
Agenda
-
①
②
Complete Binary
Heap
⑨
Insertion
⑥
Tree
Almost Complete
③
⑤
-
Deletion
Heap
Binary
in
heap
in
heap
sort
Tree
CmpleteBinaryTreeLO
Li
→
→
in →
0
o/\o
o/\o o/\o
All
levels
must
be
completely filled
.
AlmostComp1eteBnyTree
0
O/\O
O/\O
AM
level
must be
completely filled except
possibly the last level
and
all the
last ident
aligned
nodes inthe
must
be
left
Heaps
Heap
data
is
•
•
a
Heap
is
heap
sort
Heap
-
-
structure
used
are
of
in
two
Max Heap
Min
Heap
a
sorting algorithm
types
( default )
known
as
Heapproperties
The
or
value
modem
at
equal to
value
at each
of modem
Heap
an
"
complete
binary tree
This
④
heap
n
is
,
and
Max
no
heap
n
{
min
" ≤ "
↳
.
no ≥
children
for
must be
almost
greater than
is
≥ nz
heap
"" " °
"
Examples
⑧
④
1
200
11
⑧ ④ 250
1
⑤
Max
-
heap
Representatrcnoftkap
stated , heap is maintained
Unless otherwise
in
by
memory
0
⑤
11
④
④
11
⑤ ④ 250
11
200
⑤
tf
linear array
a
I
2
3
4
5
.
6
7
8
-0/40/3012013011012515110--15
0
⑤
I
④
\
⑧
\
④
/
⑨
"
⑤ ⊕
I
2
3
45
6
FTÉg
④%⑧
⑤
⊕
Howtotirdparentacndnde?
⑤
I
④
3
1
200
14
⑧ʰ
Is \
How
to
index
find
nodes?
6
⑧ ④ 250
index
is
=
How to
index of node
index of
index of
N
6
8
7
=
of
N
=
2
*
index
2*
=
ind[✗
(
+1
index
parent node ?
index
Parent node
of child
index of node N
index of left child
index of right child
find
5
-014013012013011012515110mV
tf
\
4
3
2
I
0
-12
Insertion
0
H
I
2
3
4
#
1--9070804060305020
N
④
'
1
⊕ ⑧
"
④ ⑤
temp
☐
⑧ ⑤
"
Deletion
µ
Mft
NID
.emP
Always delete
node
root
⑧
⑧
20
④
⑤
30
40
50
⑤
'
⊕
⑧
④
60
70
80
90
Heapsoot
valves
Delete
and
to
of
from the heap ( Max heap )
store them
left
.
As
deleting
heap
,
array
-
in
a
an
array from
at the
result
,
right
end
all the elements of
becomes
sorted
.
Heap
can
priority
be
used to
Queue
.
implement
Download