![(第1版)數(shù)據(jù)結(jié)構(gòu)實驗指導_第1頁](http://file4.renrendoc.com/view/fd77b7c9f27bb724c7d8993f263e0a2f/fd77b7c9f27bb724c7d8993f263e0a2f1.gif)
![(第1版)數(shù)據(jù)結(jié)構(gòu)實驗指導_第2頁](http://file4.renrendoc.com/view/fd77b7c9f27bb724c7d8993f263e0a2f/fd77b7c9f27bb724c7d8993f263e0a2f2.gif)
![(第1版)數(shù)據(jù)結(jié)構(gòu)實驗指導_第3頁](http://file4.renrendoc.com/view/fd77b7c9f27bb724c7d8993f263e0a2f/fd77b7c9f27bb724c7d8993f263e0a2f3.gif)
![(第1版)數(shù)據(jù)結(jié)構(gòu)實驗指導_第4頁](http://file4.renrendoc.com/view/fd77b7c9f27bb724c7d8993f263e0a2f/fd77b7c9f27bb724c7d8993f263e0a2f4.gif)
![(第1版)數(shù)據(jù)結(jié)構(gòu)實驗指導_第5頁](http://file4.renrendoc.com/view/fd77b7c9f27bb724c7d8993f263e0a2f/fd77b7c9f27bb724c7d8993f263e0a2f5.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領
文檔簡介
3Projects
3.1Project1:PerformanceMeasurement
GivenalistoforderedNintegers,numberedfrom0toN–1,checkingtoseethatNis
notinthislistprovidesaworstcaseformanysearchalgorithms.
Considertwoalgorithms:oneiscalled“sequentialsearch”whichscansthroughthelist
fromlefttoright;andtheotheris“binarysearch”whichisgivenonpage24(Figure2.9)of
yourtextbook.Yourtasksare:
(1)Implementaniterativeversionandarecursiveversionofsequentialsearch;
(2)Implementaniterativeversionofbinarysearch;
(3)Analyzetheworstcasecomplexitiesoftheabovetwoversionsofsequentialsearch
andthatofbinarysearch;
(4)Measureandcomparetheworstcaseperformancesoftheabovethreefunctionsfor
N=100,500,1000,2000,4000,6000,8000,10000.
Tomeasuretheperformanceofafunction,wemayuseC?sstandardlibrarytime.hasthe
following:
Note:Ifafunctionrunssoquicklythatittakeslessthanaticktofinish,wemayrepeatthe
functioncallsforKtimestoobtainatotalruntime(“TotalTime”),andthendividethetotaltime
byKtoobtainamoreaccurateduration(“Duration”)forasinglefunofthefunction.The
repetitionfactormustbylargeenoughsothatthenumberofelapsedticksisatleast10ifwe
wantanaccuracyofatleast10%.
Thetestresultsmustbelistedinthefollowingtable:
1
TheperformancesofthethreefunctionsmustbeplottedinthesameN-run_timecoordinate
systemforillustration.
2
3.2Project2:ImplementationofLists,andPolynomial
Problems
1.Mergetwoorderedlistsintoanewlinkedlistinwhichthenodesarealsoin
thisorder.Iflengthsoforiginaltwolistsaremandn,thelengthofnewlinked
listism+n.
Forexample:
Input:
5(lengthoflist1)
426465695
11(lengthoflist2)
1517263046485658829095
Output:
41517263046485658
829095
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)inthe
VC++workspace.Theirnamesshouldbelinkedlist.h,linkedlist.cpp,merge.cpp.
2.ThedeclarationsthatfollowgiveusthepolynomialADT.
StructurePolynomialis
e,awherea
Object:P(x)axe1axen;asetoforderedpairsof
is
1
n
i
i
i
thecoefficientande
istheexponent.arenonnegativeintegers.
e
i
i
Operations:
Forallpoly,poly1,poly2∈Polynomial,coef∈Coefficients,expon∈Exponents
PolynomialZero()
::=returnthepolynomial,P(x)=0
::=if(poly)returnFALSE;
elsereturnTRUE;
BooleanIsZero(poly)
CoefficientCoef(poly,expon)
::=if(expon∈poly)returnitscoeffient
3
elsereturnzero.
ExponentLead_Exp(poly)
::=returnthelargestexponentinpoly.
PolynomialAttach(poly,coef,expon)::=if(expon∈poly)returnerror
elsereturnthepolynomialpolywiththeterm
<coef,expon>inserted.
PolynomialRemove(poly,expon)
:=if(expon∈poly)returnthepolynomialpolywith
thetermwhoseexponentisexpondeleted
elsereturnerror.
PolynomialSingleMult(poly,coef,expon):=returnthepolynomialpoly*coef*xexpon
PolynomialAdd(poly1,poly2)
PolynomialMult(poly1,poly2)
endPolynomial
:=returnthepolynomialpoly1+poly2.
:=returnthepolynomialpoly1*poly2.
Demands:
(1).YoushouldchooseasuitablerepresentationforPolynomial.
(2).YoushouldcreatethefunctionsZero,IsZero,Coef,Lead_Exp,Attach,Remove,
SingleMult,Add,Mult,andtestthem.
(3).IfA(x)3x202x54andB(x)3x2x3x1,writeafunctiontouse
432
abovefunctionstocomputeC(x)A(x)B(x)andD(x)A(x)*B(x).
(4).Analyzeadvantagesofyourrepresentation.
(5).TheimplementationofpolynomialADTshouldbewritteninseparatedfiles(.cppand.h)
intheVC++workspace.TheirnamesshouldbePolynomial.h,Polynomial.cpp,
main.cpp.
Note:
Yourprogrammustreadfromafile“input.txt”andwritetoafile“output.txt”inthe
currentdirectory.
4
3.3Project3:ImplementationandApplicationsofStacks
Problems
1.WriteaConversionfunctiontoconverseanydecimaldatatobinaryversion.
Demands:
(1).ImplementStackADTusinglinkedlistrepresentation,whichmustatleasthasfivebasic
operations:Create,IsFull,Push,IsEmptyandPop.
(2).BuildanewprojecttoimplementtheConversionfunction.Theinputandoutputshouldbe
accordingtothefollowingformat:
Pleaseinputthedecimalnumber:15
Thecorrespondingbinaryversionis:1111
Pleaseinputthedecimalnumber:-1
Bye!
2.Writeaprogramtojudgewhetherabracketsequence(maybehasother
letters)is“matching”.The“matching”meansthatiftherehasa?(?ina
expressionandtheremusthasa?)?init.Iftheinputsequenceis“matching”,
thenoutput?ok?,otherwiseoutputE?RROR?.
Demands
(1).ImplementStackusingarrayrepresentation,whichmustatleasthasfivebasicoperations:
Create,IsFull,Push,IsEmptyandPop.
(2).BuildanewprojecttoimplementthebracketMatchingfunction.Theinputandoutput
shouldbeaccordingtothefollowingformat:
Pleaseinputtheexpression:a*(b+c)
ThebracketoftheexpressionismatchingOK!
Pleaseinputtheexpression:a*(b+c))
ThebracketoftheexpressionismatchingERROR!
Pleaseinputtheexpression:(a*(b+c)
ThebracketoftheexpressionismatchingERROR!
5
Note
ThetwoimplementationofStackshouldbewritteninseparatedfiles(.cppand.h)inthe
VC++workspace.Theirfilesshouldbenameddifferently,suchaslinkedStack.h,
linkedStack.cpp,SqStack.h,SqStack.cpp.
6
3.4Project4:BinaryTreeTraversals
1.Problem
Createbinarytreeasfollow(Figure-1)incomputer,writeoutthefunctionsofinorder,
preorder,postorderandlevelorder,andusethemtotraversalthebinarytree.Andcomputethe
leafnumberandheightofthebinarytree.
Hint:Youmaychoosesuitablerepresentation,suchaslinkedrepresentationisoftenused.
Figure-1abinarytree
2.Stepsandrestrictconditions
Step1.Writethefunctionofcreatetocreateatreebyinputdata.
Step2.Writerecursiveversionfunctionsofinorder,preorderandpostordertotraversalthe
tree.
Step3.SelectasuitablerepresentationtoimplementstackADT,whichmustatleasthasfive
basicoperations:Create,IsFull,Push,IsEmptyandPop.Theelementtypeinthe
stackispointerofnode.
Step4.ImplementQueueADTrepresentedbycircularqueue,whichhassevenbasic
operations:CreateQueue,IsEmpty,DisposeQueue,MakeEmpty,EnQueue,Front,
DeQueue.Theelementtypeinthequeueispointerofnode.
Step5.Writeaniterativeversionofinorder,thenameisiter_inorder()toinordertraversaltree.
Step6.Writeafunctionforlevelordertraversalofbinarytree,thenameislevel_order.
Step7.Writeafunctiontocomputetheleafnumberofthebinarytree,thenameisleaf.
Step8.Writeafunctiontocomputetheheightofthebinarytree,thenameisheight.
7
3.5Project5:JumpingtheQueue:anACMProblem
ThebeginningofawinterbreaknearSpringFestivalisalwaysthebeginning
ofapeakperiodoftransportation.Ifyouhaveevertriedtogetatrainticketatthat
time,youmusthavewitnessedtheendlessqueuesinfrontofeveryticketbox
window.Ifaguyhasseenhisfriendinaqueue,thenitisverymuchlikelythatthis
luckyguymightgostraighttohisfriendandaskforafavor.Thisiscalled"jumping
thequeue".Itisunfairtotherestofthepeopleintheline,but,itislife.Yourtaskis
towriteaprogramthatsimulatessuchaqueuewithpeoplejumpingineverynow
andthen,assumethat,ifoneinthequeuehasseveralfriendsaskingforfavors,he
wouldarrangetheirrequestsinaqueueofhisown.
InputSpecification:
Yourprogrammustreadtestcasesfromafile“input.txt”.Theinputfilewill
containoneormoretestcases.Eachtestcasebeginswiththenumberofgroupsn
(1<=n<=100).Thenngroupdescriptionsfollow,eachoneconsistingofthe
numberoffriendsbelongingtothegroupandthosepeople'sdistinctnames.Agroup
isafriendgroup.Peopleinonegrouparefriendwitheachother.Anameisastring
ofupto4characterschosenfrom{A,B,...,Z,a,b,...,z}.Agroupmayconsistof
upto1000friends.Youmayassumethatthereisnoonebelongtotwodifferent
groups.
Finally,alistofcommandsfollows.Therearethreedifferentkindsof
commands:
ENQUEUEX-Mr.orMs.Xgoesintothequeue
DEQUEUE-thefirstpersongetstheticketandleavethequeue
STOP-endoftestcase
Theinputwillbeterminatedbyavalueof0forn.
OutputSpecification:
Outputallresultstoafile“output.txt”.Foreachtestcase,firstprintaline
saying"Scenario#k",wherekisthenumberofthetestcase.Then,foreach
DEQUEUEcommand,printthepersonwhojustgetsaticketonasingleline.Print
ablanklinebetweentwotestcases,butnoextralineattheendofoutput.
SampleInput:
2
3AnnBobJoe
3ZoeJimFat
ENQUEUEAnn
ENQUEUEZoe
ENQUEUEBob
ENQUEUEJim
ENQUEUEJoe
8
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
9
3.6Project6:PerformancesMeasurementofSortingAlgorithms
1.Problems
(1).SortthelistbyInsertionSort,ShellSort,QuickSort,MergeSortandHeapSort,
respectively.Andoutputeverypassresultofthem.
Input:(alist)
265371611159154819
Output:theeverypassresultofthem.
Notes:youshouldprinttheoriginallist,everypassresultandthelastresults.
(2).MeasureperformancesofInsertionSort,ShellSort,QuickSort,MergeSort
andHeapSortforrandomdata.
2.Stepsandrestrictconditions
(1).ImplementfunctionsofInsertionSort,ShellSort,QuickSort,MergeSortandHeapSort.
(2).OutputeverypassresultofinputlistL={265371611159154819}by
executethesefunctions.
(3).Analyzetheworstcasecomplexitiesofallabovealgorithms;
(4).MeasureperformancesoftheabovefunctionsforN=100,500,1000,2000,4000,5000,
10000,20000.
Youmayuserandomlibraryfunctiontocreatethetestingdatafirstly.Second,sortitusing
abovealgorithmsalternately.Finally,measuretheirperformances.
Togeneratealistrandomdata,wemayuseC?sstandardlibrarystdlib.hasthefollowing:
3.7Project7:TraversalsandApplicationsofGraph
1.Problem
Givenadirectedgraph(seeFigure2),usetheadjacencylistmethodtorepresentit,and
outputthesequenceofvertexnamesgettingfromDepth-FirstSearchandBreadth-First
Search.AndGivenasourcev0,Determineashortestpathtoeachv∈V(G)\{v0}andoutput
them.
2.InputandOutputDemand
Input:thenumberofvertex,thenumberofedge,alledges(Vi,Vj)anditsweightinagraph.
Output:
(1).printthegraph.
(2).printthesequenceofvertexnamesgettingfromDepth-FirstSearch.
(3).printthesequenceofvertexnamesgettingfromBreadth-FirstSearch.
Forexample(SeeFigure1):
Input:
611
//indicatethegraphincludingsixvertexesandelevenedges.
//indicateanedgefromV0toV1.
0150
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?):
11
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.The
elementtypeispointerofnode;
Step3.ImplementBreadth-FirstSearchAlgorithm;
Step4.Writeafunctiontodetermineashortestpathfromvitoeachv∈V(G)\{vi}.
Note:
Yourprogrammustreadfromafile“input.txt”andwritetoafile“output.txt”inthe
currentdirectory.
12
4MinimumRequirementsonWritingaProjectReport
TitleofProject
Class
GroupID
DateofCompletionmm-dd-yy
1.Introduction
Problemdescriptionand(ifany)backgroundofthealogithms.
2.AlgorithmSpecification
Description(pseudo-codepreferred)ofallthealgorithmsinvolvedforsolvingtheproblem,
includingspecificationsofmaindatastructures.
3.TestingResults
Tableoftestcases.Eachtestcaseusuallyconsistsofabriefdescriptionoft
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 湘師大版道德與法治九年級下冊3.1《多民族的大家庭》聽課評課記錄
- 教科版道德與法治八年級上冊6.2《公民的責任》聽課評課記錄
- 魯教版數(shù)學六年級上冊2.1《0科學計數(shù)法》聽評課記錄
- 岳麓版歷史七年級上冊第18課《漢代的科技與文化》聽課評課記錄
- 蘇科版數(shù)學九年級下冊5.1《二次函數(shù)》講聽評課記錄
- 五年級數(shù)學聽評課記錄表
- 人教版九年級數(shù)學上冊第二十二章二次函數(shù)《22.2二次函數(shù)與一元二次方程》第1課時聽評課記錄
- 【2022年新課標】部編版七年級上冊道德與法治第六課 交友的智慧 2課時聽課評課記錄
- 韓式餐廳承包經(jīng)營合同范本
- 個人入股分紅協(xié)議書范本
- 中國服裝零售行業(yè)發(fā)展環(huán)境、市場運行格局及前景研究報告-智研咨詢(2025版)
- 臨床提高膿毒性休克患者1h集束化措施落實率PDCA品管圈
- 春節(jié)節(jié)后施工復工安全培訓
- GB/T 3478.1-1995圓柱直齒漸開線花鍵模數(shù)基本齒廓公差
- GB/T 1346-2001水泥標準稠度用水量、凝結(jié)時間、安定性檢驗方法
- FZ/T 25001-2012工業(yè)用毛氈
- 瑞幸咖啡SWOT分析
- DL∕T 1867-2018 電力需求響應信息交換規(guī)范
- 小學生品德發(fā)展水平指標評價體系(小學)
- 水利工程地震應急預案
- 日歷表空白每月打印計劃表
評論
0/150
提交評論