p2documentWord格式文档下载.docx

上传人:b****3 文档编号:6359647 上传时间:2023-05-06 格式:DOCX 页数:13 大小:190.94KB
下载 相关 举报
p2documentWord格式文档下载.docx_第1页
第1页 / 共13页
p2documentWord格式文档下载.docx_第2页
第2页 / 共13页
p2documentWord格式文档下载.docx_第3页
第3页 / 共13页
p2documentWord格式文档下载.docx_第4页
第4页 / 共13页
p2documentWord格式文档下载.docx_第5页
第5页 / 共13页
p2documentWord格式文档下载.docx_第6页
第6页 / 共13页
p2documentWord格式文档下载.docx_第7页
第7页 / 共13页
p2documentWord格式文档下载.docx_第8页
第8页 / 共13页
p2documentWord格式文档下载.docx_第9页
第9页 / 共13页
p2documentWord格式文档下载.docx_第10页
第10页 / 共13页
p2documentWord格式文档下载.docx_第11页
第11页 / 共13页
p2documentWord格式文档下载.docx_第12页
第12页 / 共13页
p2documentWord格式文档下载.docx_第13页
第13页 / 共13页
亲,该文档总共13页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

p2documentWord格式文档下载.docx

《p2documentWord格式文档下载.docx》由会员分享,可在线阅读,更多相关《p2documentWord格式文档下载.docx(13页珍藏版)》请在冰点文库上搜索。

p2documentWord格式文档下载.docx

 

Introduction

ProblemDescription:

In1953,DavidA.Huffmanpublishedhispaper“AMethodfortheConstructionofMinimum-RedundancyCodes”,andhenceprintedhisnameinthehistoryofcomputerscience.AsaprofessorwhogivesthefinalexamproblemonHuffmancodes,Iamencounteringabigproblem:

theHuffmancodesareNOTunique.Forexample,givenastring“aaaxuaxz”,wecanobservethatthefrequenciesofthecharacters'

a'

'

x'

u'

and'

z'

are4,2,1and1,respectively.Wemayeitherencodethesymbolsas{'

=0,'

=10,'

=110,'

=111},orinanotherwayas{'

=1,'

=01,'

=001,'

=000},bothcompressthestringinto14bits.Anothersetofcodecanbegivenas{'

=11,'

=100,'

=101},but{'

=011,'

=001}isNOTcorrectsince“aaaxuaxz”and“aazuaxax”canbothbedecodedfromthecode00001011001001.Thestudentsaresubmittingallkindsofcodes,andIneedacomputerprogramtohelpmedeterminewhichonesarecorrectandwhichonesarenot.

OurpurposeistojudgewhetherthesubmissionofthestudentsisHuffmancodeornot.

Firstweshouldmentionthatthecodethatgenetaredbythehuffmanalgorithmisuniquecausethenodeswillbesortedbeforecreatingthetree,while,generally,Huffmancodeisnotunique,justbecauseunsotednodeshavemanysequences.Itwillbeanimportantpointwhileconsideringthealgorithm.Youwillseemoredetailsinthenextchapter:

AlgorithmsSpecification.

Background:

AboutDavidA.Huffman(August9,1925–October7,1999):

DavidA.Huffmanwasapioneerinthecomputersciencefield.Throughouthislife,Huffmanmademanyimportantcontributionstothestudyoffinitestatemachines,switchingcircuits,synthesisprocedures,andsignaldesignsetc.

However,DavidHuffmanisbestknownforhislegendary“Huffmancode”,whichwewillstudyinthisproject,acompressionschemeforlosslessvariablelengthencoding.ItwastheresultofatermpaperhewrotewhileagraduatestudentattheMassachusettsInstituteofTechnology(MIT),whereheearnedaScDdegreeonathesisnamedTheSynthesisofSequentialSwitchingCircuits,advisedbySamuelH.Caldwell(1953).[1]

"

HuffmanCodes"

arewidelyusedinnearlyeveryapplicationthatinvolvesthecompressionandtransmissionofdigitaldata,suchasfaxmachines,modems,computernetworks,andhigh-definitiontelevision(HDTV),whichiswidelyusedinmodernsociety.

AboutHuffmancode:

AlgorithmSpecification

DataStructures:

MainDataStructureforaHuffmanTreeTreeNode:

typedefstruct

{

unsignedintweight;

unsignedintparent,lchild,rchild;

}HTNode;

Algorithms:

1.First,bulidtheHuffmantree:

for(i=n+1;

i<

=m;

++i)

{

select(*HT,i-1,&

s1,&

s2);

/*selectthetwosmallestnodewhoseparentiszerofromHT[1]toHT[i-1]*/

(*HT)[s1].parent=(*HT)[s2].parent=i;

(*HT)[i].lchild=s1;

(*HT)[i].rchild=s2;

(*HT)[i].weight=(*HT)[s1].weight+(*HT)[s2].weight;

}

BulidingmethodHuffmantree:

1.choosethesmallesttwonumberofthearray,assighitsparentpointertoi;

2.assighitsweightrightafterthat.

Thendoitrepeatedly.sowegottheHuffmantree.

Nowillustratingit:

Doitbyuppermethodrepeadly:

Finalstate:

NowwegotHuffmantree!

2.ThenwecalculatetheWPLofthestandardHuffmantree.

for(i=1;

=n;

i++)

{

WPL=WPL+w[i-1]*strlen(HC[i]);

/*calculatetogetthevalueofWPL*/

}

3.CalculatetheWPLoftheinputsubmissions.

sum=0;

/*initializationsum*/

for(i=0;

n;

{

scanf("

%s"

&

c);

getchar();

gets(string[i]);

sum=sum+w[i]*strlen(string[i]);

/*thetotallengthofcodeneededtodetermine*/

}

4.CompareWPLandWPL’

Ifthemareequalinputcaseright.Elsecheckwhetherinputcasehavetherelationshipofprefixion

if(sum!

=WPL)/*ifsumnotequalsWPL,thenwecansaynoimmediately*/

printf("

No\n"

);

else/*ifnot,weneedtolookwhethertheyhavetherelationshipofprefixion*/

{

for(k=0;

k<

k++)

{

for(i=k+1;

{

l=strlen(string[k]);

if(strlen(string[i])<

l)

l=strlen(string[i]);

r=strncmp(string[i],string[k],l);

if(r==0)break;

if(r==0)

printf("

break;

}

else

if(k==n-1){

printf("

Yes\n"

}

}

TestingResults

1.Sampletest

Sampleinputofthisproject:

SampleInput:

4

a4x2u1z1

2

a0

x10

u110

z111

x01

u011

z001

7

A1B1C1D3E3F6G6

A00000

B00001

C0001

D001

E01

F10

G11

A000

B001

C010

D011

E100

F101

G110

Ouputresultoftheprogrmme:

Compareitwiththecorrectoutput:

Case1:

Yes

No

Case2:

Wecanseeitcorrespondsverywell,soitisRight!

Analysis[justonNo]:

AboutfirsNo:

a0x01sowecanseethata’scodeistheprefixofx’s,thoughithavetheshotestWPL.

AboutsecondNo:

Thoughtheredonotexistprefix-relationship,butitsWPLisnottheshotestsoitisnotHuffmancode.

2.FurtherTest

A.somesmall-mediumscaletestdata:

BecauseitiseasytocreatesmalltestcasessoIjustcreatethembyhand.

a3b4c5d6

a00

b01

c10

d11

a11

b10

c01

d00

a01

c00

20

a1b2c3d4e5f6g7h8i9j10k11l12m13n14o15p16q17r18s19t20

1

a1010000

b1010001

c101001

d101010

e101011

f10000

g10001

h11000

i11001

j0100

k0101

l0110

m0111

n1001

o1011

p1101

q1110

r1111

s000

t001

Output:

Analysis:

Isimplyaddsomecodeintheprogromtheprogrammerhandtome.

Here:

And:

Sothecontentintheouputfilearechangedasfollows:

WPL:

36Case1:

WPL'

:

36Yes

864Case2:

866No

Nowwecanseeitclearlytheformerfourcases’WPLcorrespondwithshotestWPLwell,sotheprogramprint“Yes”immediately。

Whileinthecasetwo.WPL'

=866>

WPL=864,soitisnottheHuffmancode.soprintfNo!

Toconclude:

Testingofthesesetoftestcasesareallright.

B.LargeScaletestdata

inthistestIprovidesometestcasethataregeneratedbyprogram,sothattestwhetherthenon-prifixjudgingisrightornot.

Ijustchangethesampleinput.

Inputcases:

AnalysisandComments

Timecomplexity&

spacecomplexityAnalysis

SomeFurtherComments

Furtherimprovement:

A.Aboutalgorithm:

ThisalgorithmfirstneedtocreateanHuffmantreetocalculatethesmallestWPLofcertaininputcharacters,andthenitcalculatetheinput

WPL,andcomparethem.ImeancalculatingWPLbycreatingaHuffmantreewillbecosty.Itcanbeimprovedusinganotheralgorithm,whileitisreallydifficulttowrite.Iftimepermititwillbeapotentialbreakthroughpointinthisprogramme.

B.AboutOthers:

1.Theuserinterfaceoftheprogramcanbemorefriendly.

2.Theoverallstyleofthedocumentcanbesmarter.

3.Ourgroupwrkingcanbemoreefficient.

SourceCode(inC)

AppendixII:

DutyAssignments

Programmer王园园3072211113

Tester王迪3079901015

ReportWriter郭宇波3079901016

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 求职职场 > 简历

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2