9填空利用上题(KMP算法题)p=”aabcaabbaa”优化后的Next数组,对t=”aaabaabcabaabcaabbaab”进行匹配。有多少次字符比较?(注意:每一次p中的字符与t中的字符的一次比较计做一次)Usetheoptimized”next”arrayaboveforpatternp=”aabcaabbaa”tomatchthetargetstringt=”aaabaabcabaabcaabbaab”.Howmanycharactercomparisonsareneeded?(Note:Eachcomparisonofthecharactersbetweenpandtcountsonce)
10填空一个有4层结点的完全二叉树。按前序遍历周游给结点从1开始编号,则第21号结点的父结点是多少号?(注释:根的层数为0)Foracompletebinarytreewithfourlevels,labelthenodesstartingfrom1accordingtothepreordertraversal.whatisthelabeloftheparentnodefornode21?(Therootisonlevel0)
11填空假设一棵二叉树中,度为2的结点有20个,度为1的结点有10个,度为0的结点有多少个?Inabinarytree,thereare20nodeswithadegreeof2and10nodeswithadegreeof1.Howmanynodesarewithadegreeof0?
12填空某二叉树中序序列为A,B,C,D,E,F,G,前序序列为E,A,C,B,D,G,F,则后序序列是?(注意:答案不要含空格和逗号,比如可以是ABCDEFG)TheinfixordersequenceofabinarytreeisABCDEFG,anditspreordersequenceisEACBDGF.Pleasewritedownitspostordersequence.(Noblankspaceorcommainyouranswer.ForexampleABCDEFGisavalidformat.)
13填空对于键值序列{38,64,52,26,73,40,48,55,15,12},用筛选法建最小值堆,共交换元素多少次?Forthekeyvaluesequence{38,64,52,26,73,40,48,55,15,12},usethebottom-upheapificationmethodtoconstructaminimumheap.Howmanytimesshouldweexchangetheelementsinthearray
数据结构与算法
北京大学
军职在线答案
大学网课