




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
【MOOC】《數據結構與算法》(北京大學)章節期末中國大學慕課答案
有些題目順序不一致,下載后按鍵盤ctrl+F進行搜索第一章概論第一章概論測驗1.單選題:以下哪種結構是邏輯結構,而與存儲和運算無關:Whichofthefollowingstructureisalogicalstructureregardlessofthestorageoralgorithm:(Thereisonlyonecorrectanswer)
選項:
A、隊列(queue)
B、雙鏈表(doublylinkedlist)
C、數組(array)
D、順序表(Sequentiallist)
答案:【隊列(queue)】2.單選題:下列不屬于線性結構的是:Whichoneofthefollowingsdoesnotbelongtolinearstructure:(Thereisonlyonecorrectanswer)
選項:
A、隊列(queue)
B、散列表(hashtable)
C、向量(vector)
D、圖(graph)
答案:【圖(graph)】3.多選題:關于算法特性描述正確的有:Whichoneisrightaboutalgorithm’scharacterization:(therearemorethanonecorrectanswers)
選項:
A、算法保證計算結果的正確性。Algorithmwillensurethecorrectnessofthecalculationresults.
B、組成算法的指令可以有限也可能無限。Instructionswhichcompositealgorithmscanbeinfiniteorfinite
C、算法描述中下一步執行的步驟不確定。Thenextstepintheimplementationofthealgorithmdescribedisuncertain.
D、算法的有窮性指算法必須在有限步驟內結束。Thefinitenatureofalgorithmsmeansalgorithmmustbecompletedwithinalimitedstep.
答案:【算法保證計算結果的正確性。Algorithmwillensurethecorrectnessofthecalculationresults.;算法的有窮性指算法必須在有限步驟內結束。Thefinitenatureofalgorithmsmeansalgorithmmustbecompletedwithinalimitedstep.】4.多選題:已知一個數組a的長度為n,求問下面這段代碼的時間復雜度:Anarrayofa,itslengthisknownasn.Pleaseanswerthetimecomplexityofthefollowingcode.(Therearemorethanoneanswers.)for(i=0,length=1;i<p=""><>for(j=i+1;jif(length<p=""><>length=j-i+1;}
選項:
A、
B、
C、
D、
答案:【;】5.多選題:下列說法正確的是:Whichoptionsmaybecorrect?(therearemorethanonecorrectanswers)
選項:
A、如果函數f(n)是O(g(n)),g(n)是O(h(n)),那么f(n)是O(h(n))【iff(n)isO(g(n)),g(n)isO(h(n)),thenf(n)isO(h(n))】
B、如果函數f(n)是O(g(n)),g(n)是O(h(n)),那么f(n)+g(n)是O(h(n))【iff(n)isO(g(n)),g(n)isO(h(n)),sof(n)+g(n)isO(h(n))】
C、如果a>b>1,是,但不一定是【ifa>b>1,is,maynotbe】
D、函數f(n)是O(g(n)),當常數a足夠大時,一定有函數g(n)是O(af(n))【iff(n)是O(g(n)),Whenconstantaisbigenough,theremustbeg(n)isO(af(n))】
答案:【如果函數f(n)是O(g(n)),g(n)是O(h(n)),那么f(n)是O(h(n))【iff(n)isO(g(n)),g(n)isO(h(n)),thenf(n)isO(h(n))】;如果函數f(n)是O(g(n)),g(n)是O(h(n)),那么f(n)+g(n)是O(h(n))【iff(n)isO(g(n)),g(n)isO(h(n)),sof(n)+g(n)isO(h(n))】】6.計算運行下列程序段后m的值:Calculatethevalueofmafterrunningthefollowingprogramsegmentn=9;m=0;for(i=1;i<=n;i++)for(j=2*i;j<=n;j++)m=m+1;求m的值
答案:【20】7.由大到小寫出以下時間復雜度的序列:答案直接寫標號,如:(1)(2)(3)(4)(5)(提示:系統基于字符匹配來判定答案,所以您的答案中不要出現空格)Writethefollowingtimecomplexityindescendingsequence:Writedowntheanswerlabelssuchas(1)(2)(3)(4)(5).(Hint:Thisproblemisjudgedbystringmatching,Pleasemakesureyouranswerdon'tcontainanyblanks.)
答案:【(5)(1)(2)(4)(3)】第二章線性表第二章線性表測驗1.多選題:完成在雙循環鏈表結點p之后插入s的操作為:Theoperationtoinsertsafterthedoublycircularlinkedlist’snodepis:(Therearemorethanoneanswers.)
選項:
A、p->next->prev=s;s->prev=p;s->next=p->next;p->next=s;
B、p->next->prev=s;p->next=s;s->prev=p;s->next=p->next;
C、s->prev=p;s->next=p->next;p->next=s;p->next->prev=s;
D、s->next=p->next;p->next->prev=s;s->prev=p;p->next=s;
答案:【p->next->prev=s;s->prev=p;s->next=p->next;p->next=s;;s->next=p->next;p->next->prev=s;s->prev=p;p->next=s;】2.多選題:下面的敘述中正確的是:Selecttheanswerthatmatches(Therearemorethanonecorrectanswers)
選項:
A、線性表在鏈式存儲時,查找第i個元素的時間與i的數值無關。Whenthelinearliststoredinlinkedform,thetimetofindthei-thelementisregardlessofthevalueofi.
B、線性表在順序存儲時,查找第i個元素的時間與i的數值成正比。Whenthelinearliststoredsequentially,thetimetofindthei-thelementisproportionaltovaluewithi.
C、線性表在順序存儲時,查找第i個元素的時間與i的數值無關。Whenthelinearliststoredsequentially,thetimetofindthei-thelementisregardlessofthevalueofi.
D、線性表在鏈式存儲時,插入第i個元素的時間與i的數值成正比。Whenlinearlistsstoredinthelinkedform,thetimetoinsertthei-thelementisproportionaltovaluewithi.
答案:【線性表在順序存儲時,查找第i個元素的時間與i的數值無關。Whenthelinearliststoredsequentially,thetimetofindthei-thelementisregardlessofthevalueofi.;線性表在鏈式存儲時,插入第i個元素的時間與i的數值成正比。Whenlinearlistsstoredinthelinkedform,thetimetoinsertthei-thelementisproportionaltovaluewithi.】3.多選題:下面關于線性表的敘述中,正確的是哪些?Whichofthefollowingsaboutlinearlistarecorrect?(Therearemorethanoneanswers.)Selecttheanswerthatmatches
選項:
A、線性表采用順序存儲,必須占用一片連續的存儲單元。Linearlistsusesequentialstoragewhichmustoccupyacontinuousmemoryunits.
B、線性表采用順序存儲,便于進行插入和刪除操作。Linearlistsusingsequentialstorage,itiseasytodoinsertanddeleteoperations.
C、線性表采用鏈接存儲,不必占用一片連續的存儲單元。Linearlistsusingthelinkedstorage,donotoccupyacontinuousmemoryunits.
D、線性表采用鏈接存儲,便于插入和刪除操作。Linearlistsusingthelinkedstorage,itiseasyforinsertanddeletingoperations.
答案:【線性表采用順序存儲,必須占用一片連續的存儲單元。Linearlistsusesequentialstoragewhichmustoccupyacontinuousmemoryunits.;線性表采用鏈接存儲,不必占用一片連續的存儲單元。Linearlistsusingthelinkedstorage,donotoccupyacontinuousmemoryunits.;線性表采用鏈接存儲,便于插入和刪除操作。Linearlistsusingthelinkedstorage,itiseasyforinsertanddeletingoperations.】4.設某循環鏈表長度為n,并設其中一節點為p1,然后按照鏈表的順序將后面的節點依次命名為p2,p3,...,pn,那么請問pn.next=____(答案為一個節點名,注意所有字母為小寫且答案中不包含空格)
答案:【p1】5.對于一個具有n個結點的單鏈表,在已知的結點*p后插入一個新結點的時間復雜度為O(___),在給定值為x的結點后插入一個新結點的時間復雜度為O(___)。(請依次填入,格式為(a)(b),如果您的答案中出現字母,請使用小寫;后一空系統基于字符匹配來判定答案,所以您的答案中不要出現空格)Forasinglelinkedlistwithnnodes,andafteraknownnode*ptoinsertanewnode,thetimecomplexityisO(___);afteragivennodewithxvalueinsertanewnode,thetimecomplexityisO(___).(Ifyouranswercontainsletters,uselowercaseone.Thesecondblankisjudgedbystringmatching,Pleasemakesureyouranswerdon'tcontainanyblanks.)
答案:【(1)(n)】第三章棧與隊列第三章棧與隊列測驗1.單選題:現有中綴表達式E=((100-4)/3+3*(36-7))*2。以下哪個是與E等價的后綴表達式?ExistinginfixexpressionE=((100-4)/3+3*(36-7))*2.WhichofthefollowingistheequivalentpostfixexpressionofE?(Thereisonlyonecorrectanswer)
選項:
A、((1004–)3/3(367–)*+)2*
B、*+/–10043*3–3672
C、1004–3/3367–*+2*
D、*(+/(–1004)3*3(–367))2
答案:【1004–3/3367–*+2*】2.單選題:設棧S和隊列Q的初始狀態為空,元素e1,e2,e3,e4,e5和e6依次通過棧S,一個元素出棧后即進隊列Q,若6個元素出隊的序列是e2,e4,e3,e6,e5,e1則棧S的容量至少應該是_____________。AssumethatthestackSandqueueQ’sinitialstateisempty,theelementse1,e2,e3,e4,e5ande6followedthroughstackS,anelementoutthestackmeansintothequeueQ.Ifthesequencethesixelementsoutofthequeueise2,e4,e3,e6,e5,e1thenstackSofcapacityshouldbeatleast_____________.(Thereisonlyonecorrectanswer)
選項:
A、2
B、3
C、4
D、6
答案:【3】3.多選題:以下循環隊列的實現方式中,長度為n的隊列,所能容納的元素個數也為n的有:Inthefollowingrealizingwaysofcircularqueue,thequeuewhoselengthisncanalsocontainthenumberofnelementsis:(Therearemorethanoneanswers.)
選項:
A、只用front和rear兩個指針標記隊列的頭和尾,兩個指針均為實指Onlyusefrontandrearasthequeue’sheadandtailpointersandthetwopointersareactuallyreferringto.
B、用front和rear兩個指針標記隊列的頭和尾,并用整型變量len記錄隊列元素數Withthequeue’sheadandtailpointersmarkedasfrontandrear,usetheintegervariablelentorecordthenumberofelements.
C、用front和rear兩個指針標記隊列的頭和尾,并用布爾型變量empty記錄隊列是否為空Withthequeue’sheadandtailpointersmarkedasfrontandrear,useBooleanvariableemptyrecordwhetherthequeueisempty.
D、只用front和rear兩個指針標記隊列的頭和尾,兩個指針均為虛指Onlyusefrontandrearasthequeue’sheadandtailpointersandthetwopointersarevirtuallyreferringto.
答案:【用front和rear兩個指針標記隊列的頭和尾,并用整型變量len記錄隊列元素數Withthequeue’sheadandtailpointersmarkedasfrontandrear,usetheintegervariablelentorecordthenumberofelements.;用front和rear兩個指針標記隊列的頭和尾,并用布爾型變量empty記錄隊列是否為空Withthequeue’sheadandtailpointersmarkedasfrontandrear,useBooleanvariableemptyrecordwhetherthequeueisempty.】4.多選題:隊列的特點包括:Queue’featuresinclude:(Therearemorethanoneanswers.)
選項:
A、后進先出Last-infirst-out(LIFO)
B、先進后出First-inlast-out(FILO)
C、先進先出First-infirst-out(FIFO)
D、后進后出Last-inlast-out(LILO)
答案:【先進先出First-infirst-out(FIFO);后進后出Last-inlast-out(LILO)】5.雙端隊列可以在隊列的兩端進行插入和刪除操作,既可在隊尾進行插入/刪除,又可在隊頭進行插入/刪除。現有4個不同的元素順序輸入到雙端隊列,那么可以得到_____種不同的排列。double-endedqueuecaninsertanddeleteoperationsonbothendsofthequeue.Thatitcaninsert/deleteatitstail,butalsoatthehead.Existing4differentelementssequentiallyinputtothedouble-endedqueue,youcanget_____differentpermutations.
答案:【8】6.編號為1,2,3,4的四輛列車,順序開進一個棧式結構的站臺;則開出車站的順序有______種可能。注釋:例如1,2,3,4或4,3,2,1就是其中兩種可能出站序列;而4,3,1,2是非法序列。Numbered1,2,3,4fourtrains,orderlyenteredastackstructurestation.Howmanypossibleleavingsequencesofthatfourtrains?______.Note:Forinstance,theleavingsequencecouldbe1,2,3,4or4,3,2,1thesetwopossibilities,but4,3,1,2isnotapossiblesequence.
答案:【14】第四章字符串第四章字符串測驗1.單選題:Seekthestring"BAAABBBAA"‘sfeaturevector,wherethefeaturevectorisdefinedasfollows:(Thereisonlyonecorrectanswer)
選項:
A、{-1,0,0,0,0,0,0,1,2}
B、{-1,0,0,0,0,1,1,1,2}
C、{-1,0,0,0,0,0,1,1,2}
D、{-1,0,0,0,1,1,1,1,2}
答案:【{-1,0,0,0,0,1,1,1,2}】2.單選題:下面關于串的的敘述中,哪一個是不正確的:(單選)Whichofthefollowingdescriptionsaboutstringisnotcorrect?(Thereisonlyonecorrectanswer)
選項:
A、串是字符的有限序列Stringisafinitesequenceofcharacters.
B、模式匹配是串的一種重要運算Patternmatchingisanimportantoperation.
C、串是一種數據對象和操作都特殊的線性表Stringisalinearlistwhosedataobjectsandoperationsbothspecial
D、空串是由空格構成的串Emptystringisastringconsistingofspaces.
答案:【空串是由空格構成的串Emptystringisastringconsistingofspaces.】3.單選題:若串S1=‘ABCDEFG’,S2=‘9898’,S3=‘###’,S4=‘012345’,執行concat(replace(S1,substr(S1,length(S2),length(S3)),S3),substr(S4,index(S2,‘8’),length(S2)))注意:substr(S,i,j)是對字符串S的下標為i開始取j個字符,這里的下標是從0開始的(單選)IfthestringS1='ABCDEFG',S2='9898',S3='###',S4='012345',executeconcat(replace(S1,substr(S1,length(S2),length(S3)),S3),substr(S4,index(S2,'8'),length(S2)))Notesubstr(S,i,j)istheoperationtotakestringS’sjcharactersfromsubscripti.Subscripthereisstartingfrom0.(Thereisonlyonecorrectanswer)
選項:
A、ABC###G0123
B、ABCD###2345
C、ABCD###1234
D、ABC###G2345
答案:【ABCD###1234】4.單選題:下列說法正確的是:(單選)Whichofthefollowingstatementsiscorrect?(Thereisonlyonecorrectanswer)
選項:
A、空串就是空白串“Emptystring”isblankstring.
B、空串是任意字符串的子串Emptystringisasubstringofarbitrarystring.
C、串只可以采用順序存儲,不可以采用鏈式存儲Stringonlycanbestoredinsequentialmethodandcannotbestoredinlinkedmethod.
D、在C++標準中,charS[M]最多能表示長度為M的字符串InC++standards,charS[M]canrepresentuptoastringoflengthM.
答案:【空串是任意字符串的子串Emptystringisasubstringofarbitrarystring.】5.單選題:設有兩個串p和q,其中q是p的子串,求q在p中首次出現的位置的算法稱為()(單選)Therearetwostringspq,qisp’ssubstring.Thealgorithmtosearchthefirsttimeqappearedinpiscalled()(Thereisonlyonecorrectanswer)
選項:
A、求子串Seekingsubstring
B、聯接Concatenation
C、匹配Matching
D、求串長Seekinglength
答案:【匹配Matching】6.多選題:在字符{A,C,G,T}組成的DNA序列中,A和T、C和G是互補對。判斷一個DNA序列中是否存在互補回文串(例如,ATCATGAT的補串是TAGTACTA,與原串形成互補回文串)。下面DNA序列中存在互補回文串的是:(多選)IntheDNAsequencesconsistingofcharacter{A,C,G,T},AandT,CandGarecomplementarypairs.JudgingwhetherthereisacomplementarypalindromesequenceinaDNAsequence(e.g.,ATCATGAT’scomplementstringsisTAGTACTA,itiscomplementarypalindromesequencewiththeoriginalsequence).WhichofthefollowingDNAsequenceshavecomplementarypalindromestring?(Therearemorethanoneanswers.)
選項:
A、CTGATCAG
B、AATTAATT
C、TGCAACGT
D、CATGGTAC
E、GTACGTAC
F、AGCTAGCT
答案:【CTGATCAG;AATTAATT;GTACGTAC;AGCTAGCT】7.上一題中的字符串"BAAABBBAA",與目標"BAAABBBCDDDCCHHHHBBBAAABBBAADD"進行匹配,至少需要多少次字符匹配(提示:利用優化后的Next數組):Thestringinquestionabove"BAAABBBAA"matcheswith"BAAABBBCDDDCCHHHHBBBAAABBBAADD".Howmanytimescharactermatchingwillneedatleast?(Hint:Use“Next”arrays):
答案:【31】8.下列程序判斷字符串s是否對稱,對稱則返回1,否則返回0;如f("abba")返回1,f("abab")返回0;Usethefollowingprocedurestodeterminewhetherthestringsissymmetry,symmetryreturns1,otherwisereturn0;suchasf("abab")returns0;intf(chars[]){inti=0,j=0;while(s[j])(1)__++;for(j--;i<j&&s[i]==s[j];i++,j--);return((2)__>=(3)__);}注:(1)和(2)和(3)三個答案之間用空格分隔,每個答案是一個字符,不要加空格
答案:【jij】9.S=“S1S2…Sn”是一個長為n的字符串,存放在一個數組中,編程序將S改造之后輸出。S="S1S2...Sn"isastringoflengthn,andstoredinanarray,outputSafteritsprogrammabletransformation.1.將S的所有第偶數個字符按照其原來的下標從大到小的次序放在S的后半部分;1.Alltheeven-numberedcharactersofSshouldbeplacedinaccordancewiththeirsubscriptdescendingorderinthesecondhalfofS;2.將S的所有第奇數個字符按照其原來的下標從小到大的次序放在S的前半部分;2.Alltheodd-numberedcharactersofSshouldbeplacedinaccordancewiththeirsubscriptascendingorderinthefirsthalfofS.例如:S=‘ABCDEFGHIJKL’,則改造后的S為‘ACEGIKLJHFDB’。則S=’algorithm’,改造后為____________(Hint:1.答案不需要加引號2.系統基于字符匹配來判定答案,所以您的答案中不要出現空格)。Forexample:S='ABCDEFGHIJKL',thenafterthetransformationSis'ACEGIKLJHFDB'.IfS='algorithm',thenafterthetransformationSis____________(Hint:1.pleasedon’tincludeanyquotesinyouranswer.2.Thisproblemisjudgedbystringmatching,Pleasemakesureyouranswerdon'tcontainanyblanks).
答案:【agrtmhiol】10.一個文本串可用事先給定的字母映射表進行加密。例如,設字母映射表為:Atextstringcanbeencryptedbythegivenlettersmappingtable.Forexample,thelettersmappingtableis:比如字符串"encrypt"被加密為"tkzwsdf"。則字符串“algorithm”,被加密為________________(Hint:1.答案不需要加引號2.系統基于字符匹配來判定答案,所以您的答案中不要出現空格)。Asthestring"encrypt"isencryptedas"tkzwsdf",thenthe"algorithm"isencryptedas________(Hint:1.pleasedon’tincludeanyquotesinyouranswer2.Thisproblemisjudgedbystringmatching,Pleasemakesureyouranswerdon'tcontainanyblanks.).
答案:【neopwmfbl】11.設有字符串變量StringA=“”,B=“MULE”,C=“OLD”,D=“MY”;請計算下列表達式(3個答案本身不要出現空格,答案之間用空格分開)AssumethatthereisastringvariableStringA="",B="MULE",C="OLD",D="MY";Pleasecalculatethefollowingexpression:(1)D+C+B(2)B.substr(3,2)(3)A.strlength()
答案:【MYOLDMULEE0】12.若字符串s=”algorithm”,則其子串個數為:Ifthestrings="algorithm",thenthenumberofitssub-stringis:
答案:【46】13.若字符串s=“software”,則其子串個數為:Ifthestrings="software",thenthenumberofitssub-stringis:
答案:【37】第五章二叉樹(上)第五章二叉樹(上)測驗1.多選題:下列關于二叉樹遍歷的說法正確的有:Whichsentencesofthefollowingsarerightabouttraversalofabinarytree:
選項:
A、前序和中序遍歷的順序恰好一樣的二叉樹,只能是空二叉樹或者獨根二叉樹這兩種情況。Onlythesequencesofpreorderandinfixorderofthebinarytreewithnonodesoronlyonenodearethesame.
B、所有結點左子樹為空的二叉樹的前序和中序遍歷順序恰好一樣。Thesequencesofpreorderandinfixorderofabinarytreewithallnodeswithoutleftchildtreearethesame.
C、所有結點右子樹為空的二叉樹的前序和中序遍歷順序恰好一樣。Thesequencesofpreorderandinfixorderofabinarytreewithallnodeswithoutrightchildtreearethesame.
D、只有空二叉樹和一個根結點的二叉樹這兩種二叉樹的前序和后序遍歷的順序恰好一樣。Onlythesequencesofpreorderandpostorderofthebinarytreewithnonodesoronlyonenodearethesame.
E、所有結點左子樹為空的二叉樹的前序和后序遍歷順序恰好一樣。Thesequencesofpreorderandpostorderofabinarytreewithallnodeswithoutleftchildtreearethesame.
F、所有結點右子樹為空的二叉樹的前序和后序遍歷順序恰好一樣。Thesequencesofpreorderandpostorderofabinarytreewithallnodeswithoutleftchildtreearethesame.
G、只有空二叉樹和一個根結點的二叉樹這兩種二叉樹的中序和后序遍歷的順序恰好一樣。Onlythesequencesofinfixorderandpostorderofthebinarytreewithnonodesoronlyonenodearethesame.
H、所有結點左子樹為空的二叉樹的中序和后序遍歷順序恰好一樣。Thesequencesofinfixorderandpostorderofabinarytreewithallnodeswithoutleftchildtreearethesame.
I、所有結點右子樹為空的二叉樹的中序和后序遍歷順序恰好一樣。Thesequencesofinfixorderandpostorderofabinarytreewithallnodeswithoutrightchildtreearethesame.
J、存在一棵非空二叉樹,它的前序、中序和后序遍歷都是一樣的。Thereexistsabinarytreewithatleastonenode,whosepreorder,infixorderandpostorderareallthesame.
答案:【所有結點左子樹為空的二叉樹的前序和中序遍歷順序恰好一樣。Thesequencesofpreorderandinfixorderofabinarytreewithallnodeswithoutleftchildtreearethesame.;只有空二叉樹和一個根結點的二叉樹這兩種二叉樹的前序和后序遍歷的順序恰好一樣。Onlythesequencesofpreorderandpostorderofthebinarytreewithnonodesoronlyonenodearethesame.;所有結點右子樹為空的二叉樹的中序和后序遍歷順序恰好一樣。Thesequencesofinfixorderandpostorderofabinarytreewithallnodeswithoutrightchildtreearethesame.;存在一棵非空二叉樹,它的前序、中序和后序遍歷都是一樣的。Thereexistsabinarytreewithatleastonenode,whosepreorder,infixorderandpostorderareallthesame.】2.多選題:下列關于二叉樹性質的說法正確的有:(多選)Whichsentencesofthefollowingsarerightaboutabinarytree'scharacterization:(Therearemorethanonecorrectanswers)
選項:
A、非空滿二叉樹的結點個數一定為奇數個。Theamountofnodesofafullbinarytreewithatleastonenodemustbeodd.
B、非完全二叉樹也可以用像完全二叉樹那樣使用順序存儲結構進行存儲。Sequentialstoringstructurecanalsobeusedtostoreanincompletebinarytreejustliketostoreacompletebinarytree.
C、當一棵完全二叉樹是滿二叉樹時,葉子結點不一定集中在最下面一層。Ifacompletebinarytreeisafullbinarytree,itwillbepossiblethatleafnodesisnotonthenethermostlayer.
D、完全二叉樹最多只有最下面的一層結點度數可以小于2。Foracompletebinarytree,onlythedegreesofnodesonthenethermostlayercouldbelessthan2.
E、一棵非空二叉樹的為空的外部結點數目等于其結點數加1。Theamountofexternalnullnodesinabinarytreewithatleastonenodeequalstoitsamountofnodesplus1.
F、滿二叉樹的所有結點的度均為2。Alldegreesofnodesinafullbinarytreeare2.
答案:【非空滿二叉樹的結點個數一定為奇數個。Theamountofnodesofafullbinarytreewithatleastonenodemustbeodd.;當一棵完全二叉樹是滿二叉樹時,葉子結點不一定集中在最下面一層。Ifacompletebinarytreeisafullbinarytree,itwillbepossiblethatleafnodesisnotonthenethermostlayer.;一棵非空二叉樹的為空的外部結點數目等于其結點數加1。Theamountofexternalnullnodesinabinarytreewithatleastonenodeequalstoitsamountofnodesplus1.】3.一棵有512個結點的完全二叉樹的高度為多少?(獨根樹高度為1)Whatistheheightofacompletebinarytreewith512nodes?(theheightofatreewithonlyarootis1)
答案:【10】4.一棵有510個結點的完全二叉樹的高度為多少?(獨根樹高度為1)Whatistheheightofacompletebinarytreewith510nodes?(theheightofatreewithonlyarootis1)
答案:【9】5.請寫出下面這棵二叉樹的后序遍歷(字母和字母之間不要有空格)Pleasewritedownthepostordersequenceofthefollowingbinarytree.(Thereisnoblankspacebetweenletters)
答案:【LMXCPKEQHADB】6.請寫出下面這棵二叉樹的中序遍歷(字母和字母之間不要有空格)Pleasewritedowntheinfixordersequenceofthefollowingbinarytree.(Thereisnoblankspacebetweenletters)
答案:【LXMECKPBQHDA】7.請寫出下面這棵二叉樹的前序遍歷(字母和字母之間不要有空格)Pleasewritedownthepreordersequenceofthefollowingbinarytree.(Thereisnoblankspacebetweenletters)
答案:【BEXLMKCPDHQA】8.已知一棵樹的中序遍歷為DBGEACF,后序遍歷為DGEBFCA,求這棵樹的前序遍歷。(字母和字母之間不要有空格)TheinfixordersequenceofatreeisDBGEACF,anditspostordersequenceisDGEBFCA,pleasewritedownitspreordersequence.(Thereisnoblankspacebetweenletters)
答案:【ABDEGCF】9.已知一棵樹的前序遍歷為ABDEGCF,中序遍歷為DBGEACF,求這棵樹的后序遍歷。(字母和字母之間不要有空格)ThepreordersequenceofatreeisABDEGCF,anditsinfixordersequenceisDBGEACF,pleasewritedownitspostordersequence.(Thereisnoblankspacebetweenletters)
答案:【DGEBFCA】10.在一棵非空二叉樹中,若度為0的結點的個數n,度為2的結點個數為m,則有n=________(系統根據字符串匹配來判定答案,所以您的答案中請不要包含空格)Forabinarytreewithatleastonenode,iftherearennodeswithdegree0andmnodeswithdegree2,thenn=________(Thisproblemisjudgedbystringmatching,Pleasemakesureyouranswerdon'tcontainanyblanks.)
答案:【m+1】第五章二叉樹(下)第五章二叉樹(下)測驗1.多選題:下列關于二叉搜索樹的說法正確的有Whichsentencesofthefollowingsarerightaboutbinarysearchtree:
選項:
A、二叉搜索樹按照中序遍歷將各結點打印出將各結點打印出來,將得到按照由小到大的排列。Ifweprintabinarysearchtree'snodesaccordingitsinfixorder,thesequencewillbefromsmalltolarge.
B、如果結點χ的左子樹有右子樹,則存在某個結點的值介于結點χ的值和χ左兒子的值之間,并且這個結點在$$x$$的左子樹之中。Iftheleftchildtreeofanodexhasarightchildtree,thenthereexistssomenodewhosevalueisbetweenthevalueofnodexandthevalueofitsleftchildnode,andthisnodeisontheleftchildtreeofnodex.
C、當根結點沒有左兒子時,根結點一定是值最小的結點。Iftherootnodedoesn'thaveleftchild,itmustbethenodewiththesmallestvalue.
D、二叉搜索樹一定是滿二叉樹。Abinarysearchtreemustbeafullbinarytree.
E、二叉搜索樹一定是完全二叉樹。Abinarysearchtreemustbeacompletebinarytree.
F、從根結點一直沿右兒子向下找不一定能找到樹中值最大的結點。Alongtherightchildofnodesallthetimefromtherootnode,itispossiblethatwecouldn'tfindoutthenodewiththelargestvalue.
答案:【二叉搜索樹按照中序遍歷將各結點打印出將各結點打印出來,將得到按照由小到大的排列。Ifweprintabinarysearchtree'snodesaccordingitsinfixorder,thesequencewillbefromsmalltolarge.;如果結點χ的左子樹有右子樹,則存在某個結點的值介于結點χ的值和χ左兒子的值之間,并且這個結點在$$x$$的左子樹之中。Iftheleftchildtreeofanodexhasarightchildtree,thenthereexistssomenodewhosevalueisbetweenthevalueofnodexandthevalueofitsleftchildnode,andthisnodeisontheleftchildtreeofnodex.;當根結點沒有左兒子時,根結點一定是值最小的結點。Iftherootnodedoesn'thaveleftchild,itmustbethenodewiththesmallestvalue.】2.多選題:下列關于堆的說法正確的有:Whichsentencesofthefollowingsareright:
選項:
A、堆一定是滿二叉樹。Aheapmustbeafullbinarytree.
B、最小堆中,最下面一層最靠右的結點一定是權值最大的結點。Inaminimumheap,therightestnodeonthenethermostlayermustbethenodewiththelargestvalue.
C、堆是實現優先隊列的惟一方法。Aheapistheonlymethodtoimplementapriorityqueue.
D、堆一定是完全二叉樹。Aheapmustbeacompletebinarytree.
E、最小堆中,某個結點左子樹中最大的結點可能比右子樹中最小的結點小。Inaminimumheap,thelargestvalueonsomenode'sleftchildtreecouldbepossiblysmallerthanthesmallestvalueofitsrightchildtree.
F、使用篩選法建堆要比將元素一個一個插入堆來建堆效率高。Screeningmethodhasahigherefficiencythaninsertingelementsonebyonewhileconstructingaheap.
答案:【堆一定是完全二叉樹。Aheapmustbeacompletebinarytree.;最小堆中,某個結點左子樹中最大的結點可能比右子樹中最小的結點小。Inaminimumheap,thelargestvalueonsomenode'sleftchildtreecouldbepossiblysmallerthanthesmallestvalueofitsrightchildtree.;使用篩選法建堆要比將元素一個一個插入堆來建堆效率高。Screeningmethodhasahigherefficiencythaninsertingelementsonebyonewhileconstructingaheap.】3.多選題:一組包含不同權的字母已經對應好Huffman編碼,如果某一個字母對應編碼001,下面說法正確的有AgroupofletterswithdifferentweightshascorrespondedwithHuffmancodes,ifaletter'scorrespondingcodeis001,whichsentencesofthefollowingsareright:
選項:
A、以001開頭的編碼不可能對應其他字母。Acodebeginningwith001couldn'tcorrespondwithotherletters.
B、以000開頭的編碼不可能對應任何字母。Codesbeginningwith000couldn'tcorrespondwithanyletter.
C、以01開頭和1開頭的編碼肯定對應某個字母。Codesbeginningwith01or1mustcorrespongdingwithsomeletters.
D、建好的Huffman樹至少包含4個葉結點。TheHuffmantreecontainsatleast4leafnodes.
E、編碼0和00可能對應于其他字母。Code0and00couldcorrespondingwithotherletters.
答案:【以001開頭的編碼不可能對應其他字母。Acodebeginningwith001couldn'tcorrespondwithotherletters.;以01開頭和1開頭的編碼肯定對應某個字母。Codesbeginningwith01or1mustcorrespongdingwithsomeletters.;建好的Huffman樹至少包含4個葉結點。TheHuffmantreecontainsatleast4leafnodes.】4.多選題:下列關于Huffman樹和Huffman編碼的說法正確的有:WhichsentencesofthefollowingsarerightaboutHuffmantreeandHuffmancode:
選項:
A、Huffman樹一定是滿二叉樹。AHuffmantreemustbeafullbinarytree.
B、Huffman編碼是一種前綴編碼。Huffmancodeisakindofprefixcode.
C、Huffman樹一定是完全二叉樹。AHuffmantreemustbeacompletebinarytree.
D、Huffman編碼中所有編碼都是等長的。AllcodesinaHuffmancodehavethesamelength.
E、對于同樣的一組權值兩兩不同的內容可以得到不同的Huffman編碼方案。DifferentcontentwiththesamegroupofweightscangetdifferentHuffmancodes.
F、使用頻率越高的字母,Huffman編碼越長。Thehigheraletter'sfrequencyis,thelongeritsHuffmancodeis.
答案:【Huffman樹一定是滿二叉樹。AHuffmantreemustbeafullbinarytree.;Huffman編碼是一種前綴編碼。Huffmancodeisakindofprefixcode.;對于同樣的一組權值兩兩不同的內容可以得到不同的Huffman編碼方案。DifferentcontentwiththesamegroupofweightscangetdifferentHuffmancodes.】5.對于如下圖所示的最大堆,刪除掉最大的元素后,堆的后序遍歷結果是Forthefollowingmaximumheap,afterdeletingthemaximumelement,thepostordertraversalsequenceis
答案:【12232428537434835759】6.對于如下圖所示的最大堆,刪除掉最大的元素后,堆的前序遍歷結果是Forthefollowingmaximumheap,afterdeletingthemaximumelement,thepreordertraversalsequenceis請依次寫出插入到樹中的元素,每兩個元素之間用一個空格隔開。Pleasewritedowntheelementssuccessively,andthereisoneblankspacebetweentwoelements.
答案:【59432412233728557483】7.對于關鍵碼序列{38,64,52,15,73,40,48,55,26,12},用篩選法建最小值堆,若一旦發現逆序對就進行交換,共需要交換元素多少次?Forthekeyvaluesequence{38,64,52,15,73,40,48,55,26,12},usethescreeningmethodtoconstuctaminimumheap,ifweexchangethemwhenwefindreversedorder,thenhowmanytimesshouldweexchangethem?
答案:【6】8.從空二叉樹開始,嚴格按照二叉搜索樹的插入算法(不進行旋轉平衡),逐個插入關鍵碼構造出一棵二叉樹,以怎樣的順序插入關鍵碼集合{14,32,47,6,9,12,78,63,29,81}可以使得樹的深度最???請依次寫出插入到樹中的元素,每兩個元素之間用一個空格隔開。如果有多組滿足要求的方案,請使得你的答案中先插入的元素盡可能的小。Fromanullbinarytree,insertkeyvaluessuccessivelyaccordingtotheinsertionalgorithmofabinarysearchtreestrictly(norotationandbalance)toconstructabinarysearchtree.Whatistheinsertionsequencethatcouldmakethetreehaveasmallestdepthwithakeyvalueset{14,32,47,6,9,12,78,63,29,81}?Pleasewritedowntheelementssuccessively,andthereisoneblankspacebetweentwoelements.Iftherearemorethanoneanswerthatmeetthecondition,pleasemaketheelementwhichneedstobeinsertedfirstassmallaspossibleinyouranswer.
答案:【126947291432786381】9.從空二叉樹開始,嚴格按照二叉搜索樹的插入算法(不進行旋轉平衡),逐個插入關鍵碼{18,73,10,5,68,99,27,41,51,32,25}構造出一棵二叉搜索樹,對該二叉搜索樹按照后序遍歷得到的序列為?(答案中每兩個元素之間用一個空格隔開)Fromanullbinarytree,insertkeyvalues{18,73,10,5,68,99,27,41,51,32,25}successivelyaccordingtotheinsertionalgorithmofabinarysearchtreestrictly(norotationandbalance)toconstructabinarysearchtree.Pleasewritedownthesequenceofpostorderofthisbinarysearchtree.(Thereisoneblankspacebetweentwoelements)
答案:【510253251412768997318】10.從空二叉樹開始,嚴格按照二叉搜索樹的插入算法(不進行旋轉平衡),逐個插入關鍵碼{18,73,10,5,68,99,27,41,51,32,25}構造出一棵二叉搜索樹,對該二叉搜索樹按照前序遍歷得到的序列為?(答案中每兩個元素之間用一個空格隔開)Fromanullbinarytree,insertkeyvalues{18,73,10,5,68,99,27,41,51,32,25}successivelyaccordingtotheinsertionalgorithmofabinarysearchtreestrictly(norotationandbalance)toconstructabinarysearchtree.Pleasewritedownthesequenceofpreorderofthisbinarysearchtree.(Thereisoneblankspacebetweentwoelements)
答案:【181057368272541325199】11.如果按關鍵碼值遞增的順序依次將n個關鍵碼值插入到二叉搜索樹中,如果對這樣的二叉搜索樹進行檢索時,每次檢索的字符都等概率的從這n個關鍵碼值中選取,平均比較次數為多少?Ifweinsertnkeyvaluestoabinarysearchtreesuccessivelyfromsmalltolarge,whenwesearchthisbinarysearchtree,eachtimethesearchcharacterisselectedfromthesenkeyvalueswiththesamepossibility,thenhowmanytimeswillthecomparisonbeonaverage?
答案:【(n+1)/2/(1+n)/2】12.請閱讀下面一段代碼PleasereadthefollowingcodeC++:Python:若此段代碼的作用是用來進行后序遍歷,那么應該在幾號訪問點進行訪問?(只需要填寫數字)ifthiscodeisusedtodoanpostordertraversal,whichvisitingpointshouldbevisited?(Youonlyneedtowritedownthenumber)
答案:【3】13.請閱讀下面一段代碼PleasereadthefollowingcodeC++:Python:若此段代碼的作用是用來進行中序遍歷,那么應該在幾號訪問點進行訪問?(只需要填寫數字)ifthiscodeisusedtodoaninfixordertraversal,whichvisitingpointshouldbevisited?(Youonlyneedtowritedownthenumber)
答案:【2】14.請閱讀下面一段代碼PleasereadthefollowingcodeC++:Python:若此段代碼的作用是用來進行前序遍歷,那么應該在幾號訪問點進行訪問?(只需要填寫數字)ifthiscodeisusedtodoapreordertraversal,whichvisitingpointshouldbevisited?(Youonlynee
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- DB31/T 1010-2016商標代理服務規范
- DB31/ 836-2014制冷劑使用技術通則
- 車輛信息安全與數據保護技術考核試卷
- 2024年復烤煙葉項目投資申請報告代可行性研究報告
- 跨境電商貨物代理與清關服務合同
- 退運化妝品退運與化妝品檢測服務協議
- 智能玻璃廠智能質檢系統租賃與數據對接合同
- 新能源汽車節能駕駛培訓與維護服務合同
- 計算機四級信息技術法規題目解析
- 2025年中國薄膜分切行業市場前景預測及投資價值評估分析報告
- 近年《高等教育學》考試真題試題庫(含答案)
- 外科視角解讀-《甲狀腺結節和分化型甲狀腺癌診治指南(第二版)》
- 2023CSCO免疫檢查點抑制劑相關的毒性控制指南(全文)
- 五年級下冊分數加減混合運算練習400題及答案
- 不同行業安全管理的特點與要求
- 醫學人文素質教育的跨學科研究與創新
- 社區居民滿意度調查問卷
- 異常子宮出血護理查房的課件
- 醫院基建科招聘筆試題目
- 無創血糖儀行業營銷策略方案
- 答案-國開電大本科《當代中國政治制度》在線形考(形考任務一)試題
評論
0/150
提交評論