b04902xxx 板


LINE

※ [本文转录自 NTU-Exam 看板 #1JIcTNNx ] 作者: Akaz (Akaz) 看板: NTU-Exam 标题: [试题] 102下 林轩田 资料结构与演算法 期中考 时间: Sun Apr 13 18:30:45 2014 课程名称︰资料结构与演算法 课程性质︰必带 课程教师︰林轩田 开课学院:电机资讯学院 开课系所︰资讯工程学系 考试日期(年月日)︰2014/04/13 考试时限(分钟):原120分钟,加时30分 是否需发放奖励金:是 (如未明确表示,则不予发放) 试题 : This is a open-book exam. You can use any printed materials as your reference during the exam. Any electronic devices are not allowed. Any form of cheating, lying or plagiarism will not be tolerated. Students can get zero scores and/or get negative scores and/or fail the class and/or be kicked out of school and/or receive other punishments for those kinds of misconducts. Both English and Chinese (if suited) are allowed for answering the questions. We do not accept any other languages. There are 8 problems in the exam, each worth 25 points--the full credit is 200 points. Some problems come with a few sub-problems to help you get partial credits. For the 8 problem, 3 of them are marked with * and are supposedly simple; 3 of thme are marked with ** and are supposedly regular; 2 of them are marked with *** and are supposedly difficult. There is one bonus problem, numbered 1126, with 10 points. The problems are roughly ordered by difficulty. 1. (25%, *) Considering representing a deque by a doubly-linked list, with an empty deque in the beginning. After executing each step of the following operations sequentially, list the contents of the doubly-linked list, with highlights on where the head and tail are. insertFront(1); insertBack(3); insertBack(2); insertFront(5); removeFront(); removeBack(); insertBack(7); removeFront(); removeBack(); insertBack(6); 2. (25%, *) The following is a file system that can be represented by a tree rooted at dsa. Draw a diagram illustrating how the tree can be sorted when the sub-trees are put in a linked-list-based container. You only need to draw links from parent to child as well as links between siblings, but not other links. dsa/instructor dsa/ta/ta1 dsa/ta/ta2 dsa/ta/ta3 dsa/hw/hw1/write dsa/hw/hw1/prog dsa/hw/hw2/write dsa/hw/hw2/prog dsa/hw/hw2/data dsa/midterm/goodluck 3. (25%, *) Write down the outputs of the following C++ code. (a) (15%) Execute max(arr, 0, 6, res) with an array arr = {1,2,3,4,5,6,7} and res = 0. 1 void max(int* arr, int left, int right, int& res){ 2 int mid = (left+right)/2; 3 int res1 = 0; 4 int res2 = 0; 5 if (left == right){ 6 res = arr[mid]; 7 } 8 else{ 9 max(arr, left, mid, res1); 10 max(arr, mid+1, right, res2); 11 std::cout << res1 << ' ' << res2 << ' ' << std::endl; 12 res = (res1 > res2 ? res1 : res2); 13 } 14 } (b) (10%) Execute max(arr, 0, 6, res) with an array arr = {1,2,3,4,5,6,7} and res = 0. 1 void max(int* arr, int left, int right, int res){ 2 int mid = (left+right)/2; 3 int res1 = 0; 4 int res2 = 0; 5 if (left == right){ 6 res = arr[mid]; 7 } 8 else{ 9 max(arr, left, mid, res1); 10 max(arr, mid+1, right, res2); 11 std::cout << res1 << ' ' << res2 << ' ' << std::endl; 12 res = (res1 > res2 ? res1 : res2); 13 } 14 } 4. (25%, **) Consider having two stacks for storing integers, a blue one and a green one with the push and pop operations only. (a) (15%) Illustrate a scheme (with code or figure) that uses the two stacks and at most O(1) of additional memory to simulate THREE stacks, numbered 1, 2, 3. In particular, illustrate how to implement the push(int stack_number, int value) and pop(int stack_number) operations clearly. (b) (10%) Illustrate a scheme (with code or figure) that uses the two stacks and at most O(1) of not-in-stack memory to simulate K stacks, numbered 1, 2, 3, ..., K. Note that the amount of not-in-stack memory that you can use should be independent of K. 5. (25%, **) Consider mathematical k-dimensional vectors stored with a sparse array on the list. That is, a vector v = (3,0,0,0,9,6) is stored as an ordered list of (0,3)→(4,9)→(5,6). Use any pseudo-code to describe an algorithm that computes the squared distance between two vectors v and u. That is, Σi=0 to k-1 (v[i] - u[i])^2. The algorithm should run in time complexity linear to the numver of non-zero terms in v and u. Briefly justify how your algorithm achieves such a time complexity. 6. (25%, **) In problem 6 and 7, the notation f(n) = O(g(n)) applies to functions f(n) and g(n) from N to R+∪{0}, and f(n) = O(g(n)) if and only if there exists n_0 > 0 and c > 0 such that for all n≧n_0, f(n)≦cg(n). (a) (15%) Assume that k belongs to N. Let f(n) = log_2(1+∣a_kn^k+ a_(k-1)n^(k-1)+a_(k-2)n^(k-2)+...+a_0∣), and g_k(n) = log_2(n^k). Prove that f(n) = O(g_k(n)). You can use the fact that 1+∣a_kn^k+a_(k-1)n^(k-1) +a_(k-2)n^(k-2)+...+a_0∣ = O(n^k), as well as the definition of O(.) above. But you cannot use any other theorems or claims beyond high-school math unless you prove them first. (b) (10%) Let f(n) = log_2(1+∣a_kn^k+a_(k-1)n^(k-1)+a_(k-2)n^(k-2)+... +a_0∣), and g(n) = log_2(n). Prove that f(n) = O(g(n). You can use the result from the previous sub-problem (even if you don't prove it) if you want. 7. (25%, ***) Consider a non-decreasing function h(m):R+∪{0}→R+∪{0}, which means h(m')≧h(m) for all m'≧m. Prove or disprove the following statement. "For functions f(n) and g(n) from N to R+∪{0}, if f(n) = O(g(n)), then h(f(n) = O(h(g(n)))." (Hint: this appears to be a more general statement that can be used to prove Problem 6(a). But is it still true?) 8. (25%, ***) Consider a consecutive array of capacity N that holds k non-NULL elements, where 0≦k≦N. That is, all non-NULL elements are in positions 0, 1, 2, ..., k-1, while all other positions contain NULL. Assume that you accidentally lose the value k and all you know is N and the array. Describe an O(log N)-time algorithm that computes k. Briefly discuss why the algorithm is correct and how it achieves such a time complexity. (Hint: think about binary search.) 1126. (Bonus 10%, ???) You learned about selection sort in a very early stage of this class, and you learned about insertion sort in your reading assignment. Now, imagine that you are in the industry and your boss asks you to implement a sorting algorithm on an array by yourself--without using any of the existing implementations such as qsort. Would you choose selection sort or insertion sort? What is the reason that you'd use to convince your boss that you are making a good choice? (Hint: Imagine that your boss, who is not of CS major, asks you this question. The TAs will grade qualitatively on whether your reason is correct and whether you can convince your boss in a reasonable manner.) --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.112.217.55
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/NTU-Exam/M.1397385047.A.5FB.html
1F:推 Hyww13 :推第1126题XD虽然我来不及写… 04/13 20:27
2F:→ rod24574575 :已收资讯系! 04/14 02:16
3F:推 peter506g :有上色有推 04/14 14:39
4F:推 tenyoku8478 :推楼主超有耐心 超多字~ 04/15 15:24
5F:推 vovo5558 :推楼上觉得期中考超EASY der~~~~ 04/16 14:19
6F:→ Akaz :推楼上跟楼上上考前五分钟在打桌球 04/17 20:51



※ 发信站: 批踢踢实业坊(ptt.cc)
※ 转录者: w4a2y4 (140.112.4.192), 03/14/2016 19:32:45
7F:推 jason1218: 推xD 03/14 23:51







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灯, 水草

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

TOP