07-08数据结构试题和答案.doc
文本预览下载声明
浙江大学2007–2008学年秋季学期
《数据结构基础》课程期末考试试卷
开课学院: 软件院、计算机、竺可桢学院 ,考试形式:闭卷,允许带_ 无 入场
考试时间:_2007_年_11_月_17日, 所需时间: 120 分钟
考生姓名: ___学号: 专业: ____教师:
题序 一 二 三 四 总 分 得分 评卷人
Answer Sheet
Part I 1. c 2. a 3. d 4. d 5. c 6. b 7. a 8. b 9. b 10. c Part II 1.
( H-Elements[ 1 ]
( Child != H-Size H-Elements[ Child + 1 ] H-Elements[ Child ]
( H-Elements[ i ] = H-Elements[ Child ]
2.
( j = Increment
( Tmp A[ j - Increment ]
3.
( ThisSum + A[j]
( ThisSum = 0
Part III 1.
(a) ABEDHIFCGJ
(b)ABDEHFICGJ
1.
(c)
2. (a)
2. (b)
or
3.
{ 2, –4, 2, 2, -5, 5, 6, 9, 5 }
4. (a)
Build max heap and call DeletMax for k times.
O(N+k logN)
Keep a min heap of k elements. Compare a new element with the root and, DeletMin and Insert the new element if the new one is larger.
O(N logk)
Sort and take the kth largest.
O(N logN)
Take a pivot and partition the set as in Quicksort.
If k=|S2| then the element must be in S2, recursively find it from S2.
If k=|S2|+1, then return the pivot.
If k|S2|, then it’s in S1 and it’s the (|S1|-N+k)-th largest element. Recursively find it from S1.
Average = O(N). Worst=O(N2).
4. (b)
Part IV
void Dijkstra( Table T )
{/* T[ ].Count is initialized to be 0. T[start].Count = T[start].balloon */
vertex v, w;
for ( ; ; ) {
v = smallest unknown distance vertex;
if ( v == NotAVertex )
break;
T[v].Known = True;
for ( each w adjacent to v )
if( !T[w].Known )
if( T[v].Dist + Cvw T[w].Dist ) {
Decrease( T[w].Dist to T[v]+Cvw )
T[w].Path = v;
T[w].Count = T[v].Count + T[w].balloon;
}
else if( ( T[v].Dist + Cvw == T[w].Dist )
( T[v].Count + T[w].balloon T[w].Count ) ) {
T[w].Count = T[v].Count + T[w].balloon;
T[w].Path = v; /* DO NOT forget this */
}
}
}
NOTE: Please write your answers on the answer sh
显示全部