博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
算法导论 算法_算法导论
阅读量:2532 次
发布时间:2019-05-11

本文共 3919 字,大约阅读时间需要 13 分钟。

算法导论 算法

Algorithms are an integral part of the development world. Before starting coding of any software first an effective algorithm is designed to get desired outputs. In this article, we will understand what are algorithms, characteristics of algorithms, some examples of famous algorithms, Types of algorithms etc..

算法是开发领域不可或缺的一部分。 在开始对任何软件进行编码之前,必须先设计一种有效的算法以获得所需的输出。 在本文中,我们将了解什么是算法,算法的特征,著名算法的一些示例,算法的类型等。

Let's get started...

让我们开始吧...

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

It is a combination of a sequence of finite steps to solve a particular problem. or, It is a well-defined procedure which takes zero or more input and must produce at least one output to solve a particular problem.

它是解决特定问题的一系列有限步骤的组合。 或者,这是一个定义明确的过程,需要零个或多个输入,并且必须产生至少一个输出才能解决特定问题。

算法的特性/特征 (Properties/Characteristics of Algorithms)

  • Input: It may take zero or more input.

    输入:可能需要零个或多个输入。

  • Output: It must produce at least one output.

    输出:它必须产生至少一个输出。

  • Definiteness (Unambiguous): Every step in algorithm should be well defined, unique, precise.

    确定性(明确):算法中的每个步骤都应定义明确,唯一,精确。

  • Finiteness (Limited): Every algorithm should contain a finite number of steps and should produce a result infinite amount of time.

    有限(有限):每种算法都应包含有限数量的步骤,并且应产生无限长的时间。

  • Effectiveness: Operations used in algorithm must be simple and easy to understand.

    有效性:算法中使用的运算必须简单易懂。

  • Language independent.

    语言无关。

Note:

注意:

  • An algorithm is a step by step procedure to solve a particular problem whereas a program is an algorithm that is encoded in any programming language.

    算法是解决特定问题的逐步过程,而程序是以任何编程语言编码的算法。

  • Program is language dependent and algorithm is language independent.

    程序与语言有关,而算法与语言无关。

算法符号 (Notation of an Algorithm)

  1. Name of the algorithm: It should specify the problem to be solved.

    算法名称:应该指定要解决的问题。

  2. Step no.: It is an identification tag ( step numbering ) that specify the numbering of steps/statements. It is a positive integer.

    步骤编号:这是一个标识标签(步骤编号),用于指定步骤/语句的编号。 它是一个正整数。

  3. Explanatory comments: It is used to specify the meaning of instruction that is used in the algorithm. It is used to understand the logic of operations by the use of [ ] for comments in the algorithm.

    解释性注释:它用于指定算法中使用的指令的含义。 通过在算法中使用[]进行注释,可以理解操作的逻辑。

  4. Termination: Generally it is a STOP statement and the last statement of an algorithm that denoted ending of the algorithm.

    终止:通常,它是STOP语句,并且是算法的最后一条语句,表示该算法的结尾。

(Example)

Algorithm for addition of two numbers:

两个数相加的算法:

ADD( A , B )    Step 1: Read A,B    Step 2: sum=A+B [ A & B are added and their value is stored in sum ]    Step 3: PRINT ‘Sum of A & B =’, sum    Step 4: STOP

This is an algorithm, the corresponding program will be different for different languages like for C language it is:

这是一种算法,不同的语言(例如C语言)的相应程序将有所不同:

#include
int main(){
int num1,num2,opt; printf("Enter the first Integer:\n"); scanf("%d",&num1); printf("Enter the second Integer:\n"); scanf("%d",&num2); printf("Enter an correct option -> 1:addition 2: subtraction 3: multiplication 4: division -> \n"); scanf("%d",&opt); switch(opt) {
case 1: printf("\nAddition of %d and %d is: %d",num1,num2,num1+num2); break; case 2: printf("\nSubstraction of %d and %d is: %d",num1,num2,num1-num2); break; case 3: printf("\nMultiplication of %d and %d is: %d",num1,num2,num1*num2); break; case 4: if(num2==0) {
printf("OOps Devide by zero\n"); } else {
printf("\n Division of %d and %d is: %d",num1,num2,num1/num2); } break; default: printf("\n Enter correct option\n"); } return 0;}

Output

输出量

Enter the first Integer: 10Enter the second Integer: 20Enter an correct option -> 1:addition 2: subtraction 3: multiplication 4: division ->  3Multiplication of 10  and 20 is:  200

算法类型 (Types of Algorithm)

  1. Simple Recursive algorithm

    简单递归算法

  2. Randomized algorithm

    随机算法

  3. Brute force algorithm

    蛮力算法

This was just the basic understanding of algorithm world. Read more .

这只是对算法世界的基本了解。 阅读更多 。

翻译自:

算法导论 算法

转载地址:http://dvtzd.baihongyu.com/

你可能感兴趣的文章
在mvc3中使用ffmpeg对上传视频进行截图和转换格式
查看>>
python的字符串内建函数
查看>>
Spring - DI
查看>>
微软自己的官网介绍 SSL 参数相关
查看>>
Composite UI Application Block (CAB) 概念和术语
查看>>
64位MATLAB和C混合编程以及联合调试
查看>>
原生js大总结二
查看>>
PHP基础
查看>>
UVa 11488 超级前缀集合(Trie的应用)
查看>>
Django 翻译与 LANGUAGE_CODE
查看>>
[转]iOS教程:SQLite的创建数据库,表,插入查看数据
查看>>
【转载】OmniGraffle (一)从工具栏开始
查看>>
初识ionic
查看>>
java 中打印调用栈
查看>>
开发 笔记
查看>>
ajax跨域,携带cookie
查看>>
阶段3 2.Spring_01.Spring框架简介_03.spring概述
查看>>
阶段3 2.Spring_02.程序间耦合_1 编写jdbc的工程代码用于分析程序的耦合
查看>>
阶段3 2.Spring_01.Spring框架简介_04.spring发展历程
查看>>
阶段3 2.Spring_02.程序间耦合_3 程序的耦合和解耦的思路分析1
查看>>