1、p2documentProject 2-Huffman Codes-By Group 06 2008.12-10IndexChapter 1: Introduction. . . . .-1.4 Steps to run the programChapter 2: Algorithms Specification. - 2.1 Data Structures2.2 AlgorithmsChapter 3: Testing Results. Chapter 4: Analysis and Comments. - 4.14.2 some Further Comments 4.3time compl
2、exity & space complexity4.4 Further Improvements Appendix I: Source Code (in C) . A. Mian function of the project.B. Test generate function for tester.Appendix II:Duty Assignments.Chapter 1: IntroductionProblem Description:In 1953, David A. Huffman published his paper “A Method for the Construction
3、of Minimum-Redundancy Codes”, and hence printed his name in the history of computer science. As a professor who gives the final exam problem on Huffman codes, I am encountering a big problem: the Huffman codes are NOT unique. For example, given a string “aaaxuaxz”, we can observe that the frequencie
4、s of the characters a, x, u and z are 4, 2, 1 and 1, respectively. We may either encode the symbols as a=0, x=10, u=110, z=111, or in another way as a=1, x=01, u=001, z=000, both compress the string into 14 bits. Another set of code can be given as a=0, x=11, u=100, z=101, but a=0, x=01, u=011, z=00
5、1 is NOT correct since “aaaxuaxz” and “aazuaxax” can both be decoded from the code 00001011001001. The students are submitting all kinds of codes, and I need a computer program to help me determine which ones are correct and which ones are not.Our purpose is to judge whether the submission of the st
6、udents is Huffman code or not.First we should mention that the code that genetared by the huffman algorithm is unique cause the nodes will be sorted before creating the tree, while ,generally, Huffman code is not unique ,just because unsoted nodes have many sequences.It will be an important point wh
7、ile considering the algorithm. You will see more details in the next chapter :Algorithms Specification.Background:About David A. Huffman(August 9, 1925 October 7, 1999):David A. Huffman was a pioneer in the computer science field. Throughout his life, Huffman made many important contributions to the
8、 study of finite state machines, switching circuits, synthesis procedures, and signal designs etc. However, David Huffman is best known for his legendary “Huffman code”, which we will study in this project, a compression scheme for lossless variable length encoding. It was the result of a term paper
9、 he wrote while a graduate student at the Massachusetts Institute of Technology (MIT), where he earned a ScD degree on a thesis named The Synthesis of Sequential Switching Circuits, advised by Samuel H. Caldwell (1953).1Huffman Codes are widely used in nearly every application that involves the comp
10、ression and transmission of digital data, such as fax machines, modems, computer networks, and high-definition television (HDTV), which is widely used in modern society.About Huffman code:Chapter 2: Algorithm SpecificationData Structures:Main Data Structure for a HuffmanTree TreeNode:typedef struct
11、unsigned int weight; unsigned int parent,lchild,rchild; HTNode; Algorithms:1.First, bulid the Huffman tree:for(i=n+1;i=m;+i) select(*HT,i-1,&s1,&s2);/* select the two smallest node whose parent is zero from HT1 to HTi-1 */ (*HT)s1.parent=(*HT)s2.parent=i; (*HT)i.lchild=s1; (*HT)i.rchild=s2; (*HT)i.w
12、eight=(*HT)s1.weight+(*HT)s2.weight; Buliding method Huffman tree:1.choose the smallest two number of the array, assigh its parent pointer to i;2.assigh its weight right after that.Then do it repeatedly.so we got the Huffman tree.Now illustrating it:Do it by upper method repeadly:Do it by upper meth
13、od repeadly:Final state:Now we got Huffman tree!2.Then we calculate the WPL of the standard Huffman tree. for(i=1;i=n;i+) WPL=WPL+wi-1*strlen(HCi);/*calculate to get the value of WPL*/ 3. Calculate the WPL of the input submissions.sum=0;/*initialization sum*/for(i=0;in;i+) scanf(%s,&c); getchar(); g
14、ets(stringi); sum=sum+wi*strlen(stringi);/*the total length of code needed to determine*/4.Compare WPL and WPL If them are equal input case right.Else check whether input case have the relationship of prefixionif(sum!=WPL)/*if sum not equals WPL, then we can say no immediately*/ printf(Non); else/*i
15、f not, we need to look whether they have the relationship of prefixion*/ for(k=0;kn;k+) for(i=k+1;in;i+) l=strlen(stringk); if(strlen(stringi)WPL=864,so it is not the Huffman code.so printf No!To conclude: Testing of these set of testcases are all right.B .Large Scale testdatain this test I provide
16、some testcase that are generated by program ,so that test whether the non-prifix judging is right or not.I just change the sample input .Input cases:Chapter 4: Analysis and CommentsTime complexity & space complexity AnalysisSome Further Comments Further improvement:A.About algorithm:This algorithm f
17、irst need to create an Huffman tree to calculate the smallest WPL of certain input characters, and then it calculate the input WPL,and compare them. I mean calculating WPL by creating a Huffman tree will be costy.It can be improved using another algorithm,while it is really difficult to write.If tim
18、e permit it will be a potential breakthrough point in this programme. B.About Others:1.The user interface of the program can be more friendly.2.The overall style of the document can be smarter.3.Our group wrking can be more efficient.Appendix I: Source Code (in C)Appendix II: Duty AssignmentsProgrammer 王园园 3072211113Tester 王迪 3079901015Report Writer 郭宇波 3079901016
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1