NTU-Exam 板


LINE

课程名称︰资料结构与演算法 课程性质︰资讯系必修 课程教师︰蔡欣穆 开课学院:电资学院 开课系所︰资讯系 考试日期(年月日)︰2012/4/17 考试时限(分钟):180分钟 是否需发放奖励金:是 试题 : Problem 1. In each of the following question, please specify if the statement is true or false. If the statement is true, explain why it is true. If it is false, explain what the correct answer is and why. (12 points. 1 point for true/false and 2 points for the explanation for each question) 1.0001 1. n = O(nlogn) 10 10 10 n 2. n = Ω(2 ) 3. Given an expression tree to represent an arthimetic expression, if we want to evaluate the expression we need to perform a preorder traversal of the tree. Here "to evaluate" means to calculate the result of the expression. 4. A queue follows a Frist-In-Last-Out (FILO) rule. Problem 2. "Short answer" questions (34 points) 1.(a) Why do we need to use a version control system to manage our source codes? (b) When would be a good time for the programmer to commit the current working copy to the repository? (4 points) 2. Using O-notation, please write down the time complexity of the binary search algorithm (a) in the best case and (b) in the worst case in terms of n, the number of elements in the list to be searched. (4 points) 3. Please give the running time of the following program using O-notation in terms if n. (4 points) sum=0; for(i=0;i<n;++i) for(j=1;j<i*i;++j) for(k=0;k<j;++k) ++sum; 4. Suppose we use an array to represent a degree-5 tree. Given the array index i of a certain tree node, please write down the functions to calculate (a) the array index of its parent node and (b) the array index of its second-to-the-left node. (4 points) 5. What is (a) the minimum and (b) the maximum number of nodes in a complete binary tree with a height of H (there are H levels in the tree)? (4 points) 6. Please complete Table 1 to show the progress of converting the infix expression "(3-9+(7+1*4))/6" to its postfix expression using a stack. (6 points) 7. Draw the expression tree of "(3-9+(7+1*4))/6". (4 points) 8. Convert "(3-9+(7+1*4))/6" to a prefix expression. (4 points) Problem 3. Give the definition of Θ-notation. Then prove that log(n!) = Θ(nlogn). (8 points, 2 points for the definition anf 6 points for the proof.) Problem 4. Please answer the following problems about linked lists. You can assume that the linked lists use the following structure. (14 points) struct ListNode{ int data; struct ListNode *next; }; 1. Please give a C function to insert a node in a descending sorted singly linked list, in which the head of the list has the largest data, and the node next to the head node, if exists, has the second large data, etc. The function should use the following declaration (prototype). struct ListNode* InsertSorted(struct ListNode* head, struct ListNode* newNode); In the declaration, head points to the head node of the list and newNode points to the node to be inserted. Your function should return a pointer to the head node of the list after you finish the insertion operation. (6 points) 2. Suppose there are two singly linked lists both of which intersect at some point and become a single linked list. The head or start pointers of both lists are known, but the intersecting node is not known, Also the number of nodes in each of the list before they intersect are unknown and both lists may have it different. List1 and List2 have n and m nodes, respectively. You are given two stacks to hold pointers to the nodes on the lists, Please give an algorithm (either pseudo code or C code) to find the merging node. Your algorithm should have a running time of O(n+m). (8 points) Problem 5. A d-ary heap is a generalized version of heap, compared to a banary heap. Each non-leaf node would have d children instead of 2 (of course, just like binary heap, there could be one node which has less than d children). The d-ary maximum heap still follows the max tree property, i.e., the parent node would always be larger than its child nodes. Like a maximum binary heap, a d-ary maximum heap supports two operations: DeleteMax and Insert. Assume that the number of elements in the heap is n. (24 points) 1. Assume that {10,12,7,18,3,11,20,19} are inserted into an initially empty 3-ary max heap in the given order. Show how the 3-ary max heap would look like after each insertion. (6 points) 2. After all numbers in the given list are inserted, we perform two DeleteMax operations. Show how the 3-ary max heap would look like after each deletion. (4 points) 3. Show how you would represent a d-ary heap with an array. Show how each element in the heap is associated with an array entry - how to map each element to an array index. (2 points) 4. With your representation in P5.3, give an efficient implementation of DeleteMax for a d-ary max heap (pseudo code or C code). The DeleteMax operation should delete and return the maximum value in the heap, and then adjust the heap accordingly so that the remaining items in the heap still maintain the max tree property. Analyze its running time in terms of d and n. (6 points) 5. With your representation in P5.3, give an efficient implentation of Insert for a d-ary max heap (psuedo code or C code). The Insert operation should the given number into the heap. Analyze its running time interms of d and n. (6 points) ┌─┐ │25│ └─┘ / \ / \ ┌─┐ ┌─┐ │7 │ │30│ └─┘ └─┘ \ / \ / ┌─┐ ┌─┐ │23│ │29│ └─┘ └─┘ / / / / ┌─┐ ┌─┐ │8 │ │27│ └─┘ └─┘ \ \ ┌─┐ │12│ └─┘ / \ / \ ┌─┐┌─┐ │10││14│ └─┘└─┘ Figure 1: A Binary Search Tree Problem 6. Please answer the following questions about the binary search tree and the threaded binary search tree: (22 points) 1. Please draw how the binary search tree in Figure 1 would look like after deleting the number 7. (4 points) 2. Since a binary search tree is also a type of binary tree, we can also modify it to become an inorder threaded binary tree. Assume that the following code is used fore representing a threaded binary tree. struct TreeNode* root; //the pointer to the root node struct TreeNode { int data; int LTag, RTag; // show twhether the left/right pointer is a thread, // 0== thread, 1==redular tree edge struct TreeNode *left, *right; //pointers to the left/right child/thread } Please convert the binary tree in Figure 1 (before the node with the number 7 is deleted) to become an inorder threaded binary tree and draw how it would look like. Note that you have to show the value of each field in the structure in each tree node. Remember to draw the dummy node as well. (6 points) 3. Please complete the following C function to return the inorder predecessor of a given node in a threaded binary tree. struct TreeNode* inorderPredecessor(struct TreenNode* given){ //put your C code here } (6 points) 4. Using the inorderPredecessor function inthe previous question, please complete the following function to print out all numbers which are in the threaded binary search tree and are larger than a and smaller than b in descending order. void printAllBetween(int a, int b, struct TreeNode* root){ //put your C code here } (6 points) Problem 7. (Bonus) Please write down two things you like/dislike about this course so far, and how you would change the theings you do not like if you were the professor. :) (4 points) --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.35.138.124
1F:推 suhorng :<(_ _)> 04/17 22:41
2F:→ peter506g :楼上神速推 04/17 22:43
3F:推 kevin4314 :<(_ _)> 04/17 22:45
4F:推 s864372002 :<(_ _)> 04/17 23:17
5F:推 oncemore :<(_ _)> 04/17 23:25
6F:推 cchao28 :<(_ _)> 04/18 00:56
7F:推 qdqdlla : <(_ _)> 04/22 15:32







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Gossiping站内搜寻

TOP