版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
PAGE
11
3Projects
3.1Project1:PerformanceMeasurement
Givenalistoforderedintegers,numberedfrom0to–1,checkingtoseethatNisnotinthislistprovidesaworstcaseformanysearchalgorithms.
Considertwoalgorithms:oneiscalled“sequentialsearch”whichscansthroughthelistfromlefttoright;andtheotheris“binarysearch”whichisgivenonpage24(Figure2.9)ofyourtextbook.Yourtasksare:
Implementaniterativeversionandarecursiveversionofsequentialsearch;
Implementaniterativeversionofbinarysearch;
Analyzetheworstcasecomplexitiesoftheabovetwoversionsofsequentialsearchandthatofbinarysearch;
Measureandcomparetheworstcaseperformancesoftheabovethreefunctionsfor=100,500,1000,2000,4000,6000,8000,10000.
Tomeasuretheperformanceofafunction,wemayuseC’sstandardlibrarytime.hasthefollowing:
Note:Ifafunctionrunssoquicklythatittakeslessthanaticktofinish,wemayrepeatthefunctioncallsforKtimestoobtainatotalruntime(“TotalTime”),andthendividethetotaltimebytoobtainamoreaccurateduration(“Duration”)forasinglefunofthefunction.Therepetitionfactormustbylargeenoughsothatthenumberofelapsedticksisatleast10ifwewantanaccuracyofatleast10%.
Thetestresultsmustbelistedinthefollowingtable:
Theperformancesofthethreefunctionsmustbeplottedinthesame-run_timecoordinatesystemforillustration.
3.2Project2:ImplementationofLists,andPolynomial
Problems
1.Mergetwoorderedlistsintoanewlinkedlistinwhichthenodesarealsointhisorder.Iflengthsoforiginaltwolistsaremandn,thelengthofnewlinkedlistism+n.
Forexample:
Input:
5(lengthoflist1)
4
26465695
11(lengthoflist2)
15
17263046485658829095
Output:
41517263046485658829095
Demands:
(1).Youshouldusesinglelinkedlist(withaheader)tocreatethefunctionsMakeEmpty,IsEmpty,IsLast,Find,Delete,FindPrevious,Insert,DeleteList,Header,First,Advance,Retrieve(SeeP40,Figure3.6).
(2).Usingabovefunctionstosolvethisproblem.
(3).Thelinkedimplementationoflistshouldbewritteninseparatedfiles(.cppand.h)intheVC++workspace.Theirnamesshouldbelinkedlist.h,linkedlist.cpp,merge.cpp.
2.ThedeclarationsthatfollowgiveusthepolynomialADT.
StructurePolynomialis
Object:;asetoforderedpairsofwhereisthecoefficientandistheexponent.arenonnegativeintegers.
Operations:
Forallpoly,poly1,poly2∈Polynomial,coef∈Coefficients,expon∈Exponents
PolynomialZero()::=returnthepolynomial,P(x)=0
BooleanIsZero(poly)::=if(poly)returnFALSE;
elsereturnTRUE;
CoefficientCoef(poly,expon)::=if(expon∈poly)returnitscoeffient
elsereturnzero.
ExponentLead_Exp(poly)::=returnthelargestexponentinpoly.
PolynomialAttach(poly,coef,expon)::=if(expon∈poly)returnerror
elsereturnthepolynomialpolywiththeterm<coef,expon>inserted.
PolynomialRemove(poly,expon):=if(expon∈poly)returnthepolynomialpolywiththetermwhoseexponentisexpondeleted
elsereturnerror.
PolynomialSingleMult(poly,coef,expon):=returnthepolynomialpoly*coef*xexpon
PolynomialAdd(poly1,poly2):=returnthepolynomialpoly1+poly2.
PolynomialMult(poly1,poly2):=returnthepolynomialpoly1*poly2.
endPolynomial
Demands:
(1).YoushouldchooseasuitablerepresentationforPolynomial.
(2).YoushouldcreatethefunctionsZero,IsZero,Coef,Lead_Exp,Attach,Remove,SingleMult,Add,Mult,andtestthem.
(3).Ifand,writeafunctiontouseabovefunctionstocomputeand.
(4).Analyzeadvantagesofyourrepresentation.
(5).TheimplementationofpolynomialADTshouldbewritteninseparatedfiles(.cppand.h)intheVC++workspace.TheirnamesshouldbePolynomial.h,Polynomial.cpp,main.cpp.
Note:
Yourprogrammustreadfromafile“input.txt”andwritetoafile“output.txt”inthecurrentdirectory.
3.3Project3:ImplementationandApplicationsofStacks
Problems
1.WriteaConversionfunctiontoconverseanydecimaldatatobinaryversion.
Demands:
(1).ImplementStackADTusinglinkedlistrepresentation,whichmustatleasthasfivebasicoperations:Create,IsFull,Push,IsEmptyandPop.
(2).BuildanewprojecttoimplementtheConversionfunction.Theinputandoutputshouldbeaccordingtothefollowingformat:
Pleaseinputthedecimalnumber:15
Thecorrespondingbinaryversionis:1111
Pleaseinputthedecimalnumber:-1
Bye!
2.Writeaprogramtojudgewhetherabracketsequence(maybehasotherletters)is“matching”.The“matching”meansthatiftherehasa‘(‘inaexpressionandtheremusthasa‘)’init.Iftheinputsequenceis“matching”,thenoutput‘ok’,otherwiseoutput‘ERROR’.
Demands
(1).ImplementStackusingarrayrepresentation,whichmustatleasthasfivebasicoperations:Create,IsFull,Push,IsEmptyandPop.
(2).BuildanewprojecttoimplementthebracketMatchingfunction.Theinputandoutputshouldbeaccordingtothefollowingformat:
Pleaseinputtheexpression:a*(b+c)
ThebracketoftheexpressionismatchingOK!
Pleaseinputtheexpression:a*(b+c))
ThebracketoftheexpressionismatchingERROR!
Pleaseinputtheexpression:(a*(b+c)
ThebracketoftheexpressionismatchingERROR!
Note
ThetwoimplementationofStackshouldbewritteninseparatedfiles(.cppand.h)intheVC++workspace.Theirfilesshouldbenameddifferently,suchaslinkedStack.h,linkedStack.cpp,SqStack.h,SqStack.cpp.
3.4Project4:BinaryTreeTraversals
1.Problem
Createbinarytreeasfollow(Figure-1)incomputer,writeoutthefunctionsofinorder,preorder,postorderandlevelorder,andusethemtotraversalthebinarytree.Andcomputetheleafnumberandheightofthebinarytree.
Hint:Youmaychoosesuitablerepresentation,suchaslinkedrepresentationisoftenused.
Figure-1abinarytree
2.Stepsandrestrictconditions
Step1.
Writethefunctionofcreatetocreateatreebyinputdata.
Step
2.
Writerecursiveversionfunctionsofinorder,preorderandpostordertotraversalthetree.
Step
3.
SelectasuitablerepresentationtoimplementstackADT,whichmustatleasthasfivebasicoperations:Create,IsFull,Push,IsEmptyandPop.Theelementtypeinthestackispointerofnode.
Step
4.
ImplementQueueADTrepresentedbycircularqueue,whichhassevenbasicoperations:CreateQueue,IsEmpty,DisposeQueue,MakeEmpty,EnQueue,Front,DeQueue.Theelementtypeinthequeueispointerofnode.
Step
5.
Writeaniterativeversionofinorder,thenameisiter_inorder()toinordertraversaltree.
Step
6.
Writeafunctionforlevelordertraversalofbinarytree,thenameislevel_order.
Step7.Writeafunctiontocomputetheleafnumberofthebinarytree,thenameisleaf.
Step8.Writeafunctiontocomputetheheightofthebinarytree,thenameisheight.
3.5Project5:JumpingtheQueue:anACMProblem
ThebeginningofawinterbreaknearSpringFestivalisalwaysthebeginningofapeakperiodoftransportation.Ifyouhaveevertriedtogetatrainticketatthattime,youmusthavewitnessedtheendlessqueuesinfrontofeveryticketboxwindow.Ifaguyhasseenhisfriendinaqueue,thenitisverymuchlikelythatthisluckyguymightgostraighttohisfriendandaskforafavor.Thisiscalled"jumpingthequeue".Itisunfairtotherestofthepeopleintheline,but,itislife.Yourtaskistowriteaprogramthatsimulatessuchaqueuewithpeoplejumpingineverynowandthen,assumethat,ifoneinthequeuehasseveralfriendsaskingforfavors,hewouldarrangetheirrequestsinaqueueofhisown.
InputSpecification:
Yourprogrammustreadtestcasesfromafile“input.txt”.Theinputfilewillcontainoneormoretestcases.Eachtestcasebeginswiththenumberofgroupsn(1<=n<=100).Thenngroupdescriptionsfollow,eachoneconsistingofthenumberoffriendsbelongingtothegroupandthosepeople'sdistinctnames.Agroupisafriendgroup.Peopleinonegrouparefriendwitheachother.Anameisastringofupto4characterschosenfrom{A,B,...,Z,a,b,...,z}.Agroupmayconsistofupto1000friends.Youmayassumethatthereisnoonebelongtotwodifferentgroups.
Finally,alistofcommandsfollows.Therearethreedifferentkindsofcommands:
ENQUEUEX-Mr.orMs.Xgoesintothequeue
DEQUEUE-thefirstpersongetstheticketandleavethequeue
STOP-endoftestcase
Theinputwillbeterminatedbyavalueof0forn.
OutputSpecification:
Outputallresultstoafile“output.txt”.Foreachtestcase,firstprintalinesaying"Scenario#k",wherekisthenumberofthetestcase.Then,foreachDEQUEUEcommand,printthepersonwhojustgetsaticketonasingleline.Printablanklinebetweentwotestcases,butnoextralineattheendofoutput.
SampleInput:
2
3AnnBobJoe
3ZoeJimFat
ENQUEUEAnn
ENQUEUEZoe
ENQUEUEBob
ENQUEUEJim
ENQUEUEJoe
ENQUEUEFat
DEQUEUE
DEQUEUE
DEQUEUE
DEQUEUE
DEQUEUE
DEQUEUE
STOP
2
5AnnyJackJeanBillJane
6EvaMikeRonSonyGeoZoro
ENQUEUEAnny
ENQUEUEEva
ENQUEUEJack
ENQUEUEJean
ENQUEUEBill
ENQUEUEJane
DEQUEUE
DEQUEUE
ENQUEUEMike
ENQUEUERon
DEQUEUE
DEQUEUE
DEQUEUE
DEQUEUE
STOP
0
SampleOutput:
Scenario#1
Ann
Bob
Joe
Zoe
Jim
Fat
Scenario#2
Anny
Jack
Jean
Bill
Jane
Eva
3.6Project6:PerformancesMeasurementofSortingAlgorithms
1.Problems
(1).SortthelistbyInsertionSort,ShellSort,QuickSort,MergeSortandHeapSort,respectively.Andoutputeverypassresultofthem.
Input:(alist)
265371611159154819
Output:theeverypassresultofthem.
Notes:youshouldprinttheoriginallist,everypassresultandthelastresults.
(2).MeasureperformancesofInsertionSort,ShellSort,QuickSort,MergeSortandHeapSortforrandomdata.
2.Stepsandrestrictconditions
(1).ImplementfunctionsofInsertionSort,ShellSort,QuickSort,MergeSortandHeapSort.
(2).OutputeverypassresultofinputlistL={265371611159154819}byexecutethesefunctions.
(3).Analyzetheworstcasecomplexitiesofallabovealgorithms;
(4).Measureperformancesoftheabovefunctionsfor=100,500,1000,2000,4000,5000,10000,20000.
Youmayuserandomlibraryfunctiontocreatethetestingdatafirstly.Second,sortitusingabovealgorithmsalternately.Finally,measuretheirperformances.
Togeneratealistrandomdata,wemayuseC’sstandardlibrarystdlib.hasthefollowing:
3.7Project7:TraversalsandApplicationsofGraph
1.Problem
Givenadirectedgraph(seeFigure2),usetheadjacencylistmethodtorepresentit,andoutputthesequenceofvertexnamesgettingfromDepth-FirstSearchandBreadth-FirstSearch.AndGivenasourcev0,Determineashortestpathtoeachv∈V(G)\{v0}andoutputthem.
2.InputandOutputDemand
Input:thenumberofvertex,thenumberofedge,alledges(Vi,Vj)anditsweightinagraph.
Output:
(1).printthegraph.
(2).printthesequenceofvertexnamesgettingfromDepth-FirstSearch.
(3).printthesequenceofvertexnamesgettingfromBreadth-FirstSearch.
Forexample(SeeFigure1):
Input:
611//indicatethegraphincludingsixvertexesandelevenedges.
0150//indicateanedgefromV0toV1.
0210
0445
1215
1410
2020
2315
3120
3435
4330
533
Figure2
Output:
0:124
1:24
2:03
3:14
4:3
5:3
ThesequenceofvertexnamesgettingfromDepth-FirstSearch(from‘V1’):
V1V2V0V4V3V5
ThesequenceofvertexnamesgettingfromBreadth-FirstSearch(from‘V1’):
V1V2V4V0V3V5
Shortestpathsfromv0toeachvertexare
V0toV145
V0toV210
V0toV325
V0toV445
V0toV51000
(“1000”meansnopath.)
3.Stepsandrestrictconditions:
Step1.ImplementDepth-FirstSearchAlgorithm;
Step2.ImplementQueueADTrepresentedbycircularqueue,whichhassevenbasicoperations:CreateQueue,IsEmpty,DisposeQueue,MakeEmpty,EnQueue,Front,DeQueue.Theelementtypeispointerofnode;
Step3.ImplementBreadth-FirstSearchAlgorithm;
Step4.Writeafunctiontodetermineashortestpathfromvitoeachv∈V(G)\{vi}.
Note:
Yourprogrammustreadfromafile“input.txt”andwritetoafile“output.txt”inthecurrentdirectory.
4MinimumRequirementsonWritingaProjectReport
TitleofProject
Class
GroupID
DateofCompletion
mm-dd-yy
1.Introduction
Problemdescriptionand(ifany)backgroundofthealogithms.
2.AlgorithmSpecification
Description(pseudo-codepreferred)ofallthealgorithmsinvolvedforsolvingtheproblem,includingspecificationsofmaindatastructures.
3.TestingResults
Tableoftestcases.Eachtestcaseusual
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 渠道經(jīng)理周工作總結(jié)
- 二零二五年度桉樹砍伐與木材電商平臺(tái)合作合同3篇
- 2025年度旅行社員工勞動(dòng)合同解除規(guī)范文本3篇
- 知到智慧樹網(wǎng)課《演講學(xué)(同濟(jì)大學(xué))》章節(jié)測試滿分答案
- 2025年度特許經(jīng)營合同(含加盟費(fèi)用)3篇
- 小學(xué)教育創(chuàng)新實(shí)踐的成果與經(jīng)驗(yàn)分享
- 2025年度租賃合同(包含設(shè)備、房產(chǎn)、車輛等)3篇
- 二零二五年度建筑工地勞務(wù)用工與施工現(xiàn)場文明施工管理合同3篇
- 小學(xué)課外勞動(dòng)教育實(shí)踐與文化傳承的橋梁
- 2025年度民間私人借款及擔(dān)保服務(wù)合同范本9篇
- 《太陽能光伏技術(shù)》課件
- 2024年職業(yè)素養(yǎng)與商務(wù)禮儀培訓(xùn)資料
- 外科醫(yī)生年終述職總結(jié)報(bào)告
- 兒科課件:急性細(xì)菌性腦膜炎
- 柜類家具結(jié)構(gòu)設(shè)計(jì)課件
- 建設(shè)項(xiàng)目管理費(fèi)用(財(cái)建2016504號(hào))
- 煤炭運(yùn)輸安全保障措施提升運(yùn)輸安全保障措施
- JTGT-3833-2018-公路工程機(jī)械臺(tái)班費(fèi)用定額
- LDA型電動(dòng)單梁起重機(jī)參數(shù)
- 保安巡邏線路圖
- (完整版)聚乙烯課件
評(píng)論
0/150
提交評(píng)論