krahets / hello-algo

《Hello 算法》:动画图解、一键运行的数据结构与算法教程。支持 Python, Java, C++, C, C#, JS, Go, Swift, Rust, Ruby, Kotlin, TS, Dart 代码。简体版和繁体版同步更新,English version ongoing
https://www.hello-algo.com
Other
95.04k stars 12.07k forks source link

对于有多个参数的函数时间及空间复杂度怎么表示 #1295

Closed LRoInT closed 4 months ago

LRoInT commented 4 months ago

有时函数会出现有多个参数的情况,若这两个参数都会影响时间及空间复杂度时该怎么表示

krahets commented 4 months ago

和一个参数的表示方法一样,将每个独立参数都计入考虑就行了,例如双层循环分别为 m 次和 n 次,那么时间复杂度为 O(mn)