NTU-Exam 板


LINE

課程名稱︰演算法設計與分析 課程性質︰資工系 大二上 必修 課程教師︰蔡欣穆 開課學院:電機資訊學院 開課系所︰資訊工程學系 考試日期(年月日)︰2014/1/8 考試時限(分鐘):180 minutes 是否需發放獎勵金:是 (如未明確表示,則不予發放) 試題 : total score : 123 points 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. (16 points. For each question, 1 point for the true/false answer and 3 points for the explanations.) 1. If P = NP, then NPC ⊆ P. 2. If NPC ⊆ P, then P = NP. 3. When performing an amortized analysis with the potential method, we usually want the potential after any given number of operations to be larger than or equal to the initial potential. 4. Let P1 = {L ⊆ {0,1}*} : there exists an algorithm A that decides L in polynomial time} and P2 = {L ⊆ {0,1}* : there exists an algorithm A that rejects L in polynomial time}. Then P1 = P2. Problem 2. " Short answer " questions : (29 points) 1. Why is it hard to discover bugs created by race conditions ? (3 piints) How to avoid race condition in a multithreaded algorithm ? (3 points) 2. Explain, in evidence-based scheduling, how to use Monte Carlo simulation to estimate the range of possible time duration for a sofeware engineer to complete a task. (4 points) 3. Analyze the work and the span of the following pseudo code program. Assume T(A) = T(B) = T(C) = O(logn), T(D(i)) = O(i). Please gives the work, the span and the parallelism of the given program in terms of n. (9 poionts) spawn A() spawn B() spawn C() parallel for i = 1 to n D(i) sync 4. Give one advantage and one disadvantage of using a paper prototype in software development. (4 points) 5. Define parallelism, ρ, using the work and the span of a multithreaded algorithm, and explain its meaning (3 points). What does it mean when P > ρ, where P is the number of processors in the system ? Please explain. (3 points) Problem 3. The CSIE network administrators need to deploy many WiFi APs (access points) in the CSIE building to provide wireless Internet connections throughout the building. That is not an easy task; if the distance between two APs is smaller than the transmission range, then two APs would interfere with each other. Although the administrators can avoid this problem by configuring the APs to use different channels, but the number of non-overlapping channels which can be utilized by the AP is limited. For example, when IEEE 802.11b/g/n is used, there are only 3 non-overlapping channels (channel 1, 6, 11). We define the problem as the following. Given a number of APs, the number of channels c, and the interfering relations of them (whether two APs would interfere with each other), can the network administrators find a way to allocate channels to APs so that no two APs would interfere with each other ? (28 points) Example : Two channels 1, 6 are available (c = 2). The line between two APs implies that they are too close and would interfere with each other (see figure 1). Here's the URL of fugure 1 : http://ppt.cc/1YLa Assume that channel 1 is reserved for research purposes in the CSIE building. Thus, only channel 6 and 11 are available (c = 2). 1. Provide an algorithm (in pseudo code or C code) to solve this problem in polynomial time. (6 points) 2. Analyze the time complexity of your algorithm. Then explain why this problem belongs to the complexity class P. (6 points) 3. Now, the network administrators decide to also utilize channel 1 ( c = 3). Prove that the problem becomes a NP-Complete problem. We can use a reduction from 3-CNF-SAT problem, which is already proven to be a NP-Complete problem in the lecture. The following outlines the reduction algorithm. The three channels 1, 6, 11 can represent the 3 states of a variable, True, False, Other, respectively. Given a formula φ of m clauses on n variables x_1, x_2, ..., x_n, we can construct an AP network as follows (see Figure 2) (a) Create 3 special APs with respectively the channels True, False, Other; these 3 special APs form a triangle (they interfere with each of the two other APs) (b) Create APs that represents each variable x and its negation. APs representing x_i and its negation ~x_i, for all i = 1 to n, interfere with each other. Link all 2n APs created so far to the special AP that uses the channel " Other ". (c) Create 5 APs for each clause, and the interfering relations are shown in Figure 2. Show that this reduction can be done in polynomial time. (6 points) Here's the URL of figure 2 : http://ppt.cc/7f3~ 4. Now prove that φ is satisfiable if and only if you can solve the 3-channel APs problem of the reduced instance. You can then show that this 3-channel APs problem is NP-hard. (6 points) 5. Prove that this problem (c = 3) is NP and thus also NP-Complete. (4 points) Problem 4. Give a multithreaded algorithm to multiply an n × n matrix A by an n-vector X that achieves θ(n^2/logn) parallelism while maintaining θ(n^2) work. Show this by calculating the work, the span, and the parallelism of your algorithm in terms on n. Note that you cannot use the following algorithm, as race condition occur in this algorithm. (10 points) Y=MAT-VEC-WRONG(A,X) n = A.rows let Y be a new vector of length n parallel for i = 1 to n parallel for j = 1 to n Y(i) = Y(i) + A(i,j) * X(j) return Y Problem 5. Consider the following multithreaded pseudo code for transosing an n × n matrix A in place : (24 points) P-TRANSPOSE(A) n = A.rows parallel for j = 2 to n parallel for i = 1 to j-1 exchange A(i,j) with A(j,i) 1. Draw the computation DAG of P_TRANSPOSE(A) in the case of n = 4. (6 points) 2. Analyze the work, span, and parallelism of this algorithm in terms of n. (3 points each) 3. Suppose that we replace the second parallel for loop in line 3 of P-TRANSPOSE with an ordinary for loop. Analyze the work, span, and parallelism of the resulting algorithm in terms of n. (3 points each) Problem 6. Consider an ordinary binary min-heap data structure with n elements supporting the instructions INSERT and EXTRACT_MIN in O(logn) worst-case time. Give a potential function φ such that the amortized cost of INSERT is O(logn) and the amortized cost of EXTRACT-MIN is O(1), and show that it works : (Hint : one way to formulate the potential function involves the depths of the nodes in the heap. Think of a way to combine them.) (12 points, 4 points each) 1. Define your potential function φ. Prove that it always satisfies φ(D_i) >= φ(D_0) for every i, where D_i is the data structure after performing the i-th operation. 2. Show that the amortized cost of INSERT is O(logn). 3. Show that the amortized code of EXTRACT-MIN is O(1). Problem 7. I understand that many of you feel that we have too much homework or the homework is too difficult that you have to spent too much time on it, while it seems that your grade does not sufficiently reflect your efforts. If you were the instructor of ADA, how would you do to reduce the homework work load, while at the same time, you can still motivate the students to spend enough time on the course materials to absorb them ? Feel free to comment on any other aspect of the course too. (4 points) --



※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.243.26 ※ 編輯: andyyuan 來自: 140.112.243.26 (01/12 00:43) ※ 編輯: andyyuan 來自: 140.112.243.26 (01/12 00:50)







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