




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
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等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年股份質押擔保借款合同范本
- 軌道交通線網(wǎng)云平臺系統(tǒng)用戶需求書-中心部分網(wǎng)絡安全專用技術要求
- 2025酒店管理承包合同模板
- 2025廢舊鋼材購銷合同范本
- 2025店面轉讓合同樣本
- 2025上海市空氣凈化設備維護保養(yǎng)合同
- 2025雇傭離職人員的勞務合同
- 2025年三資企業(yè)承包經(jīng)營合同范本
- 2025版終止房屋租賃合同范本
- 2025建筑工程分包合同(2)
- 初中數(shù)學課程標準(2021版)
- 《生物冶金》課程教學大綱
- DB22-T 5118-2022 建筑工程資料管理標準
- 工程地質測繪ppt版(共61頁)
- 水文地質與工程地質勘察工程地質測繪PPT
- 崩塌易發(fā)程度數(shù)量化評分表
- 年產(chǎn)10000噸耐高溫α-淀粉酶發(fā)酵車間設計
- 機組黑啟動方案
- 平衡計分卡及戰(zhàn)略地圖
- 《觀潮》學歷案案例
- 附件:湖北省重點水利水電工程施工招標投標評分標準-鄂水
評論
0/150
提交評論