软件学院数据结构与算法分析期末试题BWord文档格式.docx

上传人:b****1 文档编号:458122 上传时间:2023-04-28 格式:DOCX 页数:8 大小:30.94KB
下载 相关 举报
软件学院数据结构与算法分析期末试题BWord文档格式.docx_第1页
第1页 / 共8页
软件学院数据结构与算法分析期末试题BWord文档格式.docx_第2页
第2页 / 共8页
软件学院数据结构与算法分析期末试题BWord文档格式.docx_第3页
第3页 / 共8页
软件学院数据结构与算法分析期末试题BWord文档格式.docx_第4页
第4页 / 共8页
软件学院数据结构与算法分析期末试题BWord文档格式.docx_第5页
第5页 / 共8页
软件学院数据结构与算法分析期末试题BWord文档格式.docx_第6页
第6页 / 共8页
软件学院数据结构与算法分析期末试题BWord文档格式.docx_第7页
第7页 / 共8页
软件学院数据结构与算法分析期末试题BWord文档格式.docx_第8页
第8页 / 共8页
亲,该文档总共8页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

软件学院数据结构与算法分析期末试题BWord文档格式.docx

《软件学院数据结构与算法分析期末试题BWord文档格式.docx》由会员分享,可在线阅读,更多相关《软件学院数据结构与算法分析期末试题BWord文档格式.docx(8页珍藏版)》请在冰点文库上搜索。

软件学院数据结构与算法分析期末试题BWord文档格式.docx

3

4

5

6

7

卷面成绩

得分

20

10

15

阅卷教师

阅卷时间

1.Single-Choicequestions(eachquestion2scores,total20scores)

(1)Theprimarypurposeofmostcomputerprogramsis

a)toperformamathematicalcalculation.

b)tostoreandretrieveinformation.

c)tosortacollectionofrecords.

d)alloftheabove.

(2)AssumethatPcontainsnelements.ThenumberofsetsinthepowersetofPis

a)nb)n^2

c)2^nd)2^n-1

e)2^n+1

(3)Pickthegrowthratethatcorrespondstothemostefficientalgorithmasngetslarge:

a)5nb)20logn

c)2n^2d)2^n

(4)Asequencehasthefollowingproperties:

a)Mayhaveduplicates,elementhaveaposition.

b)Mayhaveduplicates,elementsdonothaveaposition.

c)Maynothaveduplicates,elementshaveaposition.

d)Maynothaveduplicates,elementsdonothaveaposition.

(5)ThecorrecttraversaltouseonaBSTtovisitthenodesinsortedorderis:

a)Preordertraversal.b)Inordertraversal.

c)Postordertraversal.

(6)Whensortingnrecords,Insertionsorthasbest-casecost:

a)O(logn).b)O(n).

c)O(nlogn).d)O(n^2)

e)O(n!

)f)Noneoftheabove.

(7)Foralistoflengthn,thelinked-listimplementation'

sprev

functionrequiresworst-casetime:

a)O

(1).

b)O(logn).

c)O(n).

d)O(n^2).

(8)Theeasiestwaytorepresentageneraltreeisto:

a)converttoalist.b)converttoabinarytree.

c)converttoagraph.

(9)Depth-firstsearchisbestimplementedusing:

a)Astackorrecursion.b)Aqueue.

c)Atree.

(10)ForsetP,thenotation|P|indicates

a)ThenumberofelementsinP.b)TheinverseofP.

c)ThepowersetofP.d)Noneoftheabove.

2.(10scores)

WriteaseriesofC++statementsthatusestheListADTasfollowstocreatealistcapableofholdingtwentyelementsandwhichactuallystoresthelistwithfollowingconfiguration:

<

6,28|18,8,19>

solution:

listL1(20);

L1.append(6);

L1.append(28);

L1.append(18);

L1.append(8);

L1.append(9);

L1.next();

//Listabstractclass

template<

classElem>

classList{

public:

//Reinitializethelist.Theclientisresponsiblefor

//reclaimingthestorageusedbythelistelements.

virtualvoidclear()=0;

//Insertanelementatthefrontoftherightpartition.

//Returntrueifsuccessful,falseifthelistisfull.

virtualboolinsert(constElem&

)=0;

//Appendanelementattheendoftherightpartition.

virtualboolappend(constElem&

//Removethefirstelementofrightpartition.Return

//trueifsuccessful,falseifrightpartitionisempty.

//Theelementremovedisreturnedintheparameter.

virtualboolremove(Elem&

//Placefenceatliststart,makingleftpartitionempty

virtualvoidsetStart()=0;

//Placefenceatlistend,makingrightpartitionempty

virtualvoidsetEnd()=0;

//Movefenceonestepleft;

nochangeifalreadyatstart

virtualvoidprev()=0;

//Movefenceonestepright;

nochangeifalreadyatend

virtualvoidnext()=0;

//Returnlengthofleftpartition

virtualintleftLength()const=0;

//Returnlengthofrightpartition

virtualintrightLength()const=0;

//Ifposormoreelementsareinthelist,setthesize

//ofleftpartitiontoposandreturntrue.Otherwise,

//donothingandreturnfalse.

virtualboolsetPos(intpos)=0;

//Returninfirstparameterthefirstelementofthe

//rightpartition.Returntrueifsuccessful,false

//iftherightpartitionisempty.

virtualboolgetValue(Elem&

)const=0;

//Printthecontentsofthelist

virtualvoidprint()const=0;

};

3.(10scores)

BuildtheHuffmancodingtreeanddeterminethecodesforthefollowingsetoflettersandweights:

abcde.

135711

Huffmancodingtreeasfollows:

Herearethefinalcodes.

a11111

b1110

c110

d10

e0

 

4.(15scores)

Whataretheminimumandmaximumnumberofelememtsinaheapofheighth?

Theminimumnumberofelementsiscontainedintheheapwithasinglenodeatdepthh-1,foratotalof2h-1nodes.

Themaximumnumberofelementsiscontainedintheheapthathascompletelyfilleduplevelh-1,foratotalof2h-1nodes.

5.(15scores)

TheBubbleSortimplentationhasthefollowinginnerforloop:

for(intj=n–1;

j>

i;

j--)

Considertheeffectofreplacingthiswiththefollowingstaement:

0;

Wouldthenewimplementationworkcorrectly?

Wouldthechangeaffecttheasymptoticcomplexityofthealgorithm?

Howwouldthechangeaffecttherunningtimeofthealgorithm?

Therevisedalgorithmwillworkcorrectly,anditsasymptoticcomplexitywillremainΘ(n2).However,itwilldoabouttwiceasmanycomparisons,sinceitwillcompareadjacentelementswithintheportionofthelistalreadyknowntobesorted.Theseadditionalcomparisonsareunproductive.

6.(15scores)

//Binarytreenodeabstractclass

classBinNode{

//Returnthenode'

selement

virtualElem&

val()=0;

//Setthenode'

virtualvoidsetVal(constElem&

sleftchild

virtualBinNode*left()const=0;

virtualvoidsetLeft(BinNode*)=0;

srightchild

virtualBinNode*right()const=0;

virtualvoidsetRight(BinNode*)=0;

//Returntrueiffthenodeisaleaf

virtualboolisLeaf()=0;

Writearecursivefunctionthatreturnsacountofthenumberofleafnodesinabinarytrue..

intcount(BinNode<

Elem>

*subroot)

{

if(subroot==NULL)return0;

//Emptysubtree

if(subroot->

isLeaf())return1;

//Aleaf

return1+count(subroot->

left())+

count(subroot->

right());

}

7.(15scores)

ListtheorderinwhichtheedgesofthefollowinggrapharevisitedwhenrunningKruskal’sMSTalgorithm.ShowthefinalMST.

(1,6)(6,5)(2,3)(2,4)(4,6).

Alternatively,(1,6)(6,5)(2,3)(2,4)(1,2).

etc

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 初中教育 > 语文

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2