Introduction to Algorithms, Third Edition


Correctness of Huffman’s algorithm



Download 4,84 Mb.
Pdf ko'rish
bet290/618
Sana07.04.2022
Hajmi4,84 Mb.
#534272
1   ...   286   287   288   289   290   291   292   293   ...   618
Bog'liq
Introduction-to-algorithms-3rd-edition

Correctness of Huffman’s algorithm
To prove that the greedy algorithm H
UFFMAN
is correct, we show that the prob-
lem of determining an optimal prefix code exhibits the greedy-choice and optimal-
substructure properties. The next lemma shows that the greedy-choice property
holds.
Lemma 16.2
Let
C
be an alphabet in which each character
c
2
C
has frequency
c:
freq
. Let
x
and
y
be two characters in
C
having the lowest frequencies. Then there exists
an optimal prefix code for
C
in which the codewords for
x
and
y
have the same
length and differ only in the last bit.
Proof
The idea of the proof is to take the tree
T
representing an arbitrary optimal
prefix code and modify it to make a tree representing another optimal prefix code
such that the characters
x
and
y
appear as sibling leaves of maximum depth in the
new tree. If we can construct such a tree, then the codewords for
x
and
y
will have
the same length and differ only in the last bit.
Let
a
and
b
be two characters that are sibling leaves of maximum depth in
T
.
Without loss of generality, we assume that
a:
freq
b:
freq
and
x:
freq
y:
freq
.
Since
x:
freq
and
y:
freq
are the two lowest leaf frequencies, in order, and
a:
freq
and
b:
freq
are two arbitrary frequencies, in order, we have
x:
freq
a:
freq
and
y:
freq
b:
freq
.
In the remainder of the proof, it is possible that we could have
x:
freq
D
a:
freq
or
y:
freq
D
b:
freq
. However, if we had
x:
freq
D
b:
freq
, then we would also have
a:
freq
D
b:
freq
D
x:
freq
D
y:
freq
(see Exercise 16.3-1), and the lemma would
be trivially true. Thus, we will assume that
x:
freq
¤
b:
freq
, which means that
x
¤
b
.
As Figure 16.6 shows, we exchange the positions in
T
of
a
and
x
to produce a
tree
T
0
, and then we exchange the positions in
T
0
of
b
and
y
to produce a tree
T
00


434
Chapter 16
Greedy Algorithms
x
y
a
b
x
y
a
b
x
y
a
b
T
′′
T
T


Download 4,84 Mb.

Do'stlaringiz bilan baham:
1   ...   286   287   288   289   290   291   292   293   ...   618




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish