NTU-Exam 板


LINE

这份试题是笔试部分的,上机部分之前已经有PO过了喔~ 课程名称︰资料结构与演算法 课程性质︰资工系大一必修 课程教师︰张智星 开课学院:电机资讯学院 开课系所︰资讯工程学系 考试日期(年月日)︰2016/04/24 考试时限(分钟):80mins,14:00~15:20,不加时 试题 : 1. (5 pts) Steps in selection sort: Please show each step of selection sort on the vector [3 5 1 4 2 7 9 6 8]. 2. (4 pts) Shallow copy: A program is used to record each student's quiz scores. a. Class definition: class student { public: student(int n){count=n; score=new int[count];}; ~student(){delete [] score;}; void print(); // Print score int *score, count; string name; }; b. Main program: int main(){ student a(3); a.name="John"; a.score[0]=70; a.score[1]=80; student b=a; b.name="Mary"; b.score[2]=90; } Answer the following sub- questions: a. What are the contents of variables a and b? b. What are the two potential problems of this program? 3. (3 pts) STL vectors: Given an STL vector x, answer the following sub-questions. a. What does "x.reserve(25)" mean? b. What is the difference between x[i] and x.at(i)? c. What is the difference between x.size() and x.capacity()? 4. (2 pts) Efficiency of 2D matrix computation: Given the following code snippet: #define N (100) #define M (200) int twodim[N][M]; int get( int arr [][M] , int n, int m) { return arr [n][m];} Why do you need to give M when calling the function get()? 5. (4 pts) Efficiency of 2D matrix computation: Given the following code snippet: #define M 10000 #define N 20000 int array[M][N]; int rowSum(){ int total=0; for (int i=0; i<M; i++) for (int j=0; j<N; j++) total+=array[i][j]; return total; } int colSum(){ int total=0; for (int j=0; j<N; j++) for (int i=0; i<M; i++) total+=array[i][j]; return total; } a. Which function runs faster? b. Why? 6. (8 pts) Search minimum element in a sorted rotated array: Design a O(log n) algorithm which finds the minimum element in a sorted rotated array. If an array is rotated once, then a[0] is moved to a[1], a[1] is moved to a[2], etc., and a[end] is moved to a[0]. This is repeated for k times if the array is rotatd by k positions. For instance, given a sorted array of [1 2 4 5 7 9], we can rotate it 4 times to have [4 5 7 9 1 2]. 7. (4 pts) Infix vs. postfix: What are the major two advantages of postfix notation over infix notaton? 8. (5 pts) About BT: Given a binary tree with the root located at depth 0, and the height of the tree is defined as the maximum depth. a. What is the maximum number of nodes at depth d of a binary tree? b. What is the maximum number of nodes in a binary tree of height h? c. If a binary tree has 25 nodes, what is its maximum height? d. If a binary tree has 25 nodes, what is its minimum height? e. If a proper binary tree has 35 nodes, what are the numbers of external nodes? 9. (2 pts) Vector representation for BT: In order to access the tree nodes quickly, the binary tree shown at bottom is stored level-by-level in a one-dimensional array A. What are the indices of nodes L, M are? (A=1, B=2, D=3) A / \ B D \ / \ F C J / \ \ G H N / / L K \ P \ M 10. (5 pts) Preorder traversal using a stack: Please use the tree shown at bottom to explain how to do iterative implementation of preorder traversal using an explicit stack. (Please show the contents of the stack in order to describe your approach clearly.) a / | \ b c d / / \ e f g / | \ h i j 11. (5 pts) Level- order traversal using a queue: Please uee the tree shown at Question 10 to explain how to do iterative implementation of level-order traversal using a queue. (Please show the contents of the queue in order to describe your approach clearly.) 12. (6 pts) Euler Tour Traversal: Please use a simple binary tree to explain the concept of Euler Tour Traversal. 13. (3 pts) BT from inorder and preorder sequences: Draw a binary tree with inorder sequence [a b c d e f g h i] and preorder sequence [f b a e d c h g i]. 14. (3 pts) BT from inorder and postorder sequences: Draw a binary tree with inorder sequence [a b c d e f g h i] and postorder sequence [b a e d g i h f c]. 15. (8 pts) Leaders in a list: Design a O(n) algorithm that uses a stack to find leaders in a singly linked list. A leader is a key in a node of a linked list which is bigger than all the keys on its right. For instance: If the linked list stores the keys 2 6 1 5 4, then the leaders are 6, 5, 4.If the linked list stores the keys 8, 7, 9, 6, 2, 3, 1, then the leaders are 9, 6, 3, 1. 16. (3 pts) Complexity of operations on heaps: Give the time complexity of the following operations on a heap of nodes: (a) min (b) insert (c) removeMin. 17. (5 pts) Insertion and deletion in heaps: Draw the max- heap tree after the following operations are performed beginning with an empty heap: insert 43, insert 31, insert 68, insert 24, delete- max, insert 51, insert 44, insert 53, insert 69, insert 71, deletemax. 18. (10 pts) In-place heap sort: Given a vector of [8 5 1 3 7], how do you perform inplace heap sort? Please plot the 5 heaps (both vector and tree representations) during heap construction, and the other 5 during output. 19. (5 pts) Evaluation of expressions in postfix: Use a stack to show how to evaluate the postfix expression 9 8 7 2 3 * - / - 5 2 - * 3 / step by step. (You should draw thestack status after each step.) 20. (5 pts) Infix to postfix conversion using a stack: Use a stack to show how to convert the expression (a/(b- c*d))/(e- a)*c into a postfix form. (You should draw the stack after each step). 21. (5 pts) Catalan number: Let bn be the number of different permutations obtainable by passing the numbers 1, 2, 3, ..., n through a stack and deleting in all possible ways. Give the recursive formula for bn. (Be sure to specify the initial condition for your formula.) (Total score = 100) --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.112.16.172
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/NTU-Exam/M.1463624376.A.44C.html
1F:推 rod24574575 : 已收资讯系! 05/19 10:21
2F:推 hummingbird7: 时限特别标红XDD 05/22 13:09
3F:推 simonmao : 80mins...... 06/03 02:21







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

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

TOP