蠻力寫算法_蠻力算法解釋

蠻力寫算法

Brute Force Algorithms are exactly what they sound like – straightforward methods of solving a problem that rely on sheer computing power and trying every possibility rather than advanced techniques to improve efficiency.

蠻力算法聽起來確實像是–解決問題的直接方法,該方法依賴于純粹的計算能力,并嘗試各種可能性而不是先進的技術來提高效率。

For example, imagine you have a small padlock with 4 digits, each from 0-9. You forgot your combination, but you don't want to buy another padlock. Since you can't remember any of the digits, you have to use a brute force method to open the lock.

例如,假設您有一個帶有4位數字的小掛鎖,每個數字從0-9。 您忘記了密碼,但是您不想再購買一個掛鎖。 由于您不記得任何數字,因此必須使用蠻力方法來打開鎖。

So you set all the numbers back to 0 and try them one by one: 0001, 0002, 0003, and so on until it opens. In the worst case scenario, it would take 104, or 10,000 tries to find your combination.

因此,您將所有數字都設置回0,然后一一嘗試:0001、0002、0003,依此類推,直到打開為止。 在最壞的情況下,將需要10 4或10,000次嘗試來找到您的組合。

A classic example in computer science is the traveling salesman problem (TSP). Suppose a salesman needs to visit 10 cities across the country. How does one determine the order in which those cities should be visited such that the total distance traveled is minimized?

計算機科學中的經典示例是旅行商問題(TSP)。 假設業務員需要訪問全國10個城市。 如何確定應該訪問這些城市的順序,以使旅行的總距離最小化?

The brute force solution is simply to calculate the total distance for every possible route and then select the shortest one. This is not particularly efficient because it is possible to eliminate many possible routes through clever algorithms.

蠻力解決方案僅是計算每種可能路線的總距離,然后選擇最短的路線。 這不是特別有效,因為可以通過巧妙的算法消除許多可能的路線。

The time complexity of brute force is O(mn), which is sometimes written as O(n*m) . So, if we were to search for a string of "n" characters in a string of "m" characters using brute force, it would take us n * m tries.

蠻力的時間復雜度為O(m n ) ,有時寫為O(n * m) 。 因此,如果要使用蠻力在“ m”個字符字符串中搜索一個“ n”個字符字符串,則需要進行n * m次嘗試。

有關算法的更多信息 (More information about algorithms)

In computer science, an algorithm is simply a set of step by step procedure to solve a given problem. Algorithms can be designed to perform calculations, process data, or perform automated reasoning tasks.

在計算機科學中,算法只是解決特定問題的一組逐步步驟。 可以將算法設計為執行計算,處理數據或執行自動推理任務。

Here's how Wikipedia defines them:

維基百科如何定義它們:

An algorithm is an effective method that can be expressed within a finite amount of space and time and in a well-defined formal language for calculating a function. Starting from an initial state and initial input (perhaps empty), the instructions describe a computation that, when executed, proceeds through a finite number of well-defined successive states, eventually producing “output” and terminating at a final ending state. The transition from one state to the next is not necessarily deterministic; some algorithms, known as randomized algorithms, incorporate random input.
算法是一種有效的方法,可以在有限的空間和時間范圍內并以定義明確的形式語言表示,以計算函數。 從初始狀態和初始輸入(可能為空)開始,指令描述了一種計算,該計算在執行時會經過有限數量的定義明確的連續狀態,最終產生“輸出”并終止于最終的結束狀態。 從一種狀態過渡到另一種狀態不一定是確定性的; 一些算法(稱為隨機算法)包含隨機輸入。

There are certain requirements that an algorithm must abide by:

算法必須滿足某些要求:

  1. Definiteness: Each step in the process is precisely stated.

    確定性:過程中的每個步驟均已明確說明。
  2. Effective Computability: Each step in the process can be carried out by a computer.

    有效的可計算性:該過程的每個步驟都可以由計算機執行。
  3. Finiteness: The program will eventually successfully terminate.

    有限:程序最終將成功終止。

Some common types of algorithms include:

一些常見的算法類型包括:

  • sorting algorithms

    排序算法
  • search algorithms

    搜索算法
  • compression algorithms.

    壓縮算法。

Classes of algorithms include

算法類別包括

  • Graph

    圖形
  • Dynamic Programming

    動態編程
  • Sorting

    排序
  • Searching

    正在搜尋
  • Strings

    弦樂
  • Math

    數學
  • Computational Geometry

    計算幾何
  • Optimization

    優化
  • Miscellaneous.

    雜。

Although technically not a class of algorithms, Data Structures are often grouped with them.

盡管從技術上講不是一類算法,但是數據結構經常與它們組合在一起。

效率 (Efficiency)

Algorithms are most commonly judged by their efficiency and the amount of computing resources they require to complete their task.

最常根據算法的效率和完成任務所需的計算資源量來判斷算法。

A common way to evaluate an algorithm is to look at its time complexity. This shows how the running time of the algorithm grows as the input size grows. Since the algorithms today have to operate on large data inputs, it is essential for our algorithms to have a reasonably fast running time.

評估算法的常見方法是查看其時間復雜度。 這顯示了算法的運行時間如何隨著輸入大小的增長而增長。 由于當今的算法必須在大數據輸入上運行,因此對于我們的算法而言,具有相當快的運行時間至關重要。

排序算法 (Sorting Algorithms)

Sorting algorithms come in various flavors depending on your necessity. Some, very common and widely used are:

排序算法根據您的需要而有不同的風格。 一些非常普遍和廣泛使用的是:

快速排序 (Quicksort)

There is no sorting discussion which can finish without quick sort. Here is the basic concept: Quick Sort

沒有排序討論,沒有快速排序就可以結束。 這是基本概念: 快速排序

合并排序 (Mergesort)

A sorting algorithm which relies on the concept how to sorted arrays are merged to give one sorted arrays. Read more about it here: Mergesort

排序算法依賴于如何將排序數組合并為一個排序數組的概念。 在此處了解更多信息: Mergesort

freeCodeCamp’s curriculum heavily emphasizes creating algorithms. This is because learning algorithms is a good way to practice programming skills. Interviewers most commonly test candidates on algorithms during developer job interviews.

freeCodeCamp的課程非常強調創建算法。 這是因為學習算法是練習編程技能的好方法。 面試官最常在開發人員工作面試中測試算法候選人。

有關JavaScript算法的書籍: (Books about algorithms in JavaScript:)

Data Structures in JavaScript

JavaScript中的數據結構

  • Free book which covers Data Structures in JavaScript

    涵蓋JavaScript中數據結構的免費書籍
  • GitBook

    GitBook

Learning JavaScript Data Structures and Algorithms - Second Edition

學習JavaScript數據結構和算法-第二版

  • Covers object oriented programming, prototypal inheritance, sorting & searching algorithms, quicksort, mergesort, binary search trees and advanced algorithm concepts

    涵蓋面向對象的編程,原型繼承,排序和搜索算法,快速排序,合并排序,二進制搜索樹和高級算法概念
  • Amazon

    亞馬孫

  • ISBN-13: 978-1785285493

    ISBN-13:978-1785285493

Data Structures and Algorithms with JavaScript: Bringing classic computing approaches to the Web

JavaScript的數據結構和算法:將經典的計算方法引入Web

  • Covers recursion, sorting and searching algorithms, linked lists and binary search trees.

    涵蓋遞歸,排序和搜索算法,鏈表和二進制搜索樹。
  • Amazon

    亞馬孫

  • ISBN-13: 978-1449364939

    ISBN-13:978-1449364939

翻譯自: https://www.freecodecamp.org/news/brute-force-algorithms-explained/

蠻力寫算法

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

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

相關文章

NoClassDefFoundError和ClassNotFoundException之間有什么區別?是由什么導致的?

問題: NoClassDefFoundError和ClassNotFoundException之間有什么區別?是由什么導致的? NoClassDefFoundError和ClassNotFoundException之前的區別是什么? 是什么導致它們被拋出?這些問題我們要怎么樣解決? 當我在為了引入新的jar包而修改現有代碼…

關于Tensorflow安裝opencv和pygame

1.安裝opencv https://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv C:\ProgramData\Anaconda3\Lib\site-packages>pip install opencv_python-3.3.1-cp36-cp36m-win_amd64.whlProcessing c:\programdata\anaconda3\lib\site-packages\opencv_python-3.3.1-cp36-cp36m-win_a…

內置的常用協議實現模版

SuperSocket內置的常用協議實現模版 中文(中國)Toggle Dropdownv1.6Toggle Dropdown關鍵字: TerminatorReceiveFilter, CountSpliterReceiveFilter, FixedSizeReceiveFilter, BeginEndMarkReceiveFilter, FixedHeaderReceiveFilter 閱讀了前面一篇文檔之…

機器學習 來源框架_機器學習的秘密來源:策展

機器學習 來源框架成功的機器學習/人工智能方法 (Methods for successful Machine learning / Artificial Intelligence) It’s widely stated that data is the new oil, and like oil, data needs the right refinement to evolve to be utilised perfectly. The power of ma…

linux gcc 示例_最好的Linux示例

linux gcc 示例Linux is a powerful operating system that powers most servers and most mobile devices. In this guide, we will show you examples of how to use some of its most powerful features. This involves using the Bash command line.Linux是功能強大的操作系…

帆軟報表和jeecg的進一步整合--ajax給后臺傳遞map類型的參數

下面是頁面代碼&#xff1a; <% page language"java" contentType"text/html; charsetUTF-8" pageEncoding"UTF-8"%> <%include file"/context/mytags.jsp"%> <% String deptIds (String)request.getAttribute("…

@Nullable 注解的用法

問題&#xff1a;Nullable 注解的用法 我看到java中的一些方法聲明為: void foo(Nullable Object obj){…}在這里Nullable是什么意思?這是不是意味著輸入可以為空? 沒有這個注解&#xff0c;輸入仍然可以是null&#xff0c;所以我猜這不是它的用法? 回答一 它清楚地說明…

WebLogic調用WebService提示Failed to localize、Failed to create WsdlDefinitionFeature

在本地Tomcat環境下調用WebService正常&#xff0c;但是部署到WebLogic環境中&#xff0c;則提示警告&#xff1a;[Failed to localize] MEX0008.PARSING_MDATA_FAILURE<SOAP_1_2 ......警告&#xff1a;[Failed to localize] MEX0008.PARSING_MDATA_FAILURE<SOAP_1_1 ..…

呼吁開放外網_服裝數據集:呼吁采取行動

呼吁開放外網Getting a dataset with images is not easy if you want to use it for a course or a book. Yes, there are many datasets with images, but few of them are suitable for commercial or educational use.如果您想將其用于課程或書籍&#xff0c;則獲取帶有圖像…

git push命令_Git Push命令解釋

git push命令The git push command allows you to send (or push) the commits from your local branch in your local Git repository to the remote repository.git push命令允許您將提交(或推送 )從本地Git存儲庫中的本地分支發送到遠程存儲庫。 To be able to push to you…

在Java里面使用Pairs或者二元組

問題&#xff1a;在Java里面使用Pairs或者二元組 在Java里面&#xff0c;我的Hashtable要用到一個元組結構。在Java里面&#xff0c;我可以使用的什么數據結構呢&#xff1f; Hashtable<Long, Tuple<Set<Long>,Set<Long>>> table ...回答一 我不認…

github 搜索技巧

1、關鍵詞 指定開發語言 bitcoin language:javascript 2、關鍵詞 stars 數量 forks 數量 bitcoin stars:>100 forks:>50

React JS 組件間溝通的一些方法

剛入門React可能會因為React的單向數據流的特性而遇到組件間溝通的麻煩&#xff0c;這篇文章主要就說一說如何解決組件間溝通的問題。 1.組件間的關系 1.1 父子組件 ReactJS中數據的流動是單向的&#xff0c;父組件的數據可以通過設置子組件的props傳遞數據給子組件。如果想讓子…

數據可視化分析票房數據報告_票房收入分析和可視化

數據可視化分析票房數據報告Welcome back to my 100 Days of Data Science Challenge Journey. On day 4 and 5, I work on TMDB Box Office Prediction Dataset available on Kaggle.歡迎回到我的100天數據科學挑戰之旅。 在第4天和第5天&#xff0c;我將研究Kaggle上提供的TM…

sql limit子句_SQL子句解釋的位置:之間,之間,類似和其他示例

sql limit子句什么是SQL Where子句&#xff1f; (What is a SQL Where Clause?) WHERE子句(和/或IN &#xff0c; BETWEEN和LIKE ) (The WHERE Clause (and/or, IN , BETWEEN , and LIKE )) The WHERE clause is used to limit the number of rows returned.WHERE子句用…

在Java里面使用instanceof的性能影響

問題&#xff1a;在Java里面使用instanceof的性能影響 我正在寫一個應用程序&#xff0c;其中一種設計方案包含了instanceof操作的大量使用。雖然我知道面向對象設計通常試圖避免使用instanceof&#xff0c;但那是另一回事了&#xff0c;這個問題純粹只是討論與性能有關。我想…

Soot生成控制流圖

1.將soot.jar文件復制到工程bin目錄下&#xff1b;2.在cmd中執行如下命令java -cp soot-trunck.jar soot.tools.CFGViewer --soot-classpath .;"%JAVA_HOME%"\jre\lib\rt.jar com.wauoen.paper.classes.Activity其中&#xff0c;JAVA_HOME是jdk目錄&#xff1b;com.w…

Centos 6.5安裝MySQL-python

報錯信息&#xff1a;Using cached MySQL-python-1.2.5.zip Complete output from command python setup.py egg_info: sh: mysql_config: command not found Traceback (most recent call last): File "<string>", line 1, in <module&g…

react 最佳實踐_最佳React教程

react 最佳實踐React is a JavaScript library for building user interfaces. It was voted the most loved in the “Frameworks, Libraries, and Other Technologies” category of Stack Overflow’s 2017 Developer Survey.React是一個用于構建用戶界面JavaScript庫。 在S…

先知模型 facebook_Facebook先知

先知模型 facebook什么是先知&#xff1f; (What is Prophet?) “Prophet” is an open-sourced library available on R or Python which helps users analyze and forecast time-series values released in 2017. With developers’ great efforts to make the time-series …