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:
Sizhe Fan
2025-03-20 19:46:17 +08:00
committed by GitHub
parent 1db2001e9b
commit 3177d35eb2

View File

@ -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)$** 。