给出了 CLRS 算法书中的以下问题。
For each function f (n) and time t in the following table, determine the largest size n of a problem that can be solved in time t, assuming that the algorithm to solve the problem takes f(n) microseconds.
- 当时间为 1 秒时,如何计算 f(n)=nlog(n) 的 n?
- 如何计算 f(n)=n 的 n!什么时候是 1 秒?
最佳答案
提到该算法需要 f(n) 微秒。那么,可以认为该算法由 f(n) 个步骤组成,每个步骤需要 1 微秒。
给出的问题表明相关的 f(n) 值受 1 秒的限制。 (即 106 微秒)然后,由于您正在寻找满足这些条件的最大 n 可能,您的问题归结为下面给出的不等式。
1) f(n) = nlog(n) <= 106
2) f(n) = n! <= 106
我认为剩下的主要是处理代数和对数方程来找到相关值。
关于algorithm - 计算 n 为 nlog(n) 和 n!当时间为 1 秒时。 (算法需要 f(n) 微秒),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39912029/