欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    MarkAllenWeiss数据结构与算法分析课后习题答案2339.pdf

    • 资源ID:83884569       资源大小:73.32KB        全文页数:3页
    • 资源格式: PDF        下载积分:20金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要20金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    MarkAllenWeiss数据结构与算法分析课后习题答案2339.pdf

    Chapter 2:Algorithm Analysis2.12/N,37,N,N,Nlog log N,Nlog N,Nlog(N2),Nlog2N,N1.5,N2,N2log N,N3,2N/2,2N.Nlog N and Nlog(N2)grow at the same rate.2.2(a)True.(b)False.A counterexampleis T1(N)=2N,T2(N)=N,and f(N)=N.(c)False.A counterexampleis T1(N)=N2,T2(N)=N,and f(N)=N2.(d)False.The same counterexampleas in part(c)applies.2.3We claim that Nlog N is the slower growing function.To see this,suppose otherwise.Then,N/log Nwould grow slower than log N.Taking logs of both sides,we find that,under this assumption,/log N log N grows slower than log log N.But the first expres-sion simplifies to log N.If L=log N,then we are claiming that L grows slower thanlog L,or equivalently,that2Lgrowsslowerthanlog2 L.Butwe knowthatlog2 L=(L),so the original assumption is false,proving the claim.2.4Clearly,logk1N=(logk2N)if k1 k2,so we need to worry only about positive integers.The claim is clearly true for k=0 and k=1.Suppose it is true for k i.Then,byLHospitals rule,NlimNlogiN_ _=Nlim iNlogi1N_The second limit is zero by the inductive hypothesis,proving the claim.2.5Let f(N)=1 when N is even,and N when N is odd.Likewise,let g(N)=1 when N isodd,and N when N is even.Then the ratio f(N)/g(N)oscillates between 0 and.2.6For all these programs,the following analysis will agree with a simulation:(I)The running time is O(N).(II)The running time is O(N2).(III)The running time is O(N3).(IV)The running time is O(N2).(V)j can be as large as i2,which could be as large as N2.k can be as large as j,which isN2.The running time is thus proportional to N.N2.N2,which is O(N5).(VI)The if statement is executed at most N3times,by previous arguments,but it is trueonly O(N2)times(because it is true exactly i times for each i).Thus the innermost loop isonly executed O(N2)times.Each time through,it takes O(j2)=O(N2)time,for a total ofO(N4).This is an example where multiplying loop sizes can occasionally give an overesti-mate.2.7(a)It should be clear that all algorithms generate only legal permutations.The first twoalgorithms have tests to guarantee no duplicates;the third algorithm works by shuffling anarray that initially has no duplicates,so none can occur.It is also clear that the first twoalgorithms are completely random,and that each permutation is equally likely.The thirdalgorithm,due to R.Floyd,is not as obvious;the correctness can be proved by induction.-4-SeeJ.Bentley,Programming Pearls,Communications of the ACM 30(1987),754-757.Note that if the second line of algorithm 3 is replaced with the statementSwap(Ai,A RandInt(0,N-1);then not all permutations are equally likely.To see this,notice that for N=3,there are 27equally likely ways of performing the three swaps,depending on the three random integers.Since there are only 6 permutations,and 6 does not evenly divide27,each permutation cannot possibly be equally represented.(b)For the first algorithm,the time to decide if a random number to be placed in Ai hasnot been used earlier is O(i).The expected number of random numbers that need to betried is N/(N i).This is obtained as follows:i of the N numbers would be duplicates.Thus the probability of success is(N i)/N.Thus the expected number of independenttrials is N/(N i).The time bound is thusi=0N1NiNi_ i=0N1NiN2_ N2i=0N1Ni1_ 1,the number of multiplies used islog N +b(N)12.18(a)A.(b)B.(c)The information given is not sufficient to determine an answer.We have only worst-case bounds.(d)Yes.2.19(a)Recursion is unnecessary if there are two or fewer elements.(b)One way to do this is to note that if the first N1 elements have a majority,then the lastelement cannot change this.Otherwise,the last element could be a majority.Thus if N isodd,ignore the last element.Run the algorithm as before.If no majority element emerges,then return the Nthelement as a candidate.(c)The running time is O(N),and satisfies T(N)=T(N/2)+O(N).(d)One copy of the original needs to be saved.After this,the B array,and indeed the recur-sion can be avoided by placing each Biin the A array.The difference is that the originalrecursive strategy implies that O(log N)arrays are used;this guarantees only two copies.2.20 Otherwise,we could perform operations in parallel by cleverly encoding several integersinto one.For instance,if A=001,B=101,C=111,D=100,we could add A and B at thesame time as C and D by adding 00A00C+00B00D.We could extend this to add N pairsof numbers at once in unit cost.2.22 No.If Low=1,High=2,then Mid=1,and the recursive call does not make progress.2.24 No.As in Exercise 2.22,no progress is made.-6-

    注意事项

    本文(MarkAllenWeiss数据结构与算法分析课后习题答案2339.pdf)为本站会员(得****3)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开