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/m.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燈, 水草

請輸入看板名稱,例如:WOW站內搜尋

TOP