算法導論 算法_算法導論

算法導論 算法

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<stdio.h>
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: 10
Enter the second Integer: 20
Enter an correct option -> 1:addition 2: subtraction 3: multiplication 4: division ->  3Multiplication of 10  and 20 is:  200

算法類型 (Types of Algorithm)

  1. Divide and conquer algorithm

    分而治之算法

  2. Greedy algorithm

    貪心算法

  3. Dynamic programming

    動態編程

  4. Branch and bound algorithm

    分支定界算法

  5. Back Tracking

    回溯

  6. Simple Recursive algorithm

    簡單遞歸算法

  7. Randomized algorithm

    隨機算法

  8. Brute force algorithm

    蠻力算法

This was just the basic understanding of algorithm world. Read more articles/tutorials on Algorithms.

這只是對算法世界的基本了解。 閱讀有關算法的更多文章/教程 。

翻譯自: https://www.includehelp.com/algorithms/introduction-to-algorithms.aspx

算法導論 算法

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/540941.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/540941.shtml
英文地址,請注明出處:http://en.pswp.cn/news/540941.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

[Phonegap+Sencha Touch] 移動開發77 Cordova Hot Code Push插件實現自己主動更新App的Web內容...

原文地址&#xff1a;http://blog.csdn.net/lovelyelfpop/article/details/50848524 插件地址&#xff1a;https://github.com/nordnet/cordova-hot-code-push 以下是我對GitHub項目readme的翻譯 ——————————————————————————————————————…

java 如何重寫迭代器,如何用Java按需定制自己的迭代器

編寫自己的迭代器的流程是&#xff1a;首先實現Iterable接口&#xff0c;進而實現該接口中的Iterator iterator()方法&#xff0c;該方法返回接口Iterator&#xff0c;Iterator接口中封裝了next&#xff0c;hasnext&#xff0c;remove等方法。實現了Iterable接口的類能夠通過fo…

count函數里加函數_PHP count()函數與示例

count函數里加函數PHP count()函數 (PHP count() function) "count() function" is used to get the total number of elements of an array. “ count()函數”用于獲取數組元素的總數。 Syntax: 句法&#xff1a; count(array, [count_mode])Here, 這里&#xff0…

php整合支付寶,Thinkphp5.0整合支付寶在線下單

thinkphp5.0支付寶在線支付下單整個流程&#xff0c;包括創建訂單、支付成功回調更新訂單狀態、最終跳轉到商戶訂單詳情頁查看演示下載資源&#xff1a;17次 下載資源下載積分&#xff1a;998積分支付寶在線支付控制器代碼 public function alipay() {//發起支付寶支付$order_n…

python函數示例_PHP closeir()函數與示例

python函數示例PHP Closedir()函數 (PHP closedir() function) The full form of closedir is "Close Directory", the function closedir() is used to close an opened directory. Closedir的完整格式為“ Close Directory” &#xff0c; 函數closedir()用于關閉打…

java宋江,Java編程內功-數據結構與算法「單鏈表」,

package com.structures.linkedlist;public class SingleLinkedListDemo {public static void main(String[] args) {HeroNode heroNode1 new HeroNode(1, "宋江", "及時雨");HeroNode heroNode2 new HeroNode(2, "盧俊義", "玉麒麟"…

智能家居逐漸融入AI技術 向大眾市場擴張仍需時間

雖然智能家居變得越來越普遍&#xff0c;并且大眾認知度越來越高&#xff0c;但是在這一技術變得像智能手機一樣無處不在之前&#xff0c;OEM和服務提供商仍然有很長的路要走。 在2016年11月在硅谷舉行的智能家居峰會上&#xff0c;代表們聽到了來自整個價值鏈上的聲音&#xf…

python 示例_Python使用示例設置add()方法

python 示例設置add()方法 (Set add() Method) add() method is used to add an element to the set, the method accepts an element and adds the elements to this set. add()方法用于將元素添加到集合中&#xff0c;該方法接受元素并將元素添加到該集合中。 Note: If the …

php怎么引用表單元素,表單元素:最全的各種html表單元素獲取和使用方法總結...

表單是網頁與用戶的交互工具&#xff0c;由一個元素作為容器構成&#xff0c;封裝其他任何數量的表單控件&#xff0c;還有其他任何元素里可用的標簽&#xff0c;表單能夠包含、、、、、等表單控件元素。表單元素有哪些呢&#xff1f;它包含了如下的這些元素&#xff0c;輸入文…

數據中心部署氣流遏制系統需要考慮的十大要素

數據中心氣流遏制策略能夠大幅提高傳統數據中心制冷系統的可預測性和效率。事實上&#xff0c;綠色網格組織&#xff08;The Green Grid&#xff09;將氣流管理策略稱作“實施數據中心節能計劃的起點”。但是&#xff0c;大多數已有數據中心由于受各種條件的制約&#xff0c;只…

JAVA語言異常,Java語言中的異常

1、異常分類從產生源頭來看&#xff0c;Java語言中的異常可以分為兩類&#xff1a;JVM拋出的異常。比如&#xff1a;訪問null引用會引發NullPointerException&#xff1b;0作為除數&#xff0c;如9/0&#xff0c;JVM會拋出ArithmeticException&#xff1b;內存消耗完&#xff0…

使用Mybatis Generator結合Ant腳本快速自動生成Model、Mapper等文件的方法

新建generatorConfig.xml和build_mybatis.xml&#xff1a; jar下載 <dependency><groupId>org.mybatis.generator</groupId><artifactId>mybatis-generator-core</artifactId><version>1.3.2</version></dependency> <depe…

java bitset_Java BitSet or()方法與示例

java bitsetBitSet類或()方法 (BitSet Class or() method) or() method is available in java.util package. or()方法在java.util包中可用。 or() method is used to perform logical OR between this BitSet and the given BitSet(bs). This BitSet is updated when either t…

matlab 細化函數,MATLAB圖像處理工具箱函數(細化篇).doc

MATLAB圖像處理工具箱函數(細化篇)第3章 MATLAB數字圖像處理工具箱3.1 MATLAB圖像預處理3.1.1 圖像處理的基本操作1. 讀入并顯示一幅圖像clear %清除所有的工作平臺變量close all %關閉已打開的圖形窗口Iimread (pout.tif); %讀取圖像pout.tif(該圖像是圖像處理工具箱自帶的圖像…

STM32啟動解析

啟動方式對的不同下載模式 STM32可以通過BOOT引腳的配置&#xff0c;來選擇不同的啟動模式------對應不同的下載方式。 仿真器下載—— 內部FLASH的啟動方式 串口下載 —— 系統存儲器的啟動方式 內部SRAM一般不用&#xff0c;不講 啟動過程 以內部FLASH的啟動方式為例&am…

OpenBSD基金會收到錘子科技約140萬捐贈款

11月26日消息&#xff0c;給開源項目捐款一向是錘子科技發布會的傳統&#xff0c;去年發布會的門票收入捐給了國人章亦春主導的開源項目OpenResty。今年&#xff0c;錘子科技選擇將收益捐贈給OpenBSD基金會。OpenBSD基金會收到錘子科技約140萬捐贈款 OpenBSD基金會11月23日發布…

自動化部署kvm虛擬機_自動化虛擬助手

自動化部署kvm虛擬機The automated virtual assistant or commonly called personal assistants, are developed to serve its users by performing some tasks, setting reminders and much more based on the input is given and local awareness. It is integrated with a l…

php 數據庫編碼,php怎么設置數據庫編碼方式

在php中&#xff0c;可以使用mysql_query()函數來設置mysql數據庫的編碼方式&#xff1b;具體方法&#xff1a;在mysql_connect()語句之后添加“mysql_query("set names 編碼方式");”代碼即可。本教程操作環境&#xff1a;windows7系統、PHP7.1版&#xff0c;DELL G…

mysql截取字符串與reverse函數

mysql的函數大全&#xff1a; http://www.jb51.net/Special/606.htm 這個網頁上很多知識點&#xff0c;可以學習下&#xff0c;關于mysql的函數&#xff0c;也可以作為API查詢&#xff1a; 這里只說下mysql的截取函數和reverse函數&#xff1a; MySQL 字符串截取函數&#xff1…

flask sql外鍵使用_如何在SQL中使用外鍵?

flask sql外鍵使用Basically, Foreign Key represents relationship between tables. 基本上&#xff0c; 外鍵代表表之間的關系 。 Syntax: 句法&#xff1a; column-name data_type (size) CONSTRAINT constraint-name References Table-name (Column-name)Example: 例&a…