mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-04 20:31:59 +08:00
Update the description of time and space complexity of fractional_knapsack problem. (#1688)
* 优化分数背包的部分复杂度描述,使其更加严谨 * Update fractional_knapsack_problem.md --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
@ -33,6 +33,8 @@
|
||||
[file]{fractional_knapsack}-[class]{}-[func]{fractional_knapsack}
|
||||
```
|
||||
|
||||
内置排序算法的时间复杂度通常为 $O(\log n)$ ,空间复杂度通常为 $O(\log n)$ 或 $O(n)$ ,取决于编程语言的具体实现。
|
||||
|
||||
除排序之外,在最差情况下,需要遍历整个物品列表,**因此时间复杂度为 $O(n)$** ,其中 $n$ 为物品数量。
|
||||
|
||||
由于初始化了一个 `Item` 对象列表,**因此空间复杂度为 $O(n)$** 。
|
||||
|
Reference in New Issue
Block a user