|
Shennon fano algoritmning ishlashi
|
bet | 4/5 | Sana | 20.02.2024 | Hajmi | 0,92 Mb. | | #159700 |
- Ikkala yarmining har biriga 3 va 4-bosqichlarni dumaloq tarzda qo'llang, guruhlarni kichikroq kichik guruhlarga bo'ling va har bir belgi daraxtda mos keladigan kod bargiga aylanmaguncha kodlarga bitlarni kiriting.
- Misol: • ABCDE belgisi sifatida • Hisoblash A 15 B 7 C 6 D 6 E 5
- Belgisi: ABCDE • Kod A 00 B 01 C 10 D 110 E 111
- Amalga oshirish
- Yuqoridagi yondashuvni amalga oshirish:
- Pseudo-kod
Pseudo va phyton bo‘yicha ko’ribchiqish 1: begin 3: sort source units to non-decreasing order 4: SF-SplitS 5: output(count of symbols, encoded tree, symbols) 7: end 8: 9: procedure SF-Split(S) 10: begin 11: if (|S|>1) then 12: begin 13: divide S by S1 and S2 with about the same count of units 14: add 1 to codes in S1 15: add 0 to codes in S2 16: SF-Split(S1) 17: SF-Split(S2) 18: end 19: end // C++ program for Shannon Fano Algorithm #include // declare structure node struct node { string sym; float pro; int arr[20]; int top; } p[20]; // function to find shannon code void shannon(int l, int h, node p[]) {
Float pack1 = 0, pack2 = 0, diff1 = 0, diff2 = 0;
int i, d, k, j;
if ((l + 1) == h || l == h || l > h) {
if (l == h || l > h)
return;
p[h].arr[++(p[h].top)] = 0;
p[l].arr[++(p[l].top)] = 1;
return;
{
for (i = l; i <= h – 1; i++)
pack1 = pack1 + p[i].pro;
pack2 = pack2 + p[h].pro;
diff1 = pack1 – pack2;
if (diff1 < 0)
diff1 = diff1 * -1;
j = 2;
while (j != h – l +
|
| |