NTU-Exam 板


LINE

課程名稱︰演算法 課程性質︰資管系系必修 課程教師︰蔡益坤 開課學院:管理學院 開課系所︰資訊管理學系 考試日期(年月日)︰2011/04/18 考試時限(分鐘):14:20 - 18:00 是否需發放獎勵金:是 (如未明確表示,則不予發放) 試題 :         Midterm Note This is a closed-book exam. Each problem accounts for 10 points, unless otherwise marked. Problems 1.Consider the following theorem regarding Gray codes, for which we have sketched a proof by induction in class. There exist a Gray code of length ┌log2 k┐(取上界) for any number k ≧ 2 of objects. The Gray codes for the even values of k are closed , and the Gray codes for the odd values of k are open. Please complete the proof(giving sufficient details); in particular, try to be precise about the length of a code in the proof. You should assume and use the following facts in your proof: (a) Given a closed Gray code for an even number k (≧2) of objects, we can construct a closed Gray code with one additional bit for 2k objects. (b) Given a closed Gray code of length i for 2^i (i≧1) odjects, we can construct an open Gray code of the same length for any odd k, 2^(i-1) < k < 2^i, of objects. (c) Given an open Gray code for an odd number k ( ≧2 ) of objects, we can construct a closed Gray code with one additional bit for 2k objects. 2.Consider the following two-player game: given a positive integer N, player A and player B take turns counting to N. In his turn, a player may advance the count by 1 or 2. For example, player A may start by saying "1 ,2", player B follows by saying "3", player A follows by saying "4", etc. The player who eventually has to say the number N loses the game. A game is determined if one of the two players always has a way to win the game. Prove that the counting game as described is determined for any positive integer N; the winner may differ for different given integers. You must use induction in your proof. (Hint: think about the remainder of the number N divided by 3.) 3.We sometimes would use a diagram like the following to distribute n gifts (or assign n tasks) to n peoples. The main part of the diagram covered, each person(without seeing the horizontal line segments) is asked to choose one of the vertical lines. After everyone has made a choice, the whole diagram is revealed. Following the line chosen by pi, go down along the line and, whenever hitting an intersection, must make a turn( to the left or right). The traced path will eventually reach a gift at the end and the gifts is given to pi. p3 p2 p1 p5 p4 │ │ │ │ │ ├─┤ ├─┤ │ │ ├─┤ ├─┤ │ │ ├─┤ │ g1 g2 g3 g4 g5 Prove by induction that such a diagram( with arbitary numbers of vertical and horizontal line segments)always produces a one-to-one mapping between the people and the gifts( whose number equals that of the vertical lines). 4.For each of the following pairs of functions, determine whether f(n) = O(g(n)) and/or f(n) = Ω(g(n)). Justify your answers. f(n) g(n) (a)(logn)^(logn) n/logn (b)(2^n)*(n^3) 3^n 5.Solve the following recurrence relation using generating functions. This is a very simple recurrence relation, but you must use generating functions in your solution. ┌T(1) = 1 ├T(2) = 2 └T(n) = 2T(n-1) - T(n-2), n ≧ 3 6.If f(x) is monotonically decreasing, then n n Σf(i) ≦f(1) +∫f(x)dx. i=1 1 Show that this is indeed the case. (5 points) 7.Consider the Knapsack Problem: Given a set S of n items, where the i-th item has an integer size S[i], and an integer K, find a subset of the items whose sizes sum to exactly K or determine that no such subset exist. We have discussed in class two approaches to implementing a solution that we designed by induction: one uses dynamic programming (see the Appendix), while the other uses recursive function calls. Suppose there are 5 items, with size 2,3,4,5,6, and we are looking for a subset whose sizes sum to 13. Assuming recursive function calls are used, please give the two-dimension table P whose entries are filled with -,O,I, or left blank when the algorithm terminates. Which entries of P[n,K] are visited/computed more than once? 8.Consider a variant of the Knapsack Problem where we want the subset to be as large as posible(i.e., to be with as many items as possible). How will you afapt the algorithm (see the Appendix) that we have studied in class? Your algorithm should collect at the end the items in one of the best solutions if they exist. Please present your algorithm in an adequate pseudo code and make assumptions wherever necessary(you may reuse the code for the original Knapsack Problem). Give an analysis of its time complexity. The more efficient your algorithm is, the more points you will get for this problem. n 9.Let x1, x2,...,xn be a set of integers, and let S = Σxi. Design an i=1 algorithm to partition the set into two subsets of equal sum, or determine that it is impossible to do so. When the partitioning is possible, your algorithm should also give the two subsets of integers. The algorithm should run in time O(nS). 10.In the towers of Hanoi puzzle, there are three pegs A, B, and C, with n (generalizing the original eight) disks of different sizes satcked in decreasing order on peg A. The objective is to transfer all the disks on peg A to peg B, moving one disk at a time(from one peg to one of the other two) and never having a larger disk stacked upon a smaller one. (a) Give an algorithm to solve the puzzle. Compute the total number of moves in the algorithm. (10 points) (b) If there is an additional fourth peg D, it is possible to reduce the number of moves. Please give a new algorithm that requires fewer moves (5 points) Appendix Below is an algorithm for determining whether a solution to the Knapsack Problem exists . Algorithm Knapsack (S,K); begin P[0,0].exist := true; for k := 1 to K do P[0,k].exist := false; for i := 1 to n do for k := 0 to K do P[i,k].exist := false; if P[i-1,k].exist then P[i,k].exist := true; P[i,k].belong := false; else if k - S[i] ≧ 0 then if P[i-1,k-S[i]].exist then P[i,k].exist := true; P[i,k].belong := true; end --



※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.4.170







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