You are on page 1of 5

2.

Design Huffman codes for the following symbols: a, b, c, d, e,


f and I having relative frequencies 2,4,6,8,10,12,16
respectively
Ans.

symbols a b c d e f l
frequencies 2 4 6 8 10 12 16

Step1: arrange them in the priority queue

symbols a b c d e f l
frequencies 2 4 6 8 10 12 16

Already in the ascending order.

 a(2) b(4) c(6) d(8) e(10) f(12) l(16)

Step2:- taking first two elements from the queue and add them

n1(6)

a(2) b(4) and adding to the queue in ascending order

 c(6) n1(6) d(8) e(10) f(12) l(16)

a(2) b(4)

taking c ,n1 and adding them

n2(12)

c(6) n1(6)

a(2) b(4) and adding to the queue in ascending order

 d(8) e(10) f(12) n2(12) l(16)


c(6) n1(6)

a(2) b(4)
taking d ,e from the queue

n4(18)

d(8) e(10) adding to the queue

 f(12) n2(12) l(16) n4(18)

c(6) n1(6) d(8) e(10)

a(2) b(4)

taking f and n2

n3(24)

f(12) n2(12)

c(6) n1(6)

a(2) b(4) and adding to the queue

queue becomes >


l(16) n4(18) n3(24)

d(8) e(10) f(12) n2(12)

c(6) n1(6)

a(2) b(4)
adding l, n4

n5(34)

l(16) n4(18)

d(8) e(10) and now adding to the queue

queue becomes:-
n3(24) n5(34)

f(12) n2(12) l(16) n4(18)

c(6) n1(6) d(8) e(10)

a(2) b(4)

now taking n3 and n5

n6(58)
0 1
n3(24) n5(34)
0 1 0 1
f(12) n2(12) l(16) n4(18)
0 1 0 1
c(6) n1(6) d(8) e(10)
0 1
a(2) b(4)
now the codes are
symbols a b c d e f l
frequencies 2 4 6 8 10 12 16
codes 0110 0111 010 110 111 00 10

2. Find a Hamiltonian circuit in the following graph using


backtracking.

B
A
F

D C

Ans. Hamiltonian circuit using backtracking:-


so the path can be A,B,F,E,D,C,A

so the path can be A,B,F,E,C,D,A

You might also like