zoukankan      html  css  js  c++  java
  • Exercise 1.14 count change的时间复杂度

    题目

      Draw the tree illustrating the process generated by the count-change procedure of section 1.2.2 in making change for 11 cents. What are the orders of growth of the space and number of steps used by this process as the amount to be changed increases? 

    -----------------------------------------------------------------------------------------------------------------------------------------------------------------

    设amount是N。

    由于count-change算法是二叉树分支递归,所以树的高度决定了时间复杂度。二叉树的最大高度是 N/1,最小高度是N/50,因此时间复杂度介于 2^N 与2^(N/50)之间,即O(2^N)。这其中进行了大量的重复计算。

    如果使用HashMap将 "(amount, change_list)"=>"结果" 中间计算结果存储起来,则时间复杂度取决于(amount,change_list)有多少种组合数量。change_list有包含50、25、10、5、1,共有C(5,0)+C(5,1)+C(5,2)+C(5,3)+C(5,4)+C(5,5)种组合,amount则有N种取值。因此时间复杂度是O(N)。

  • 相关阅读:
    洛谷P2805 植物大战僵尸
    洛谷P4307 球队收益
    bzoj4842 Delight for a Cat
    洛谷P2053 修车
    bzoj2561 最小生成树
    bzoj3114 LCM Pair Sum
    洛谷P4486 Kakuro
    bzoj3698 XWW的难题
    关于oracle数据库
    toString方法的用法
  • 原文地址:https://www.cnblogs.com/linghuaichong/p/3974432.html
Copyright © 2011-2022 走看看