版權聲明:本文爲博主原創文章,轉載請註明出處:www.dongjinbao.com
判斷題
1-1
算法分析的兩個主要方面是時間複雜度和空間複雜度的分析。 (2分)
答案:T
1-2
將NN個數據按照從小到大順序組織存放在一個單向鏈表中。如果採用二分查找,那麼查找的平均時間複雜度是O(logN)O(logN)。 (3分)
答案:F
1-3
通過對堆棧S操作:Push(S,1), Push(S,2), Pop(S), Push(S,3), Pop(S), Pop(S)。輸出的序列爲:123。 (3分)
答案:F
1-4
所謂“循環隊列”是指用單向循環鏈表或者循環數組表示的隊列。 (2分)
答案:F
1-5
在一棵二叉搜索樹上查找63,序列39、101、25、80、70、59、63是一種可能的查找時的結點值比較序列。 (3分)
答案:F
1-6
將1、2、3、4、5、6順序插入初始爲空的AVL樹中,當完成這6個元素的插入後,該AVL樹的先序遍歷結果是:4、2、1、3、5、6。 (3分)
答案:T
1-7
一棵有124個結點的完全二叉樹,其葉結點個數是確定的。 (3分)
答案:T
1-8
用鄰接表法存儲圖,佔用的存儲空間數只與圖中結點個數有關,而與邊數無關。 (3分)
答案:F
1-9
如果無向圖G必須進行兩次廣度優先搜索才能訪問其所有頂點,則G中一定有迴路。 (3分)
答案:F
1-10
某二叉樹的前序和中序遍歷序列正好一樣,則該二叉樹中的任何結點一定都無右孩子。 (3分)
答案:F
選擇題
2-1
下列函數中,哪個函數具有最快的增長速度? (4分)
A、N2logN
B、N(logN)4
C、N3
D、NlogN2
答案:C
2-2
給定N\times NN×N的二維數組A,則在不改變數組的前提下,查找最大元素的時間複雜度是:(4分)
A、O(N2)
B、O(NlogN)
C、O(N)
D、O(N2logN)
答案:A
2-3
給定程序時間複雜度的遞推公式:T(1)=1T(1)=1,T(N)=2T(N/2)+NT(N)=2T(N/2)+N。則程序時間複雜度是:(4分)
A、O(logN)
B、O(N)
C、O(NlogN)
D、O(N2)
答案:C
2-4
設h爲不帶頭結點的單向鏈表。在h的頭上插入一個新結點t的語句是:(4分)
A、h=t; t->next=h->next;
B、t->next=h->next; h=t;
C、h=t; t->next=h;
D、t->next=h; h=t;
答案:D
2-5
若藉助堆棧將中綴表達式a+b*c+(d*e+f)*g轉換爲後綴表達式,當讀入f時,堆棧裏的內容是什麼(按堆棧自底向上順序)? (4分)
A、+(*+
B、+(+
C、++(+
D、abcde
答案:B
2-6
若用大小爲6的數組來實現循環隊列,且當前front和rear的值分別爲0和4。當從隊列中刪除兩個元素,再加入兩個元素後,front和rear的值分別爲多少? (4分)
A、2和0
B、2和2
C、2和4
D、2和6
答案:A
2-7
三叉樹中,度爲1的結點有5個,度爲2的結點3個,度爲3的結點2個,問該樹含有幾個葉結點? (4分)
A、8
B、10
C、12
D、13
答案:A
2-8
已知一棵二叉樹的先序遍歷結果是ABC,則以下哪個序列是不可能的中序遍歷結果: (4分)
A、ABC
B、BAC
C、CBA
D、CAB
答案:D
2-9
在一個用數組表示的完全二叉樹中,如果根結點下標爲1,那麼下標爲17和19這兩個結點的最近公共祖先結點在哪裏(數組下標)? (注:兩個結點的“公共祖先結點”是指同時都是這兩個結點祖先的結點) (4分)
A、8
B、4
C、2
D、1
答案:B
2-10
將6、4、3、5、8、9順序插入初始爲空的最大堆(大根堆)中,那麼插入完成後堆頂的元素爲: (4分)
A、3
B、5
C、6
D、9
答案:D
2-11
設一段文本中包含字符{a, b, c, d, e},其出現頻率相應爲{3, 2, 5, 1, 1}。則經過哈夫曼編碼後,文本所佔字節數爲: (4分)
A、40
B、36
C、25
D、12
答案:C
2-12
在並查集問題中,已知集合元素0~8所以對應的父結點編號值分別是{ 1, -4, 1, 1, -3, 4, 4, 8, -2 }(注:-n−n表示樹根且對應集合大小爲nn),那麼將元素6和8所在的集合合併(要求必須將小集合併到大集合)後,該集合對應的樹根和父結點編號值分別是多少? (4分)
A、1和-6
B、4和-5
C、8和-5
D、8和-6
答案:B
程序填空題
3-1
下列代碼的功能是從一個大頂堆H的某個指定位置p開始執行下濾。
<code class="hljs haskell has-numbering" style="display: block; padding: 0px; background: transparent; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal;"><span class="hljs-title" style="box-sizing: border-box;">void</span> <span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">PercolateDown</span>( int p, <span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">PriorityQueue</span> <span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">H</span> ) { int child; <span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">ElementType</span> <span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">Tmp</span> = <span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">H</span>-><span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">Elements</span>[p]; for ( ; p * <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span> <= <span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">H</span>-><span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">Size</span>; p = child ) { child = p * <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>; <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> ( child!=<span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">H</span>-><span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">Size</span> && <span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">H</span>-><span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">Elements</span>[child] < <span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">H</span>-><span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">Elements</span>[child+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>]) child++; <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> ( <span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">H</span>-><span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">Elements</span>[child] > <span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">Tmp</span> ) <span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">H</span>-><span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">Elements</span>[p]=<span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">H</span>-><span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">Elements</span>[child]; <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">else</span> break; } <span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">H</span>-><span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">Elements</span>[p] = <span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">Tmp</span>; }</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li></ul>
3-2
下列代碼的功能是返回帶頭結點的單鏈表L的逆轉鏈表。
<code class="hljs lasso has-numbering" style="display: block; padding: 0px; background: transparent; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal;"><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">List</span> Reverse( <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">List</span> L ) { Position Old_head, New_head, Temp; New_head <span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">=</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">NULL</span>; Old_head <span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">=</span> L<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-></span>Next; <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">while</span> ( Old_head ) { Temp <span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">=</span> Old_head<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-></span>Next; Old_head<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-></span>Next<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">=</span>New_head; New_head <span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">=</span> Old_head; Old_head <span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">=</span> Temp; } L<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-></span>Next<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">=</span>New_head; <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> L; }</code>