gpt4 book ai didi

time-complexity - 时间复杂度上的大写 N 与小写 n

转载 作者:行者123 更新时间:2023-12-05 05:07:48 24 4
gpt4 key购买 nike

我遇到了以下问题,这让我很困惑:

A quadratic algorithm with processing time T(n) = cn2 spends T(N) seconds for processing N data items. How much time will be spent for processing n = 5000 data items, assuming that N = 100 and T(N) = 1ms?

N和n在时间复杂度上有什么区别?

最佳答案

大写字母N与小写字母n在时间复杂度上没有特殊含义。在这种情况下 nN 只是用作同一变量的不同值,如果他们给你的不是 N ,那也没有什么区别x.

Important, when I use A => B, the => arrow means "A equals to B", or if you prefer "A ends up being B"

现在,考虑到原始二次函数 T(n) = c*n^2

  1. 如果 N = 100T(N) = 1ms 那么他们告诉你 T(100)
    = 1ms
    => 1ms = c * 100^2.
  2. 你从前面的陈述中推导出的是 1ms = c * 100^2 =>c = 1ms/100^2
  3. 现在只需替换​​ T(n) = 的原始公式中的 cncn2(n = 5000):

    T(5000) = (1/100^2) * 5000^2 => T(n) = 2.500ms => T( n) = 2,5s

关于time-complexity - 时间复杂度上的大写 N 与小写 n,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58833584/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com