数据结构题库Word文档下载推荐.docx
《数据结构题库Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《数据结构题库Word文档下载推荐.docx(31页珍藏版)》请在冰豆网上搜索。
(a)itgreatlyincreasesefficiency
(b)itisapowerfulcodereusemechanism
(c)itmakestype-checkingmucheasier
(d)itcanoftenreplacetemplates
9.Considerthefollowingoutlineofatemplatearrayclass.
template<
typenameT>
classArray{...}
Whichofthefollowingistrueaboutusingthisoutlinetoimplementageneralcontainerclass?
(a)Itisapoorchoicesincetemplatesslowdowncompilation.
(b)Itisapoorchoicesincethetypematchingwillslowdownaccessatruntime.
(c)Itisareasonablewaytoimplementsuchaclass.
(d)ItisimpossiblesincethealgorithmcannotknowhowtocopyaninstanceoftypeT.
SSD5选择题Multiple-ChoiceQuiz1答案
2010-09-2415:
40
9.Whichofthefollowingistrueaboutaclasswithouta(user-defined)constructor?
(a)Itcannothaveanassignmentoperator.
(b)Itmusthaveadestructor.
(c)Itcannothaveadestructor.
(d)Itmayhaveadestructor,butmightnot.
Correctansweris(d)
4.Linesatastore,filecabinets,andbookcasesarereal-worldentitiesthatmostresemble_____incomputerscience.
(a)datastructures
(b)functionalprogramminglanguages
(c)object-orientedprogramminglanguages
(d)algorithms
SSD5选择题Multiple-ChoiceQuiz6答案
2010-10-0821:
21
1.Whichofthefollowingisthemainreasonforusingrecursion?
(a)Touselessmemory
(b)Toavoidtemplatesandinheritance
(c)Toimproveefficiency
(d)Toobtainshort,elegantsolutions
Correctansweris(d)
2.Considerthefollowingdefinitionofarecursivefunctionf.
intf(intx)
{
if(x==0)return1;
returnx*f(x);
}
Forwhichinputsxwillthecallf(x)terminate?
(a)Forx=0only
(b)Foralleveninputsxonly
(c)Foralloddinputsxonly
(d)Forallinputsx
Correctansweris(a)
3.ConsiderthefollowingdefinitionofarecursivefunctionffinC++.
intff(intn,intm)
if(n==0)return0;
returnff(n-1,m)+m;
Whichofthefollowingcharacterizesthevaluereturnedbythecallf(n,m)?
(a)Theleastcommonmultiple(最小公倍数)ofmandn
(b)Theproductofmandn
(c)Thegreatestcommondivisor(最大公约数)ofmandn
(d)Thesumofmandn
Correctansweris(b)
4.Considerthefollowingdefinitionofarecursivefunctionf.
returnx*f(x-1);
Theinputsforwhichfwillterminateareallxsuchthatxis
(a)unrestricted
(b)odd
(c)even
(d)non-negative
5.Howmanycallstoitselfisarecursivefunctionallowedtomake?
(a)Atmostone
(b)None
(c)Atmosttwo
(d)Anynumber
6.Considerthefollowingdefinitionofarecursivefunctionf.
boolf(intx)
if((x&
1)==1)return(x==1);
returnf(x>
>
1);
//rightshift
Thevaluereturnedbythecallf(x)willdeterminewhethertheinputxis
(a)even
(b)aprime
(c)apowerof2
(d)odd
Correctansweris(c)
7.Usingabacktrackingtechniquetosolveaproblemtypicallyinvolves
(a)startingwiththesetofallpossiblesolutionsandworkingbackwardsfromeachtodeterminewhichistheactualsolution
(b)usingconcurrencytocheckseveralpossiblesolutionssimultaneously
(c)usingabreadth-firststrategytosearchtheproblemspace
(d)pursuingapossiblesolutionuntilitisfoundtobeasolutionoranon-solution
8.Abacktrackingalgorithmisonethat
(a)usesloopstoiteratethroughallpossiblesolutionsforaproblem
(b)usesrecursiontotestallpossiblesolutionsforaproblem
(c)usesabinarysearchtosolveaproblem
(d)splitsaproblemintotwoequalhalvesandusesrecursiontosolveeachhalf
9.Adivide-and-conqueralgorithmtypicallymakesuseof
(a)integerdivision
(b)recursion
(c)iterationthroughlooping
(d)floating-pointdivision
10.ConsiderthefollowingC++functionthatusesadivideandconquerapproachtocalculatethesumofarangeofnumbers.
intsum(inti,intj){
if(i==j){
returni;
else{
intmid=(i+j)/2;
intresult=sum(i,mid)+sum(mid+1,j);
returnresult;
Whichofthefollowinglinesofcodefromtheabovefunctiondividesthisproblemintosub-problems?
(a)intresult=sum(i,mid)+sum(mid+1,j);
(b)intmid=(i+j)/2;
(c)if(i==j){
(d)returnresult;
3.WhatwouldbetheconsequencesforalgorithmsifrecursionwereremovedfromC++?
(a)None
(b)Allalgorithmscouldstillbeimplemented,butoftenlesselegantly.
(c)Somealgorithmscouldnolongerbeimplemented.
(d)Allalgorithmscouldstillbeimplemented,buttheefficiencywouldoftenbecatastrophicallyworse.
?
6.Considerthefunctiondefinedasfollows.
intf(intn){
if((n&
1)==0)returnf(n/2);
returnf(n/2)+1;
Thevaluereturnedbythecallf(10);
is
(a)5
(b)3
(c)2
(d)1
10.Typicaldivideandconqueralgorithmsuse_____todivideaproblemintosmallersub-problems.The_____typicallysolve(s)thesesub-problemsdirectly.
(a)iteration,bodyoftheloop
(b)inheritance,methodsofthechildclass
(c)recursivefunctioncalls,basecaseoftherecursion
(d)aprocessscheduler,individualprocesses
2.Considerthefollowingdefinitionofarecursivefunctionff.
intff(intn)
if(n==0)return1;
return2*ff(n-1);
Ifn>
0,whatisreturnedbyff(n)?
(a)n^2
(b)2*n
(c)log2n
(d)2^n
5.ConsiderthefollowingdefinitionofarecursivefunctionffinC++.
if(n==0)returnm;
returnff(n-1,m+1);
(a)Thesumofmandn
(c)Theleastcommonmultipleofmandn
(d)Thegreatestcommondivisorofmandn
8.Whichofthefollowingis(are)trueoftheminimaxstrategyfordecidingtheoptimalmoveinatwo-persongame?
I.Itassumesthatahumanplayerwilleventuallymakeamistakebyplayingamovethatisnotoptimal.
II.Itiscommonlyusedwithabacktrackingalgorithm.
(a)IIonly
(b)Ionly
(c)None
(d)IandII
9.Whatistheruntimeoverhead(开支)ofadivide-and-conqueralgorithmthatrecursivelyprocessestwoequalhalvesofaproblemthateachhaveanoverheadofO(n)?
(a)O(nlogn)
(b)O(logn)
(c)O(n2)
(d)O(2n)
8.Whichofthefollowingis(are)trueofrecursivealgorithmsandthebacktrackingproblem-solvingtechnique?
I.Recursivealgorithmsimplementbacktrackingbyreducingaproblemintosmallerandsmallersub-problems.
II.Recursivealgorithmscannotbeusedtoimplementbacktracking.
III.Recursivealgorithmsthatimplementbacktrackingdonottypicallyhaveabasecase.
(a)Ionly
(b)IIonly
(c)IandIIIonly
(d)None
SSD5选择题Multiple-ChoiceQuiz2答案
06
1.Whichofthefollowingistrueaboutvariableswithdynamicextent?
(a)Theyarecreatedbytheprogrammer,butdestroyedbythecompiler.
(b)Theyaredestroyedonlyattheendofexecution.
(c)Theyarecreatedanddestroyedbytheprogrammer.
(d)Theyarecreatedanddestroyedbythecompiler.
2.Whichofthefollowingstatementsproperlyallocatesanarrayof100integers?
(a)int*A=new(int)100;
(b)int*A=newint[100];
(c)int&
A=newint[100];
(d)intA=newint[100];
3.IfAisanarrayof100integers,whichofthefollowingproperlydeallocatesA?
(a)deleteA;
(b)delete[]A;
(c)deleteA[100];
(d)delete[100]A;
1.2.1
1.Linesatastore,filecabinets,andbookcasesarereal-worldentitiesthatmostresemble_____incomputerscience.(a)
(a)datastructures
(b)functionalprogramminglanguages
(c)algorithms
(d)object-orientedprogramminglanguages
2.Incomputerscience,astructuredrepresentationofinformationisknownasa(n)(b)
(a)cache
(b)datastructure
(c)algorithm
(d)processor
3.Anorderedsetofdirectivesthatcanbecarriedoutmechanicallyisknownasa(n)(b)
(a)hashtable
(b)algorithm
(c)associativearray
(d)tree
1.4.3
4.Whichofthefollowingstatementsproperlyallocatesanarrayof100integers?
(a)
(a)int*A=newint[100];
(b)intA=newint[100];
(c)int*A=new(int)100;
(d)int&
2.1.1
2.WhichofthefollowingdatastructuresisnotacontainerimplementedintheC++StandardTemplateLibrary?
(b)
(a)Stack
(b)Hashtable
(c)List
(d)Vector
3.WhichofthefollowingstatementsregardingthedesignoftheStandardTemplate