用C++解决问题第十版Chapter 14.docx
- 文档编号:12738570
- 上传时间:2023-06-07
- 格式:DOCX
- 页数:17
- 大小:17.16KB
用C++解决问题第十版Chapter 14.docx
《用C++解决问题第十版Chapter 14.docx》由会员分享,可在线阅读,更多相关《用C++解决问题第十版Chapter 14.docx(17页珍藏版)》请在冰点文库上搜索。
用C++解决问题第十版Chapter14
TRUE/FALSE
1.Therecanbemorethanonestoppingcaseinarecursivefunction.
ANSWER:
TRUE
2.Youmayhaveatmost1recursivecallinarecursivefunction.
ANSWER:
FALSE
3.Recursivefunctionsmustreturnavalue.
ANSWER:
FALSE
4.Theoperatingsystemusesastacktocontrolrecursion.
ANSWER:
TRUE
5.Aclassmemberfunctionmayberecursive.
ANSWER:
TRUE
6.Recursivefunctionsmayreturnanytypeofvalue
ANSWER:
TRUE
7.Notallrecursivedefinitionsmaybewritteniteratively.
ANSWER:
FALSE
8.Recursivefunctionsalwaysexecutefasterthananiterativefunction.
ANSWER:
FALSE
9.Onlyfunctionsthatdonotreturnavaluemayberecursive.
ANSWER:
FALSE
10.Everyrecursivedefinitionmayberewritteniteratively.
ANSWER:
TRUE
ShortAnswer
1.Arecursivefunctionisafunctionthat______________.
ANSWER:
callsitself
2.Astackexhibitswhatbehavior?
ANSWER:
LastIn–FirstOut
3.Inarecursivefunction,thestatement(s)thatinvokethefunctionagainarecalledthe______________.
ANSWER:
recursivecalls
4.Iftherecursivefunctioncalldoesnotleadtowardsastoppingcase,youhave______________.
ANSWER:
infiniterecursionorastackoverflow
5.Howdoyouensurethatyourfunctiondoesnothaveinfiniterecursion?
ANSWER:
Allrecursivecallsmustleadtoastoppingcase.
6.Whatistheoutputofthefollowingcodefragment?
intf1(intbase,intlimit)
{
if(base>limit)
return-1;
else
if(base==limit)
return1;
else
returnbase*f1(base+2,limit);
}
intmain()
{
cout< return0; } ANSWER: 2 7.Giventhefollowingcodefragment,whatisthestoppingcondition(s)? intf1(intx,inty) { if(x<0||y<0) returnx-y; else returnf1(x-1,y)+f1(x,y-1); } intmain() { cout< return0; } ANSWER: x<0,y<0 8.Inarecursivepowerfunctionthatcalculatessomebasetoapositiveexppower,atwhatvalueofexpdoyoustop? Thefunctionwillcontinuallymultiplythebasetimesthevaluereturnedbythepowerfunctionwiththebaseargumentonesmaller. ANSWER: exp=1 9.Inarecursivepowerfunctionthatcalculatessomebasetotheexppower,whatistherecursivecall? ANSWER: returnbase*power(base,exp-1); 10.Foreveryrecursivesolution,thereisa(n)______________solution. ANSWER: iterative MultipleChoice 1.Adefinitionthatdefinesaconceptoraformulaintermsoftheconceptorformulaiscalled a.arecursivedefinition b.indecision c.iteration d.reduction ANSWER: A 2.Ifyoutrytosolveaproblemrecursively,youshould a.findallthestoppingcasesandthevaluesifneededatthatcase b.findarecursivecallthatwillleadtowardsoneofthestoppingcases c.alloftheabove d.noneoftheabove ANSWER: C 3.Whatiswrongwiththefollowingrecursivefunction? Itshouldprintoutthearraybackwards. voidprint(intarray[],intstart,intsize) { if(start==size) return; else { print(array,start-1,size); cout< } } a.infiniterecursion b.thestoppingconditioniswrong c.therecursivecalliswrong d.nothing ANSWER: C 4.Whatiswrongwiththefollowingrecursivefunction? Itshouldprintoutthearraybackwards. voidprint(intarray[],intstart,intsize) { if(start==size) return; else { print(array,start+1,size); cout< } } a.infiniterecursion b.thestoppingconditioniswrong c.therecursivecalliswrong d.nothing ANSWER: D 5.Whatiswrongwiththefollowingrecursivefunction? Itshouldprintoutthearraybackwards. voidprint(intarray[],intstart,intsize) { if(start return; else { print(array,start+1,size); cout< } } a.infiniterecursion b.thestoppingconditioniswrong c.therecursivecalliswrong d.nothing ANSWER: B 6.Whatiswrongwiththefollowingrecursivefunction? Itshouldprintoutthearraybackwards. voidprint(intarray[],intstart,intsize) { if(start==size) return; else { print(array,start-1,size); cout< } } a.infiniterecursion b.thestoppingconditioniswrong c.therecursivecalliswrong d.AandC e.nothing ANSWER: D 7.Everytimearecursivefunctioncallisexecuted,anew__________isputonthetopofthestack. a.Activityframe b.Activityrecord c.program d.Activationframe ANSWER: D 8.Astackexhibits_________behavior. a.firstinfirstout b.lastinlastout c.lastoutfirstin d.undefined ANSWER: C 9.Ifyourprogrammakestoomanyrecursivefunctioncalls,yourprogramwillcausea___________ a.stackunderflow b.activationoverflow c.stackoverflow d.syntaxerror ANSWER: C 10.Implementingataskrecursivelyratherthaniterativelygenerally a.isslower b.takesmorestorage(memory) c.issometimeseasiertoprogram d.alloftheabove ANSWER: D 11.Giventhefollowingrecursivefunctiondefinition,whatisthestoppingcase? voidtowers(charsource,chardest,charhelp,intnumDisks) { if(numDisks<1) { return; } else { towers(source,help,dest,numDisks-1); cout<<"Movediskfrom"<
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 用C+解决问题第十版Chapter 14 C+ 解决问题 第十 Chapter