Lect18 19
Lect18 19
Huffman Coding
2
JOB SEQUENCING WITH DEADLINES
There is set of n-jobs. For any job i, is a integer deadling di≥0 and profit Pi>0, the
profit Pi is earned iff the job completed by its deadline.
•To complete a job one had to process the job on a machine for one unit of time.
Only one machine is available for processing jobs.
•A feasible solution for this problem is a subset J of jobs such that each job in this
subset can be completed by its deadline.
•The value of a feasible solution J is the sum of the profits of the jobs in J, i.e.,
∑ i ∈ jP i
•An optimal solution is a feasible solution with maximum value.
•The problem involves identification of a subset of jobs which can be completed by
its deadline. Therefore the problem suites the subset methodology and can be
solved by the greedy method.
3
JOB SEQUENCING WITH DEADLINES
algorithm js(d, j, n)
//d=dead line, j=subset of jobs ,n🡪=total number of jobs
// d[i]≥1 1 ≤ i ≤ n are the dead lines,
// the jobs are ordered such that p[1]≥p[2]≥---≥p[n]
//j[i] is the ith job in the optimal solution 1 ≤ i ≤ k, k🡪 subset range
{
d[0]=j[0]=0;
j[1]=1;
k=1;
for i=2 to n do{
r=k;
while((d[j[r]]>d[i]) and [d[j[r]]≠r)) do
r=r-1;
if((d[j[r]]≤d[i]) and (d[i]> r)) then
{
for q:=k to (r+1) setp-1 do j[q+1]= j[q];
j[r+1]=i;
k=k+1;
}}
return k; 4
}
Huffman Coding
5
Huffman Coding
6
Huffman Coding
Assume we are given a data file that contains only 6 symbols, namely a, b, c, d, e, f With
the following frequency table:
Find a variable length prefix-free encoding scheme that compresses this data file as
much as possible?
7
Huffman Coding
8
Huffman Coding
9
Constructing A Huffman Code
// C is a set of n characters
O(lg n)
O(lg n)
O(lg n)
10
Cost of a Tree T
11
Running time of Huffman's algorithm
12
Prefix Code
13
Huffman Code
Encoding:
Given the characters and their frequencies, perform the algorithm and
generate a code. Write the characters using the code
Decoding:
Given the Huffman tree, figure out what each character is (possible
because of prefix property)
14
Application on Huffman code
15
REFERENCES
Text books:
• Cormen, Leiserson, Rivest, Stein, “Introduction to Algorithms”, Prentice Hall of India, 3rd edition 2012.
problem, Graph coloring.
Websites:
• https://www.tutorialspoint.com/data_structures_algorithms/kruskals_spanning_tree_algorithm.htm
• https://www.geeksforgeeks.org/kruskals-minimum-spanning-tree-algorithm-greedy-algo-2/
THANK YOU