Grad-ProbAsk 板


LINE

OBST問題, 在學習時, 看過兩種BST Cost算法 例如: 範例,給: i 0 1 2 3 4 5 pi / 0.08 0.15 0.05 0.1 0.12 qi 0.04 0.1 0.08 0.1 0.06 0.12 第一種:失敗節點視為下一層(簡稱下層): 範例產生的樹如下: p4 p2 p5 p1 p3 q4 q5 q0 q1 q2 q3 cost = 1(.1)+2(.15+.12)+3(.08+.05+.06+.12)+4(.04+.1+.08+.1) = 2.85 第二種:失敗節點視為同個節點(簡稱同層): 範例產生的樹如下(括號內表示同個點): (p2) (q0 p1 q1) (p4) (q2 p3 q3) (q4 p5 q5) cost = 1(.15)+2(.04+.08+.1+.1)+3(.08+.05+.1+.06+.12+.12) = 2.38 同層的DP關係式如下: * w(i,i)=qi, w(i,j)=w(i,j-1)+pj+qj * e(i,i)=0, eij=wij+min(r=i+1..j)e(i,r-1)+e(r,j) 下層的DP關係式如下: * w(j+1,j)=qj, w(i,j)=w(i,j-1)+pj+qj * e(j+1,j)=qj, e(i,j)=wij+min(r=i..j)e(i,r-1)+e(r+1,j) 兩種算出來答案是不同 看的的說法通常會說 沒特別提示 就視為同層 (https://webptt.com/m.aspx?n=bbs/Grad-ProbAsk/M.1268193734.A.D0B.html 我的問題是 如何判斷是某些題目問的是下層 例如: 111成大 Given a sequence K=(k1,k2,k3,k4,k5) of five distinct keys in sorted order (so that k1<k2<k3<k4<k5) and six dummy keys d0,d1,d2,d3,d4,d5, representing values not in K, we have a probability pi for ki and a probability qi for di. Determine the cost of an optimal binary search tree for K with the following probabilities: i 0 1 2 3 4 5 pi / 0.08 0.15 0.05 0.1 0.12 qi 0.04 0.1 0.08 0.1 0.06 0.12 找到的解答: 下層 https://i.imgur.com/DhqdU0H.png
https://i.imgur.com/ciVTura.png
e15=w15+min(r=4)e13+e55 = 1+ 1.37+.48 = 2.85 106成大 Given a sequence K = (k1, k2, ..., k6) of 6 distinct keys in sorted order with probabilities 0.06, 0.08, 0.10, 0.04, 0.12, 0.14. Some searches may be for values not in K, and so we also have 7 dummy keys, d0, d1, . .., d6, with probabilities 0.07, 0.07, 0.07, 0.07, 0.06, 0.06, 0.06. 找到的解答: 下層 e16=w16+min(r=3)e12+e46= 1+ .76+1.23 = 2.99 95成大 Given a sequence K=<k1,k2...kn> of n distinct keys in sorted order such that k1<k2<...<kn, and we wish to build a binary search tree from these keys. For each key ki, we have a probability pi, that a search will be for ki. Some searches may be for values not in K, and so we also have n+1 "dummy keys" d0,d1,d2,..,dn, representing values not in K. In particular, d0 represents all values less than k1, dn represents all values greater than k, and for i=1,2,...,n-1, the dummy key di, represents al values between ki, and ki+1. For each dummy key di, we have a probability qi, that a search will correspond to di. Each key ki is an internal node, and each dummy key di is a leaf. Every search is either successful (finding some key ki) or unsuccessful (finding some dummy key di), and so we have Σ(上n下i=0)pi+Σ(上n下i=0)qi=1. The expected cost or a search tree T is E[search cost in T] = Σ(上n下i=1)(depthT(ki)+1)*pi+Σ(上n下i=0)(depthT(di)+1)*qi = 1+Σ(上n下i=1)depthT(ki)*pi+Σ(上n下i=0)depthT(di)*qi where depthT denotes a node's depth in the tree T. Given five keys with p1=0.15, p2=p4=q5=q1=0.10, p3=q0=q2=q3=q4=0.05, p5=0.20, compute the corresponding small lest search cost. 找到的解答: 下層 https://i.imgur.com/1c5gQDL.png
e15=w15+min(r=2)e11+e35= 1 + .45+1.3 = 2.75 e15=w15+min(r=4)e13+e55= 1 + 1.25+.5 = 2.75 (兩種可能) 112成大 We are given a sequence K=<k1, k2,...,kn> of n distinct keys in sorted order (so that k1<k2<...<kn), and we wish to build a binary search tree from these keys. For each key ki, we have a probability pi that a search will be for ki. Some searches may be for values not in K, and so we also have n+1 "dummy keys" d0, d1,..., dn representing values not in K. In particular, d0 represents all values less than k1, dn represents all values greater than kn, and for i= 1,2,...,n-1, the dummy key di represents all values between ki and k(i+1). For each dummy key di, we have a probability qi that a search will correspond to di. Determine the cost and structure of an optimal binary search tree in the expected cost of search time for a set of n = 7 keys with the following probabilities: i 0 1 2 3 4 5 6 7 pi / .04 .06 .08 .02 .10 .12 .14 qi .06 .06 .06 .06 .05 .05 .05 .05 找到的解答: 同層 https://i.imgur.com/4x6hUVW.png
97清大 Let n= 5 and (a1, a2, a3, a4, a5) = (do, for, if, return, while) be an identifier set. Let (p1, p2, p3, p4, p5) = (1,1,3,3,2) and (q0, q1, q2, q3, q4, q5) = (2,3,1,2,1,1) be the probabilities for the successful and unsuccessful search of identifiers, respectively. Note that the p's and q's have been multiplied by 20 for convenience. What is the cost of the optimal binary search tree for (do, for, if, return, while)? 找到的解答: 同層 https://i.imgur.com/9Xx2H7H.png
e05=w05+min(r=3)e02+e35 = 20 + 13+13 = 46 98交大 Suppose that we have n records, ai, i = 1,...,n, and these n records are stored in the nodes in a binary search tree. We call this kind of node the data node and each node (record) is associated with an access probability pi. If a search in the binary search tree reaches an external node between ai and a(i+1), we say that the search reaches a failure node. There are n+1 failure nodes. Each failure node is associated with a probability qi, i = 0,. ..,n. A node (data node or failure node) contributes cost p*h to the total search cost where p is the associated probability and h is the depth of the node. The binary search tree stores these n records is an optimal binary search tree if the total cost (Σ(i)pi*hi + Σ(j)qj*hj) is the least. Which of the following statements are true. (a) Suppose there are 4 records with key values (10,15,20,25), pi are (3/16, 3/16, 1/16, 1/16), and qi are (2/16, 3/16, 1/16, 1/16, 1/16), the optimal binary search tree is as shown in Figure 3-2. 15 10 20 25 (b) Suppose there are 4 records with key values (10, 15,20, 25), pi are (3/16, 3/16, 1/16, 1/16), and qi are (2/16, 3/16, 1/16, 1/16, 1/16), the optimal binary search tree is as shown in Figure 3-3. 20 15 25 10 找到的解答: 同層 https://i.imgur.com/swXpvmx.png
前三題跟後三題,差別在哪才會用到同層的算法? 第三題有(95成大)有寫"dummy key di is a leaf"可能比較好懂 以前的文有說題目會定義清楚 (https://webptt.com/m.aspx?n=bbs/Grad-ProbAsk/M.1476847293.A.776.html 但前兩題看題意,我看不出來要用哪種,是不是我哪裡沒理解到? --



※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.229.66.15 (臺灣)
※ 文章網址: https://webptt.com/m.aspx?n=bbs/Grad-ProbAsk/M.1726751753.A.C5B.html ※ 編輯: Jaka (36.229.66.15 臺灣), 09/19/2024 21:17:23
1F:→ new1100726: 用cormen那套就好,成大OBST都歸類在演算法那邊 10/28 17:44
2F:→ new1100726: 資結算OBST還蠻麻煩的,Cormen那套直接表格弄一弄就好 10/28 17:45
3F:→ Jaka: 好 謝謝 11/02 22:01







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

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

TOP