HEAP-EXTRACT-MIN O(log k).ppt

  1. 1、本文档共22页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
HEAP-EXTRACT-MIN O(log k)

* Xi = indicator random variable of the event that i-th person gets his hat back. E[Xi]=1/20 X=X1+…+X20 E[X] = E[X1] +…+ E[X20] = 1 derangement = permutation with no fixed points ? n! / e ? permutations with 1 fixed point number = derangement = permutation with no fixed points ? n! / e ? permutations with 1 fixed point number = n ? (n-1)! / e ? n ? (n-1)! / e ? n! ? 0.3678 ? 0.368 Claim: Alice wins only on HHH game. 1/8 - Alice wins, gets $6 7/8 - Alice loses, pays $1= gets -$1 Alice’s expected payoff: (1/8)* 6 + (7/8) * (-1) = - 1/8 Bob has the advantage. Heap MIN-HEAP-INSERT O(log k) HEAP-EXTRACT-MIN O(log k) … P1 Pk We will find the array Ai whose first element e is the smallest, output e to B, remove e from Ai, and repeat. We will use a heap H as follows: we find e using Heap-Extract-Min procedure and then add the next element from Ai to H using Min-Heap-Insert procedure. We make n calls to Min-Heap-Insert and n calls to Heap-Extract-Min. Hence the running time is O(n.log k). To simplify the exposition we add ? at the end of each array. for i from 1 to k do Pi ? 1; Max-Heap-Insert( H,[Ai[1],i] ); for j from 1 to n do [e,i] ? Heap-Extract-Max (H); Pi ? Pi + 1; Max-Heap-Insert( H, [Ai [Pi],i] ); add e to B LA?1,RA?n,LB?1,RB?n while LARA do MA? ? (LA + RA)/2 ? MB? ? (LB + RB)/2 ? if A[MA]B[MB] then LA? MA + 1, RB? MB - 1 else RA? MA, LB? MB output smaller of A[LA],B[LB] Randomized algorithm for “median” L R x =x x for random x 2) recurse on the appropriate part 1) SELECT k-th element Quick-sort L R x =x x for random x 2) recurse on both parts 1) PARTITION Quick-sort R-QUICK-SORT (A, l, r) x ? random element of A[l,r]; q ? PARTITION(A,x,l,r); R-QUICK-SORT(A,l,q-

文档评论(0)

cj80011 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档