2009级数据结构试卷A及答案 - 副本 下载本文

内容发布更新时间 : 2024/5/9 18:32:02星期一 下面是文章的全部内容请认真阅读。

( 密 封 线 内 不 答 题 ) ………………………………………密………………………………………………封………………………………………线…………………………………… 学院 专业 座位号 诚信应考,考试作弊将带来严重后果! 华南理工大学期末考试 《 Data Structure 》A试卷 注意事项:1. 考前请将密封线内填写清楚; 2. 所有答案请直接答在试卷上; 3.考试形式:闭卷; 4. 本试卷共十大题,满分100分,考试时间120分钟。 题 号 一 二 三 四 五 六 七 八 九 十 总分 得 分 评卷人 1. Select the correct choice. (20 scores, each 2 scores) (1) An algorithm must be or do all of the following EXCEPT: ( C ) (A) Correct (B) Finite (C) Ambiguous (D) Concrete steps (2) Pick the growth rate that corresponds to the most inefficient algorithm as n gets large: ( C ) (A) 2n3 (B) 2n (C) n! (D) 20n2logn (3) If a data element requires 8 bytes and a pointer requires 6 bytes, then a linked list representation will be more space efficient than a standard array representation when the fraction of non-null elements is less than about: ( B ) (A) 1/4 (B) 4/7 (C) 4/5 (D) 3/4 (4) Which statement is not correct among the following four: ( B ) (A) The Quick-sort is an unstable sorting algorithm. (B) The number of empty sub-trees in a non-empty binary tree is one more than the number of nodes in the tree. (C) The worst case for my algorithm is n becoming larger and larger because that is the slowest. (D) A cluster is the smallest unit of allocation for a file, so all files occupy a multiple of the cluster size. (5) Which of the following is a true statement: ( C ) (A) A general tree can be transferred to a binary tree with the root having both left child and right child. (B) In a BST, the node can be enumerated sorted by a preorder traversal to the BST. (C) In a BST, the left child of any node is less than the right child, but in a heap, the left child of any node could be less than or greater than the right child. (D) A heap must be full binary tree. (6) The golden rule of a disk-based program design is to: ( B ) (A) Improve the basic operations. (B) Minimize the number of disk accesses. 《 Data Structure 》A试卷 第 1 页 共 6 页 _____________ ________ 姓名 学号 (C) Eliminate the recursive calls. (D) Reduce main memory use.

(7) Given an array as A[m][n]. Supposed that A[0][0]is located at 644(10) and A[2][2]is stored at 676(10), and every element occupies one space. “(10)” means that the number is presented in decimals. Then the element A[4][4](10) is at position: ( D )

(A) 692 (B) 695 (C) 650 (D) 708

(8) If there is 0.5MB working memory, 4KB blocks, yield 128 blocks for working memory. By the multi-way merge in external sorting, the average run size and the sorted size in one pass of multi-way merge on average are separately ( C )? (A) 0.5MB, 128 MB (B) 2MB, 512MB (C) 1MB, 128MB (D) 1MB, 256MB (9) Which algorithm is used to generate runs in classic external sorting? ( D ) (A) Quick-sort (B) Bubble sort

(C ) Insertion sort (D) Replacement selection

(10) Assume that we have eight records, with key values A to H, and that they are initially placed in alphabetical order. Now, consider the result of applying the following access pattern: F D F G G F A D F G, if the list is organized by the move-to-front heuristic, then the final list will be ( B ).

(A) G F D A C H B E (B) G F D A B C E H (C) F D G A E C B H (D) F D G E A B C H 2. Fill the blank with correct C++ codes: (16 scores)

(1) Given an array storing integers ordered by distinct value, modify the binary search routines to

return the position of the integer with the greatest value less than K when K itself does not appear in the array. Return ERROR if the least value in the array is greater than K: (10 scores) // Return position of greatest element <= K int newbinary(int array[], int n, int K) { int l = -1;

int r = n; // l and r beyond array bounds while (l+1 != r) { // Stop when l and r meet

___ int i=(l+r)/2_____; // Look at middle of subarray if (K < array[i]) __ r=i ___; // In left half if (K == array[i]) __ return i ___; // Found it if (K > array[i]) ___ l=i ___ // In right half }

// K is not in array or the greatest value is less than K if K> array[0] (or l !=-1)

return l ; // the integer with the greatest value less than // K when K itself does not appear

in the array

else return ERROR; // the least value in the array is greater than K }

《 Data Structure 》A试卷 第 2 页 共 6 页

(2) A full 5-ary tree with 100 internal vertices has _501__vertices. (3 scores)

(3) The number of different shapes of binary trees with 4 nodes is _14_. (3 scores)

3. A certain binary tree has the preorder enumeration as ABECDFGHIJ and the inorder enumeration as EBCDAFHIGJ. Try to draw the binary tree and give the postorder enumeration. (The process of your solution is required!!!) (6 scores) A A A A B F B F B F EBCD FHIGJ E HIGJ E C G E C G CD

D HI J D H J

I

Postorder enumeration: EDCBIHJGFA

4. Determine Θ for the following code fragments in the average case. Assume that all variables are of type int. (6 scores) (1) sum=0;

for (i=0; i<3; i++) for (j=0; j

sum++; solution : Θ___(n)_______

(2) sum = 0;

for(i=1;i<=n;i++) for(j=1;j<=i;j++)

sum++; solution : Θ__(n2)________

(3) sum=0;

if (EVEN(n))

for (i=0; i

sum=sum+n; solution : Θ___(n)_____

5. Trace by hand the execution of Quicksort algorithm on the array: int a[] = {49 38 65 97 76 13 27 49*}. The pivot is 49 in the first pass, the following pivots are selected by the same method (at the first position of the input array). (6 scores) initial: [49 38 65 97 76 13 27 49*]

pass 1: [27 38 13] 49 [76 65 49* 97]

《 Data Structure 》A试卷 第 3 页 共 6 页