繁体   English   中英

了解背包问题O(2 ^ n)其中T(n)

[英]understanding the Knapsack problem O(2^n) where T(n)

问题:如果背包的最佳解决方案是O(2 ^ n),则分区函数(下)在N上的速度有多快?

这就像说O(n + 2 ^ n)一样简单吗? 还是那是错误的及其O(2 ^ n),因为我们现在知道T(n)是什么。

分区功能:

bool Partition(List S){  
     create two lists //O(n) + O(n) 
     M = (Sum of all elements in S)/2; //O(n) 
     K = (Sum of all elements in S)/2; //O(n)
     if(Knapsack(Profits, Weights, M, K) == true) // O(2^n) 
          return true; 
     else 
     return false; 
} 

时间复杂度仅为O(2^n)因为O(n + 2^n)的复杂度为O(2^n)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM