國立臺中教育大學 96 學年度研究所碩士班招生考試
程式設計 科試題
一. 問答題(共 50%)
1. The following procedure Trace1 take one integer as input and returns a integer r. The following procedure Trace2 take one integer as input and returns a integer p. The call Trace1(6) return r =__________.(10%)(需寫出完整解釋,只給運算結果者一律以零分計。) Procedure Trace1(n)
{
if n is equal to 0 then return 1; else m <-Trace1(n-1) ; r <-Trace2(n) + m ; return r ; } Procedure Trace2(f) {
if f is equal to 1 then return 1; Else
p <- f * Trace2(f-1);
return p ;
}
2. 請將下列數字插入 Hashtable with chaining. The hashtable has 9 buckets numbered from 0 to 8, and the hashing function is H(x)=(x +3)% 9.
15, 30, 12, 64, 87, 21, 32, 25, 68, 77, 48, 2, 90 (10%) 3. Please print the output of the following C program. (10%)
#include <stdio.h>
#define min(X, Y) ((X) < (Y) ? (X) : (Y)) main()
{
int A=3, B=11, C=4;
C= min(min(A++, B++), C++);
printf(“\n (A, B, C)=(%d, %d, %d) \n”,A, B, C); }
2
4. 請問以下程式之執行結果為何:left = __ (5%) #include <stdio.h>
int main() {
int left=1, right=1;
left = right = 2 *(1 + right++); printf("left= %d\n", left); } 5. 請問以下程式之執行結果為何:sum= (5%) #include <stdio.h> int main() { int x, y, sum=0; for(x=1; x<10; x++)
for(y=0; y<x; y++) sum ++; printf("sum= %d\n",sum); } 6. 寫出以下程式執行後之輸出結果 :sum= (5%) ; a[0]= (5%) #include <stdio.h> main() { int i,j,sum=0; int temp; int a[5]={5, 1, 4, 2, 3}; for(i=1; i<5; i++) { for(j=1; j<=5-i; j++) { if(a[j]>a[j+1]) { 以下仍有試題
temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } }
for(i=0;i<5;i++) sum+= a[i]; printf("sum=%d ", sum); printf("a[0]=%d\n", a[0]); }
二. 選擇題(每題 5%,共 50%)
題組一:The Kruskal’s algorithm(回答 1~3 題)
Given an undirected connected Graphic G with n nodes and G’s edge set E. Each edge has a weight value. Below is the Kruskal’s algorithm for finding the minimum cost spanning tree, please fill the Block A, Block B and Block C.
1. Please select the correct command for Black A: (A) delete (v,w) from E
(B) delete (v,w) from T (C) copy (v,w) from E to T (D) move (v,w) from E to T
2. Please select the correct command for Black B: (A) can create a cycle in T
(B) can not create a cycle in T (C) is the minimum cost in T (D) can not create a cycle in E
4
3. Please select the correct command for Black C: (A) n-1 edges
(B) n edges (C) n+1 edges (D) 1
4. Given 5 nodes A, B, C, D and E. The weight of these nodes are WA=3, WB=4, WC=8, WD=9, and
WE= 12. Please use Huffman algorithm to construct a binary tree with the minimal weighted
external path. What is the weighted external path length? (A) 69 (B) 79 (C) 59 (D) 89 5. 假定有1、2、3、4四個數字依此ㄧ次序分別經由堆疊(Stack)、佇列(quene)、與雙向佇列(deque) 方式做排列,問各自會有多少種不同排列方式? (A) (14,1,24) (B) (12,2,24) (C) (24,14,1) (D) (10,12,14) 6. 承第5題,下列何者不是經由堆疊(Stack)進行排列所獲得的結果? (A) (1234) (B) (2134) (C) (3214) (D) (4123)
7. Which of the following sorting algorithms are in the worst case complexity
θ
(
n
2)
, where n is the number of input data?(A) selection sort (B) heap sort (C) shell sort (D) quick sort
8. What is the number edges in a binary tree with n nodes ? (A) n-1
(B) n/2 (C) n+1 (D) n
9. 有一個二維陣列 A,假設 A(1,1)的位址是 644 而 A(3,3)的位址是 676 的話,請問 (14,14)的位址為何?請簡述你的答案。
(A) 852 (B) 951 (C) 753 (D) 654
10. Given the postfix representation of an expression abcd+*-ef/+,where a,b,c,d,e, and f are operands. Find the prefix representation of the expression.
(A) (a+b*c-d)+(e/f) (B) +-a*b+cd/ef
(C) -*+abcd+/ef (D) (a-(b*(c+d)))+(e/f)