蛮力写算法

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-1785285493ISBN-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-1449364939ISBN-13:978-1449364939

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

蛮力写算法

蛮力写算法_蛮力算法解释相关推荐

  1. 常用十大算法_回溯算法

    回溯算法 回溯算法已经在前面详细的分析过了,详见猛击此处. 简单的讲: 回溯算法是一种局部暴力的枚举算法 循环中,若条件满足,进入递归,开启下一次流程,若条件不满足,就不进行递归,转而进行上一次流程. ...

  2. cb32a_c++_STL_算法_查找算法_(5)adjacent_find

    cb32a_c++_STL_算法_查找算法_(5)adjacent_find adjacent_find(b,e),b,begin(),e,end() adjacent_find(b,e,p),p-p ...

  3. 层次聚类算法 算法_聚类算法简介

    层次聚类算法 算法 Take a look at the image below. It's a collection of bugs and creepy-crawlies of different ...

  4. prim算法_贪心算法详解(附例题)

    贪心算法的特征规律 贪心算法,"贪心"二字顾名思义,因此其规律特征就是更加注重当前的状态,贪心法做出的选择是对于当前所处状态的最优选择,它的解决问题的视角是微观的"局部& ...

  5. 数据挖掘算法_数据挖掘算法入门

    有南方的朋友讲过北方人喜欢打比方,尤其是甲方的,其实也没什么不好了.如果是做菜的话,那么这些算法就相当于烹饪的工具了.对原始的食材进行预处理.加工整合,选择合适烹饪工具,以及对应的方法步骤,最后收获舌 ...

  6. python序列模式的关联算法_关联算法

    以下内容来自刘建平Pinard-博客园的学习笔记,总结如下: 1 Apriori算法原理总结 Apriori算法是常用的用于挖掘出数据关联规则的算法,它用来找出数据值中频繁出现的数据集合,找出这些集合 ...

  7. java调度问题的贪心算法_贪心算法——换酒问题

    知识回顾 贪心算法 (greedy algorithm),又称贪婪算法. 是一种在每一步选择中都采取在当前状态下最好或最优(即最有利)的选择,从而希望导致结果是最好或最优的算法. 贪心算法在 有最优子 ...

  8. 编程神奇算法_分类算法的神奇介绍

    编程神奇算法 由Bryan Berend | 2017年3月23日 (by Bryan Berend | March 23, 2017) About Bryan: Bryan is the Lead ...

  9. python实现关联算法_关联规则算法Apriori学习及Python实现

    关联规则算法Apriori以及FP-growth学习 最近选择了关联规则算法进行学习,目标是先学习Apriori算法,再转FP-growth算法,因为Spark-mllib库支持的关联算法是FP,随笔 ...

最新文章

  1. max flow value 是网络流里的什么_为什么你这么努力,还是没有通过投行面试
  2. 不要光仅仅知道ipconfig了,你out了
  3. 【漏洞实战】从信息泄露到内网滲透
  4. Chrome 0 day漏洞利用链
  5. db2与oracle的区别 锁,db2和oracle语句区别
  6. Symbol的应用场景1
  7. Buck-Boost变换
  8. [html] http中的301、302、307、308有什么区别?
  9. 一张图解决项目常见乱码问题
  10. 判断一棵树是否为完全二叉树的算法c语言_别再翻了,面试二叉树看这 11 个就够了!||CSDN博客精选...
  11. informix的常用SQL语句
  12. 文华赢顺显示连接服务器失败,文华财经赢顺云本机已被系统限制登陆修复工具...
  13. python绘制单线图_教你快速利用CAD绘制管道单线图.pdf
  14. Excel 绘制 人口年龄结构树状图
  15. 近几十年基础科学的停滞影响研究
  16. 因果卷积(causal)与扩展卷积(dilated)
  17. 使用echarts画饼状图,设置饼状图颜色
  18. 父母脾气暴躁对孩子有哪些影响
  19. 鱼和熊掌兼得——解密阿里云PCDN如何实现高质量低价格
  20. win10账号锁定计算机,win10如何设置账户锁定阈值

热门文章

  1. WinPcap笔记(10):从堆文件中读取数据包
  2. 你知道怎么在生产环境下部署tomcat吗?
  3. python浅蓝色对应的代码_浅蓝色Python模块不在m上工作
  4. 大话数据结构—栈与队列
  5. LeetCode Range Sum Query Immutable
  6. Element表格嵌入复选框以及单选框
  7. python.day05
  8. Java构造函数的深入理解
  9. web前端【第十一篇】jQuery属性相关操作
  10. 函数的定义,语法,二维数组,几个练习题