Amortized complexity in layman's terms?

后端 未结 6 1427
南笙
南笙 2020-12-02 06:56

Can someone explain amortized complexity in layman\'s terms? I\'ve been having a hard time finding a precise definition online and I don\'t know how it entirely relates to

6条回答
  •  自闭症患者
    2020-12-02 07:20

    Amortized means divided over repeated runs. The worst-case behavior is guaranteed not to happen with much frequency. For example if the slowest case is O(N), but the chance of that happening is just O(1/N), and otherwise the process is O(1), then the algorithm would still have amortized constant O(1) time. Just consider the work of each O(N) run to be parceled out to N other runs.

    The concept depends on having enough runs to divide the total time over. If the algorithm is only run once, or it has to meet a deadline each time it runs, then the worst-case complexity is more relevant.

提交回复
热议问题