1
-國立台中師範學院九十四學年度研究所碩士班考試
程式設計 科試題
一、Given the following diagraph:
1. Show the Adjacency matrix of this digraph(10%) 2. Show the orders using BFS traversal from node B(10%) 3. Show the orders using DFS traversal from node B(10%)
二、選擇題:
1. For an already sorted array of sizen, which of the following algorithm is asymptotically the slowest?(5%)
n Insertion Sort o Merge Sort p Quick Sort q Counting Sort
2. To find both the maximum and minimum of n numbers, how many comparisons are necessary in the worst case? (5%)
n 3 n
/2
o
3n/2
p 3n/2-2 q
3n/2
−23. Which of the following functions has the fastest rate of growth? (5%) n (log n )! o logn ) 2 ( p logn 4 q 3 n
4. Which of the following sorts are in-place and stable? (5%) n INSERTION SORT o QUICK SORT p HEAP SORT q COUNTING SORT 數教所、測統所 用 G A H I B C D E F
2
-5. What value is returned by the following code when
n
=
10
?(5%) MYSTERY( )
n
1.r
←
0
2. fori
←
1
ton
3. do forj
←
1
toi
4. dor
= r
+
1
5. returnr
n 110 o 109 p 55 q 54 三、 使用任何程式語言寫出計算二元樹的高度。(25%)四、 Given the Fibonacci numbers as 1, 1, 2, 3, 5, 8, 13, 21, 34, …, where the next Fibonacci number will be the sum of its previous two Fibonacci numbers
a. Write a recursive program to generate the N’th Fibonacci number.(5%) b. Write a non-recursive program using the loop-structure to generate the N’th
Fibonacci number.(5%)
五、 Please draw out the AVL trees after inserting 4 and then 3 separately in the following AVL tree. (10%)