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/cn.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/cn.aspx?n=bbs/Grad-ProbAsk/M.1476847293.A.776.html 但前两题看题意,我看不出来要用哪种,是不是我哪里没理解到? --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 36.229.66.15 (台湾)
※ 文章网址: https://webptt.com/cn.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灯, 水草

请输入看板名称,例如:e-shopping站内搜寻

TOP