- 1、本文档共7页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
07-08数据结构试题和答案
浙江大学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
文档评论(0)