07-08数据结构试题和答案

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

07-08数据结构试题和答案
浙江⼤学2007–2008学年秋季学期
《数据结构基础》课程期末考试试卷
开课学院:软件院、计算机、竺可桢学院,考试形式:闭卷,允许带_ ⽆⼊场考试时间:_2007_年_11_⽉_17⽇, 所需时间:120 分钟
考⽣姓名: ___学号:专业: ____教师:
Answer Sheet
NOTE: Please write your answers on the answer sheet.
注意:请将答案填写在答题纸上。

I. Please select the answer for the following problems. (20 points)
(1)The time complexity of the following piece of code is (2 points) for(i=0; i
for(j=i; j>0; j/=2)
printf(“%d\n”, j);
a. O(n)
b. O(n*n)
c. O(nlogn)
d. O(n*i)
(2)Suppose that the time complexities of two programs are given by T1(N)=O(f(N))
and T2(N)=O(f(N)). Which of the following equations is true? (2 points) a. T1(N)+T2(N)=O(f(N)) b. T1(N)-T2(N)=o(f(N))
c. T1(N)/T2(N)=O(1)
d. T1(N)=O(T2(N))
(3)Given an empty stack S and an empty queue Q. A list of characters are pushed
into S in the order of a, b, c, d, e, f and every character that is popped from S will be inserted into Q immediately. If the output of Q is b, d, c, f, e, a, the minimum capacity of S must be . (2 points)
a. 6
b. 5
c. 4
d. 3
(4)Suppose that the size of a hash table is 11, and the hash function is
H(key)=key%11. The following 4 elements have been inserted into the table as Addr(14)=3, Addr(38)=5, Addr(61)=6,
Addr(86)=9. When open addressing with quadratic probing is used to solve collisions, the address of the element with
key=49 will be . (2 points)
a. 4
b. 7
c. 8
d. 10
(5)For a binary tree, given the postorder traversal sequence FDEBGCA and the
inorder traversal sequence FDBEACG, the corresponding preorder traversal sequence is . (2 points)
a. ABDFEGC
b. ABDEFCG
c. ABDFECG
d. ABCDEFG
(6)Insert 10, 12, 1, 14, 6, 5, 8, 15, 3, 9, 7, 4, 11, 13, 2 into an initially
empty binary min heap one at a time, after performing three DeleteMin operations, the last element of the heap is . (2 points)
a. 10
b. 11
c. 8
d. 5
(7)Let T be a tree created by union-by-size with N nodes, then the height of
T can be . (2 points)
a. at most log2(N)+1
b. at least log2(N)+1
c. as large as N
d. anything that is greater than 1
(8)Given a weighted and connected undirected graph G, there is/are minimum
spanning tree(s) of G. (2 points)
a. only one
b. one or more
c. more than one
d. zero or more
(9)To find the shortest path between a pair of given vertices, method
can be used. (2 points)
a. Kruskal
b. Dijkstra
c. Hashing
d. Critical Path
(10)Among the following sorting algorithms, has the average run time
O(NlogN) with O(N) extra spaces. (2 points)
a. Quick sort
b. Heap sort
c. Merge sort
d. Insertion sort
II. Given the function descriptions of the following three (pseudo-code) programs, please fill in the blank lines. (24 points) (1)The function is to delete the maximum element in a max heap. (12 points) ElementType DeleteMax( PriorityQueue H ) {
int i, Child;
ElementType MaxElement, LastElement;
MaxElement = ① ;
LastElement = H->Elements[ H->Size-- ];
for( i = 1; i * 2 <= H->Size; i = Child )
{ Child = i * 2;
if( ② )
Child++;
if( LastElement < H->Elements[ Child ] )
③ ;
else break;
}
H->Elements[ i ] = LastElement;
return MaxElement;
}
(2)The function is to sort a list of N elements A[] in non-decreasing order
by Shellsort with Shell’s increments. (6 points)
void Shellsort( ElementType A[ ], int N )
{
int i, j, Increment;
ElementType Tmp;
for ( Increment = N / 2; Increment > 0; Increment /= 2 )
for ( i = Increment; i < N; i++ ) {
Tmp = A[ i ];
for ( j = i; ① ; j - = Increment )
if(② )
A[ j ] = A[ j - Increment ];
else break;
A[ j ] = Tmp;
}
}
(3)The function is to find maximum sum value of the subsequence in A[0], A[1], A[2], … A[N-1]. (6 points)
int MaxSubsequenceSum(int A[], int N)
{
int ThisSum, MaxSum, j;
ThisSum=MaxSum=0;
for(j=0; j
ThisSum = ① ;
if (ThisSum >MaxSum)
MaxSum= ThisSum;
else if (ThisSum <0)
② ;
}
return MaxSum;
}
III. Please write or draw your answers for the following problems on the answer sheet.
(41 points)
(1)
Please list:
(a)the depth-first search sequence;
(b)
(c)the minimum spanning tree.
Note: All the adjacent vertices are to be visited by alphabetical order.
(15 points)
(2)Insert the numbers 40, 28, 6, 72, 100, 3, 80, 91, 38 into an initially empty
binary search tree. Please show
(a)the resulting binary search tree; (10 points) and
(b)the resulting binary search tree after 72 is deleted. (3 points)
(3)The array representation of the disjoint sets is given by { 2, –4, 2, 2,
-3, 5, 6, 9, -2 }. Please list the resulting array elements after invoking
Union(7, 9) with union-by-size. Keep in mind that the elements are numbered
from 1 to 9. (5 points)
(4)Given a list of N elements and an integer k. Please describe two different
algorithms for finding the kth largest element and give the time complexities.
(8 points)
IV. If each vertex in an undirected weighted graph has a number of balloons assigned.
Explain how to modify Dijkstra's algorithm so that if there is more than one minimum path from v to w, a path with the maximum number of balloons is chosen.
(15 points)
Note : T[ V ].balloon contains the number of balloons at vertex V.
void Dijkstra( Table T )。

相关文档
最新文档