算法分析与设计_算法分析

算法分析与设计

In this tutorial you will learn about analysis of algorithms.

在本教程中,您将学习算法分析。

Before learning analysis of algorithms lets quickly take a look on what is an algorithm and why we require it.

在学习算法分析之前,让我们快速了解什么是算法以及为什么需要它。

什么是算法? (What is an Algorithm?)

An algorithm is the step by step unambiguous procedure to solve a given problem.

算法是逐步解决特定问题的明确过程。

For example steps for making Tea or Coffee can be considered as an algorithm.

例如,可以将制作茶或咖啡的步骤视为一种算法。

So for solving a problem we require an algorithm.

因此,为了解决问题,我们需要一种算法。

算法分析 (Analysis of Algorithms)

Design and Analysis of Algorithms

Image Source

图片来源

There can be several algorithms for solving one problem. So analysis of algorithms is required to find the correctness (algorithm should give solution of problem in finite number of steps) and efficiency (time and memory it takes) of an algorithm.

解决一个问题可以有几种算法。 因此,需要对算法进行分析以找到算法的正确性(算法应以有限的步数解决问题)和效率(所需的时间和内存)。

For example: To go from city A to B there can be several ways like by bus, train, flight, etc.  Depending upon the availability and convenience we choose the one that suits best for us.

例如:从城市A到城市B ,可以有几种方式,例如乘公共汽车,火车,飞机等。根据可用性和便利性,我们选择最适合我们的方式。

Similarly in computer science we use analysis of algorithms to choose the algorithm which is most efficient in terms of running time and space required.

同样,在计算机科学中,我们使用算法分析来选择在运行时间和所需空间方面最高效的算法。

运行时间分析 (Running Time Analysis)

It is the process of determining how processing time of an algorithm increase as the input size increase.

它是确定算法的处理时间如何随着输入大小的增加而增加的过程。

Input size is the number of elements in the input. There can be different types of inputs depending upon the problem type. Below are some common types of inputs.

输入大小是输入中元素的数量。 根据问题类型,可以有不同类型的输入。 以下是一些常见的输入类型。

  • Size of an array.

    数组的大小。
  • Number of elements in matrix.

    矩阵中的元素数。
  • Vertices and edges in a graph.

    图中的顶点和边。

Also Read: Asymptotic Notations

另请参阅: 渐近符号

分析类型 (Types of Analysis)

To analyze an algorithm we need to know for which input the algorithm takes less time and for which input it takes long time.

要分析算法,我们需要知道该算法对哪个输入花费较少的时间,对哪个输入花费较长时间。

In terms of running time there can be three cases mentioned below.

在运行时间方面,可能会出现以下三种情况。

Worst Case: It defines the input for which the algorithm takes longest time (slowest time) to complete.

最坏的情况:它定义了算法需要最长时间(最慢时间)才能完成的输入。

Best Case: It defines the input for which the algorithm takes least time (fastest time) to complete.

最佳情况:它定义了算法需要最少时间(最快时间)完成的输入。

Average Case: Run the algorithm using different random inputs and then find total running time by finding average of all running times.

平均情况:使用不同的随机输入运行算法,然后通过查找所有运行时间的平均值来找到总运行时间。

Comment below if have any queries regarding above tutorial.

如果对以上教程有任何疑问,请在下面评论。

翻译自: https://www.thecrazyprogrammer.com/2017/05/analysis-of-algorithms.html

算法分析与设计

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值