如何确定的算法函数的复杂? [英] How to determine the complexity of an algorithm function?

查看:131
本文介绍了如何确定的算法函数的复杂?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你怎么知道,如果一个算法函数取线性/常数/对数时间的具体操作?它不依赖于CPU周期?

How do you know if a algorithm function takes linear/constant/logarithmic time for a specific operation? does it depend on the cpu cycles?

推荐答案

有三种方法可以做到这一点(至少)。

There are three ways you can do it (at least).

  1. 查找算法在网络上,看看它说,有关它的时间复杂度。

  1. Look up the algorithm on the net and see what it says about its time complexity.

检查算法,自己看东西像嵌套循环和递归的条件,以及多久每次循环运行或每个递归完成后,根据输入的大小。这方面的一个扩展是一个严格的数学分析。

Examine the algorithm yourself to look at things like nested loops and recursion conditions, and how often each loop is run or each recursion is done, based on the input size. An extension of this is a rigorous mathematical analysis.

实验。改变输入变量,看看需要多长时间取决于这一点。计算的公式,让你说基于变量运行时(联立方程求解是一种可能性在这里为O(n C ) - 型功能

Experiment. Vary the input variable and see how long it takes depending on that. Calculate an equation that gives you said runtime based on the variable (simultaneous equation solving is one possibility here for O(nc)-type functions.

其中,可能是第一个是最简单的门外汉,因为它几乎肯定会至今已生产了更多的人见地做第二: - )

Of these, probably the first is the easiest for the layman since it will almost certainly have been produced by someone more knowledgable doing the second :-)

这篇关于如何确定的算法函数的复杂?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆