latex 插图解释_大O符号-只需插图和视频即可解释
latex 插图解释
Big O notation is used to communicate how fast an algorithm is. This can be important when evaluating other people’s algorithms, and when evaluating your own! In this article, I’ll explain what Big O notation is and give you a list of the most common running times for algorithms using it.
大O表示法用于传达算法的速度。 这在评估别人的算法以及评估自己的算法时可能很重要! 在本文中,我将解释Big O表示法是什么,并为您提供使用该算法的最常见运行时间的列表。
算法运行时间以不同的速度增长 (Algorithm running times grow at different rates)
My son Judah has a lot of toys. In fact, he has acquired a billion toys! You’d be surprised how quickly a kid can get that many toys if he’s the first grandchild on both sides of the family. ??
我的儿子犹大有很多玩具。 实际上,他已经获得了十亿个玩具! 如果一个孩子是家庭双方的第一个孙子,那么一个孩子这么快就能得到这么多玩具,您会感到惊讶。 ??
Anyway, Judah has a problem. When his friends visit and want to play with a specific toy, it can take FOREVER to find the toy. So he wants to create a search algorithm to help him find a specific toy as quick as possible. He is trying to decide between two different search algorithms: simple search and binary search. (Don’t worry if you are not familiar with these algorithms.)
无论如何,犹大有问题。 当他的朋友拜访并想玩特定的玩具时,可能需要永远找到玩具。 因此,他想创建一个搜索算法来帮助他尽快找到特定的玩具。 他正在尝试在两种不同的搜索算法之间做出选择:简单搜索和二进制搜索。 (如果您不熟悉这些算法,请不要担心。)
The algorithm chosen needs to be both fast and correct. On one hand, binary search is faster. And Judah often only has about 30 seconds before his friend gets bored looking for a toy. On the other hand, a simple search algorithm is easier to write, and there is less chance of bugs being introduced. It sure would be embarrassing if his friend found bugs in his code! To be extra careful, Judah decides to time both algorithms with a list of 100 toys.
选择的算法必须既快速又正确。 一方面,二进制搜索更快。 犹大常常只有大约3 0秒 ,他的朋友就会无聊地寻找玩具。 另一方面,简单的搜索算法更易于编写,而且引入错误的机会也更少。 如果他的朋友在他的代码中发现错误,那肯定会很尴尬! 为格外小心,犹大决定为这两种算法计时,并列出100个玩具。
Let’s assume it takes 1 millisecond to check one toy. With simple search, Judah has to check 100 toys, so the search takes 100 ms to run. On the other hand, he only has to check 7 toys with binary search (log2 100 is roughly 7, don’t worry if this math is confusing since it isn’t the main point of this article), so that search takes 7 ms to run. But really, the list will have a billion toys. If it does, how long will simple search take? How long will binary search take?
假设检查一个玩具需要1毫秒。 通过简单的搜索,犹大必须检查100个玩具,因此搜索需要100毫秒才能运行。 另一方面,他只需要通过二进制搜索来检查7个玩具(log2 100大约是7,所以不用担心这个数学是否令人困惑,因为它不是本文的重点),因此搜索需要7毫秒跑步。 但实际上,清单上将有十亿个玩具。 如果可以,简单搜索将花费多长时间? 二进制搜索需要多长时间?
简单搜索与二进制搜索的运行时间,列出了100个元素 (Running time for simple search vs. binary search, with a list of 100 elements)
Judah runs binary search with 1 billion toys, and it takes 30 ms (log2 1,000,000,000 is roughly 30). “32 ms!” he thinks. “Binary search is about 15 times faster than simple search, because simple search took 100 ms with 100 elements, and binary search took 7 ms. So simple search will take 30 × 15 = 450 ms, right? Way under the 30 seconds it takes for my friend to get bored.” Judah decides to go with simple search. Is that the right choice?
犹大使用10亿个玩具进行二进制搜索,耗时30毫秒(log2 1,000,000,000大约为30)。 “ 32毫秒!” 他想。 “二进制搜索比简单搜索快15倍,因为简单搜索用100个元素需要100毫秒,而二进制搜索则需要7毫秒。 这样简单的搜索将花费30×15 = 450 ms,对吗? 不到30秒,我的朋友就变得无聊了。” 犹大决定进行简单的搜索。 那是正确的选择吗?
No. Turns out, Judah was wrong and lost a friend for life. ? The run time for simple search with 1 billion items will be 1 billion ms, which is 11 days! The problem is, the run times for binary search and simple search don’t grow at the same rate.
没有。事实证明,犹大错了,终生失去了一个朋友。 ? 具有10亿个项目的简单搜索的运行时间将为10亿毫秒,即11天! 问题是,二进制搜索和简单搜索的运行时间不会以相同的速度增长。
Run times grow at very different speeds! As the number of items increases, binary search takes a little more time to run, but simple search takes a lot more time to run. So as the list of numbers gets bigger, binary search suddenly becomes a lot faster than simple search.
运行时间以不同的速度增长! 随着项目数量的增加,二进制搜索需要多一点时间来运行,但简单的搜索需要更多的时间来运行。 因此,作为号码列表变大,二进制搜索突然变得很多比简单的搜索速度更快。
So Judah was wrong about binary search always being 15 times faster than simple search. If there are 1 billion toys, it’s more like 33 million times faster.
因此,犹大错了,因为二进制搜索总是比简单搜索快15倍。 如果有10亿个玩具,则速度要快3300万倍。
It is very important to know how the running time increases as the list size increases. That’s where Big O notation comes in.
了解运行时间如何随着列表大小的增加而增加非常重要。 那就是Big O表示法出现的地方。
Big O notation tells you how fast an algorithm is. For example, suppose you have a list of size n. Simple search needs to check each element, so it will take n operations. The run time in Big O notation is O(n).
大O表示法告诉您算法有多快。 例如,假设您有一个大小为n的列表。 简单搜索需要检查每个元素,因此将需要n次操作。 Big O表示法的运行时间为O( n )。
Where are the seconds? There are none — Big O doesn’t tell you the speed in seconds. Big O notation lets you compare the number of operations. It tells you how fast the algorithm grows.
秒在哪里? 没有-大O不会以秒为单位告诉您速度。 大O表示法使您可以比较操作数。 它告诉您算法的增长速度。
Let’s do another example. Binary search needs log n operations to check a list of size n. What’s the running time in Big O notation? It’s O(log n). In general, Big O notation is written as follows.
让我们再举一个例子。 二进制搜索需要log n次操作才能检查大小为n的列表。 Big O符号的运行时间是多少? 是O(log n )。 通常,Big O表示法如下所示。
This tells you the number of operations an algorithm will make. It’s called Big O notation because you put a “big O” in front of the number of operations.
这告诉您算法将执行的操作数。 之所以称为Big O表示法,是因为您在操作数前面放置了一个“ big O”。
大O确定最坏的运行时间 (Big O establishes a worst-case run time)
Suppose you’re using simple search to look for a user in your user database. You know that simple search takes O(n) time to run, which means in the worst case, you’re algorithm will have to look through every user in the database. In this case, you’re looking for a user with the name ‘aardvark213’. This is the first user in the list. So your algorithm didn’t have to look at every entry — it found it on the first try. Did the algorithm take O(n) time? Or did it take O(1) time because it found the person on the first try?
假设您正在使用简单搜索在用户数据库中查找用户。 您知道简单搜索需要O( n )时间来运行,这意味着在最坏的情况下,您的算法将必须遍历数据库中的每个用户。 在这种情况下,您正在寻找名称为“ aardvark213”的用户。 这是列表中的第一个用户。 因此,您的算法不必查看每个条目-它是在第一次尝试时就发现的。 该算法是否花费O( n )时间? 还是花了O(1)时间,因为它在第一次尝试中找到了那个人?
Simple search still takes O(n) time. In this case, the algorithm found what it was looking for instantly. That’s the best-case scenario. But Big O notation is about the worst-case scenario. So you can say that, in the worst case, the algorithm will have to look through every user in the database once. That’s O(n) time. It’s a reassurance — you know that simple search will never be slower than O(n) time.
简单搜索仍然需要O( n )时间。 在这种情况下,算法会立即找到其要查找的内容。 那是最好的情况。 但是Big O符号是关于最坏情况的。 因此,您可以说,在最坏的情况下 ,该算法将不得不遍历数据库中的每个用户一次。 那是O( n )时间。 可以放心-简单的搜索永远不会比O( n )时间慢。
一些常见的Big O运行时间 (Some common Big O run times)
Here are five Big O run times that you’ll encounter a lot, sorted from fastest to slowest:
这是您会遇到的五个大O运行时间,从最快到最慢排序:
O(log n), also known as log time. Example: Binary search.
O(log n ),也称为对数时间。 示例:二进制搜索。
O(n), also known as linear time. Example: Simple search.
O( n ),也称为线性时间 。 示例:简单搜索。
O(n * log n). Example: A fast sorting algorithm, like quicksort.
O( n * log n )。 示例:一种快速排序算法,例如quicksort。
O(n2). Example: A slow sorting algorithm, like selection sort.
O( n 2)。 示例:慢速排序算法,例如选择排序。
O(n!). Example: A really slow algorithm, like the traveling salesperson.
O( n !) 示例:一个非常慢的算法,例如旅行营业员。
可视化不同的大O运行时间 (Visualizing different Big O run times)
Suppose you’re drawing a grid of 16 boxes, and you can choose from 5 different algorithms to do so. If you use the first algorithm, it will take you O(log n) time to draw the grid. You can do 10 operations per second. With O(log n) time, it will take you 4 operations to draw a grid of 16 boxes (log 16 base 2 is 4). So it will take you 0.4 seconds to draw the grid. What if you have to draw 1,024 boxes? It will take you log 1,024 = 10 operations, or 1 second to draw a grid of 1,024 boxes. These numbers are using the first algorithm.
假设您要绘制一个由16个框组成的网格,并且可以从5种不同的算法中进行选择。 如果使用第一种算法,则将花费O(log n )时间来绘制网格。 您每秒可以执行10次操作。 使用O(log n )时间,您将需要4次操作才能绘制一个由16个框组成的网格(log 16以2为底)。 因此,绘制网格将需要0.4秒。 如果您必须画1,024箱怎么办? 您将需要记录1,024 = 10个操作,或1秒才能绘制一个1,024个框的网格。 这些数字使用第一种算法。
The second algorithm is slower: it takes O(n) time. It will take 16 operations to draw 16 boxes, and it will take 1,024 operations to draw 1,024 boxes. How much time is that in seconds?
第二种算法较慢:需要O( n )时间。 绘制16个盒子需要16个操作,绘制1,024个盒子将需要1,024个操作。 以秒为单位的时间是多少?
Here’s how long it would take to draw a grid for the rest of the algorithms, from fastest to slowest:
这是为其余算法(从最快到最慢)绘制网格所需的时间:
There are other run times, too, but these are the five most common.
也有其他运行时间,但这是最常见的五个时间。
This is a simplification. In reality you can’t convert from a Big O run time to a number of operations this neatly, but this is good estimation.
这是一个简化。 实际上,您不能整齐地将Big O运行时转换为许多操作,但这是一个很好的估计。
结论 (Conclusion)
Here are the main takeaways:
这是主要的要点:
- Algorithm speed isn’t measured in seconds, but in growth of the number of operations.算法速度不是以秒为单位,而是以操作数量的增长来衡量。
- Instead, we talk about how quickly the run time of an algorithm increases as the size of the input increases.相反,我们谈论的是算法的运行时间随着输入大小的增加而增加的速度。
- Run time of algorithms is expressed in Big O notation.算法的运行时间以Big O表示法表示。
O(log n) is faster than O(n), but it gets a lot faster as the list of items you’re searching grows.
O(log n )比O( n )快,但是随着您要搜索的项目列表的增加,它变得更快。
And here is a video that covers a lot of what is in this article and more.
这是一个视频,涵盖了本文以及更多内容。
I hope this article brought you more clarity about Big O notation. This article is based on a lesson in my video course from Manning Publications called Algorithms in Motion. The course is based on the amazing book Grokking Algorithms by Adit Bhargava. He’s the one who drew all the fun illustrations in this article.
我希望本文能使您对Big O符号有更多的了解。 本文基于我的视频课程中曼宁出版物上的一门课程,该课程称为“ 运动中的算法” 。 该课程基于Adit Bhargava 撰写的令人惊讶的 《 Grokking Algorithms》一书。 他是绘制本文中所有有趣插图的人。
If you learn best through books, get the book! If you learn best through videos, consider buying my course. You can get 39% off my course by using the code ‘39carnes’.
如果您通过书本学得最好,请获取书本 ! 如果您通过视频学习得最好,请考虑购买我的课程 。 使用代码“ 39carnes ”,您可以从我的课程中获得39%的折扣。
翻译自: https://www.freecodecamp.org/news/big-o-notation-simply-explained-with-illustrations-and-video-87d5a71c0174/
latex 插图解释
相关文章:

[YTU]_2002(C语言实验——单词统计)
Description 从键盘输入一行字符,统计其中单词的个数,各单词以空格分隔,且空格数可以是多个。Input 输入只有一行句子。仅有空格和英文字母构成。 Output 单词的个数。 Sample Input stable marriage problem Consists of Matching memb…

资本中国人物-金融
一、二、三、店、五、土地、七、八、玖、拾起、白、千、一万、一亿、元(圆)、角、支、零、整个。这是上图中我们经常要填写。问:什么是它用数词?想必很多人都不是很清楚! 请看下面的两个相关的表数词: 1、数字化和大、小写数字对照…

Ant Design Pro 网络请求流程
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 在 Ant Design Pro 中,一个完整的前端 UI 交互到服务端处理流程是这样的: UI 组件交互操作; 调用 model 的 effect; 调用统一管理的 service 请求函数&a…

在Google Cloud Platform上持续部署Node.js
by Gautam Arora由Gautam Arora 在Google Cloud Platform上持续部署Node.js (Continuous Deployment for Node.js on the Google Cloud Platform) Google Cloud Platform (GCP) provides a host of options for Node developers to easily deploy our apps. Want a managed ho…

hdu-1108 最小公倍数
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid1108 题目类型: 数论 题意概括: 求两个数的最小公倍数 解题思路: 模拟 题目: 最小公倍数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O…

sql-schema与catalog
schema: 指的是说当偶create database caiceclb时,caiceclb就是一个schema catalog: 指的是所有的database目录,就像上图显示的那样,将MySQL原来的(mysql,infomation_schema)及后来新建的的data…

这是如何更好地利用JavaScript数组的方法
by pacdiv由pacdiv 这是如何更好地利用JavaScript数组的方法 (Here’s how you can make better use of JavaScript arrays) Quick read, I promise. Over the last few months, I noticed that the exact same four mistakes kept coming back through the pull requests I c…

07、C语言——函数
函数 1、函数定义 函数返回值类型 函数名(形式参数列表) { 函数体; } 注意: 定义有参函数时,形参的定义可以采用传统方式或现代方式两种 1)传统方式: int …

This is probably not a problem with npm. There is likely additional logging output above
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 E:\weii_objct\invoice-manage-web-view>npm start > ant-design-pro@2.1.0 start E:\weii_objct\invoice-manage-web-view > cross-env APP_TYPE=site umi dev cross-env 不是内部或外部命令…

parcel react_如何使用Parcel捆绑React.js应用程序
parcel reactby Michael Ozoemena迈克尔奥索埃梅纳(Michael Ozoemena) 如何使用Parcel捆绑React.js应用程序 (How to use Parcel to bundle your React.js application) 什么是包裹? (What’s Parcel?) Parcel is a web application bundler which offers a blazi…

SparkSQL 与 Spark Core的关系
不多说,直接上干货! SparkSQL 与 Spark Core的关系 Spark SQL构建在Spark Core之上,专门用来处理结构化数据(不仅仅是SQL)。 Spark SQL在Spark Core的基础上针对结构化数据处理进行很多优化和改进, 简单来讲: Spark SQ…

linux操作系统-设置静态ip
在使用linux虚拟机的时候因为经常有关机的需求,然后重新开机后可能面临这上一次获取的ip被改变,在这里我分享一下在linux 下设置静态ip的经验 1.查看路由状态 [rootlocalhost ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Met…

判断数组里面的下标是否等于一个字符串
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 使用includes() 1、判断字符串里面是否包含一个字符串 示例: var a aaaaaaaavconsole.log(a.includes(v)); //truevar a aaaaaaaavconsole.log(a.includes(c)); //falsevar a aa…

如何获得更多的自由开发者客户
by Jad Joubran通过贾德乔布兰(Jad Joubran) 如何获得更多的自由开发者客户 (How to get more clients as a freelance developer) 我希望几年前知道的实用技巧 (Practical tips I wish I knew a few years ago) Whenever a conversation about freelancing kicks off with fe…

2017.6.4 入门组 NO.2——睡眠
其实这题就是将第二个时间-第一个时间,小于0的补全就A了代码如下: var x,y,k:string;l1,l2,x1,x2,x3,y1,y2,y3:longint; beginreadln(x);readln(y);l1:pos(:,x);l2:pos(:,y);k:copy(x,1,2); val(k,x1);k:copy(x,l11,2); val(k,y1);k:copy(y,1,2); val(k…

微信小程序获取用户收货地址 完整代码
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 获取用户收货地址需要用户点击授权,所以有两种情况,确认授权、取消授权。 情况一,用户第一次访问用户地址授权,并且点击确定授权。 情况二,用…

easyui的combobox下拉框初始化默认值以及保持该值一直显示的方法
easyui的combobox下拉框默认初始值是空,下面是实现从远程加载数据之后初始化默认值,以及让该值一直排在下拉框的最顶部的方式。 目前的需求是需要在初始化的时候添加"全部数据库"字段,并且在下拉的时候,"全部数据库"一直排在最顶部。 初始化效果…

关系数据库非关系数据库_如何与关系数据库最佳配合
关系数据库非关系数据库Relational databases handle data smoothly, whether working with small volumes or processing millions of rows. We will be looking at how we can use relational databases according to our needs, and get the most out of them.关系数据库无论…

看过的bootstrap书籍(附下载地址)
http://yun.baidu.com/share/link?shareid3820784617&uk1008683945 以下书籍下载地址。 《BootStrap入门教程》 就是网上的常规教程,过了一遍,不是很重要。 《Bootstrap实战_第一章》 没找到其余的章节,不过这本书不如直接看网上的boots…

Sql的连接表补充
连接条件可在FROM或WHERE子句中指定,建议在FROM子句中指定连接条件。WHERE和HAVING子句也可以包含搜索条件,以进一步筛选连接条件所选的行。 连接可分为以下几类: 内连接。(典型的连接运算,使用像 或 <…

js正则验证身份证号是否正确
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 封装js公共方法 //验证身份证格式 const IdentityCodeValid sId > {const aCity { 11: "北京", 12: "天津", 13: "河北", 14: "山西", 15: "内蒙古…

jupyter笔记本_如何为Jupyter笔记本电脑设置PySpark
jupyter笔记本by Tirthajyoti Sarkar由Tirthajyoti Sarkar 如何为Jupyter笔记本电脑设置PySpark (How to set up PySpark for your Jupyter notebook) Apache Spark is one of the hottest frameworks in data science. It realizes the potential of bringing together both …

php 判断是否有相同的ID,如果有就修改数据库字段,没有就插入数据库字段
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 php代码 <?phpheader("Content-Type:text/html;charsetutf8"); header("Access-Control-Allow-Origin: *"); //解决跨域header(Access-Control-Allow-Methods:POST);// 响应类…

MySql存储引擎特性对比
下表显示了各种存储引擎的特性: 其中最常见的两种存储引擎是MyISAM和InnoDB 刚接触MySQL的时候可能会有些惊讶,竟然有不支持事务的存储引擎,学过关系型数据库理论的人都知道,事务是关系型数据库的核心。但是在现实应用中ÿ…

如何使用React提前三天计划
by Mohit Jain由Mohit Jain 如何使用React提前三天计划 (How you can plan three days ahead with React) Today we’ll be making a ‘to-do’ website… with some different features.今天,我们将建立一个具有一些不同功能的“待办事项”网站。 You can check …

ajax 基础
ajax基础模式 url : "Handler.ashx", -- 提交到哪个服务端 data: { "uname": s }, -- 提交的数据,以键值对的方式传字符串,只能是字符串,可以传多个。 type: "post", …

wamp配置虚拟域名
1、打开apache下httpd.conf 我的目录是在F:\wamp\bin\apache\apache2.2.22\conf\httpd.conf 2、去掉这两行前面的#注释 LoadModule rewrite_module modules/mod_rewrite.so Include conf/extra/httpd-vhosts.conf 这两个注释 3、配置httpd-vhosts.conf <VirtualHost *:80>…

VUE 事件获取当前组件的属性
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 for循环把当前的item传递给绑定事件: <block v-for"(item, index) in data_list"><div v-on:clickchangeType(item) class"ci "><div class"cib&q…

javascript计时器_JavaScript计时器:您需要了解的一切
javascript计时器by Samer Buna通过Samer Buna JavaScript计时器:您需要了解的一切 (JavaScript Timers: Everything you need to know) A few weeks ago, I tweeted this interview question:几周前,我在推特上发布了这个面试问题: *** An…
软考总结——虚存管理
存储管理是操作系统的重要职能之中的一个,主要任务是对内存空间进行分配与回收。因为计算机内存容量有限(如今一般都是32位或64位系统),而外存储设备的容量增长速度很快,比如移动硬盘已经到了…