为什么这个简单算法T(n / 2)+1的最坏情况时间复杂度与n ^ 2 + T(n-1)相反?(Why is the worst case time complexity of this simple algorithm T(n/2) +1 as opposed to n^2+T(n-1)?)

在此处输入图像描述

以下问题是关于大学最近的任务。 我原以为答案是n ^ 2 + T(n-1)因为我认为n ^ 2会使它的渐近时间复杂度为O(n ^ 2)。 与T(n / 2)+1一样,其渐近时间复杂度为O(log2(n))。

答案被返回,结果是正确的答案是T(n / 2)+1然而我无法理解为什么会这样。

有人可能会向我解释为什么这个算法的最坏情况时间复杂度? 我对时间复杂性的理解可能是错误的。


enter image description here

The following question was on a recent assignment in University. I would have thought the answer would be n^2+T(n-1) as I thought the n^2 would make it's asymptotic time complexity O(n^2). Where as with T(n/2)+1 its asymptotic time complexity would be O(log2(n)).

The answers were returned and it turns out the correct answer is T(n/2)+1 however I can't get my head around why this is the case.

Could someone possibly explain to me why that's the worst case time complexity of this algorithm? It's possible my understanding of time complexity is just wrong.


原文:https://stackoverflow.com/questions/36627715
2024-04-22 21:04

满意答案

我也使用glmatrix和require.js,最新的版本有require.js支持,对我来说似乎工作正常。

但是我对require.js的使用略有不同,我的模块通常是这样开始的:

define(['lib/glmatrix/gl-matrix'],
    function(glmatrix) {
        var myModule = function() {};
        // use glmatrix.vec3, etc here
        return myModule;
});

这对你有用吗?


I use glmatrix too with require.js, the most recent version has require.js support and for me it seems to work fine.

I have however I slightly different usage with require.js, my modules usually start like this:

define(['lib/glmatrix/gl-matrix'],
    function(glmatrix) {
        var myModule = function() {};
        // use glmatrix.vec3, etc here
        return myModule;
});

Does this work for you?

相关问答

更多

如何一起使用requireJS和jQuery?(How do I use requireJS and jQuery together?)

这也是我的确切问题! 我也必须使用一个较旧的jQuery,而且还有更多的“传统”JavaScript库。 最好的技术是什么? (我可以编辑你的问题,使它更广泛,如果你不介意。)这是我学到的。 RequireJS作者James Burke解释了RequireJS + jQuery文件组合的优点 。 你得到两件事 一个模块jquery是可用的,它是jQuery对象。 这是安全的: // My module depends on jQuery but what if $ was overwritten?...

使用带有requirejs的whenjs(Using whenjs with requirejs)

尝试使用requirejs.config的paths属性:如果你将when.js放在js/libs/when/when.js ,你可以尝试: requirejs.config({ paths: { 'when': 'libs/when/when' } }); define(['when'], function(When) {... 如果您的JavaScript代码包含baseUrl ,则甚至不需要baseUrl ,但如果需要...

RequireJS应用程序无法识别我的依赖项(RequireJS application not recognising my dependencies)

在问题解决后发布我的评论作为答案。 在指定路径时,require.js不需要文件扩展名.JQuery的当前路径 jquery : 'vendor/jquery-2.2.0.min.js', 将被取代 jquery : 'vendor/jquery-2.2.0.min', 有关文档的更多信息 RequireJS默认还假定所有依赖项都是脚本,因此它不希望在模块ID上看到尾随的“.js”后缀。 在将模块ID转换为路径时,RequireJS会自动添加它。 Posting my comment as an ...

glMatrix不工作?(glMatrix not working?)

只需检查API,您就会遇到一个相当基本的问题,例如x = f(x); vec3.normalize()返回输入内核的修改版本(见下文) 来自http://glmatrix.net/docs/2.2.0/symbols/src/gl-matrix_src_gl-matrix_vec3.js.%3Chtml 333 /** 334 * Normalize a vec3 335 * 336 * @param {vec3} out the receiving vector 337 * @param...

RequireJS优化器 - Oracle MapViewer有多个匿名定义(RequireJS optimizer - Oracle MapViewer has more than one anonymous define)

r.js优化器无法理解包含多个匿名define调用的文件。 您必须找到不包含多个匿名define调用的oraclemaps版本。 (这意味着除了oraclemaps之外你必须得到jQuery和Kendo oraclemaps 。)如果这样的构建不可用,你可以处理oraclemaps来删除额外的模块。 或者您可以处理它以便为define调用添加名称。 There's nothing the r.js optimizer can do to understand files that contain ...

使用requirejs与节点(using requirejs with node)

使用RequireJS服务器端存在原因,但它们很少。 除非你能说明理由,例如: 我必须使用RequireJS因为X. “X”是证明使用RequireJS的理由,那么你就不应该这样做。 请注意,仅仅想要以AMD格式编写模块是不够的,因为存在允许在Node中加载AMD模块的加载器 (如node-amdl-loader )。 当我想测试不依赖于浏览器的代码时,我实际上使用了这个。 我以AMD格式编写模块,并指定如果在Node中使用,则应使用类似node-amd-loader的AMD加载程序。 这样,库既...

无法找到gradle 2.2.0-rc1(Could not find gradle 2.2.0-rc1)

根据: https : //code.google.com/p/android/issues/detail?id=221529 问题已经解决(确切地说:小时前)。 只是为了重建你的项目。 According to: https://code.google.com/p/android/issues/detail?id=221529 The problem is already fixed (exactly: hour ago). Just for sure rebuild your project....

使用cordova-android创建,导致cordova-2.2.0.jar:没有这样的文件或目录(use cordova-android create,cause cordova-2.2.0.jar: No such file or directory)

您很可能已经下载了Cordova src并解压缩了cordova-android.zip文件。 相反,只需下载Phonegap下载并将其解压缩并cd进入phonegap / lib / android / bin文件夹即可执行create。 More than likely you have downloaded the Cordova src and extracted the cordova-android.zip file. Instead, just download the Phoneg...

使用RequireJS设置smooch-js(Setup smooch-js with RequireJS)

您应该在需求调用中使用“Smooch”而不是“smooch”,如下所示: <!doctype html><html> <head> <meta charset="utf-8"> <script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js"></script> <script> require.config({ "paths": ...

带有RequireJS的glMatrix 2.2.0(glMatrix 2.2.0 with RequireJS)

我也使用glmatrix和require.js,最新的版本有require.js支持,对我来说似乎工作正常。 但是我对require.js的使用略有不同,我的模块通常是这样开始的: define(['lib/glmatrix/gl-matrix'], function(glmatrix) { var myModule = function() {}; // use glmatrix.vec3, etc here return myModule...

相关文章

更多

I18n的一个问题

升级了,2.2.2, 用了I18n. 问题来了。 以前model validation 出错的默认消 ...

hibernate 1+N 问题

有一个表ID表 @Entity @Table(name=&quot;WF_ID_CH_TBL&qu ...

Don’t work. Be hated. Love someone.

http://halfhalf.posterous.com/dont-work-be-hated-lo ...

hibernate一级缓存及N+1问题

Hibernate的一级缓存是由Session提供的,因此它只存在于Session的生命周期中,也就是 ...

物理专业英语词汇(H-N)

物理专业英语词汇(H-N) H h maser 氢微波激射器氢脉泽 h parameter h参数 ...

Storm常见模式——求TOP N

Storm的另一种常见模式是对流式数据进行所谓“streaming top N”的计算,它的特点是持续 ...

solr 优化索引成 2段或N段

默认 solr 优化索引的时候,只一个段,比起 N段(N不是很大)来说,可能有点耗时。索引为N段也不会 ...

I18N 国际化 简介

软件的国际化: 软件开发时,要使它能同时应对世界不同地区和国家的访问,并针对不同地区和国家的访问,提 ...

gui求jtapi高手T_T

小弟今年刚毕业,上了一个星期班,老大要我用jtapi写一个监控程序,弄了两天了,头很大啊。 有一部座 ...

最新问答

更多

sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)

否(它不会使它们无法访问),是(您可以在没有停机的情况下运行它)。 sp_updatestats可以在没有停机的情况下针对实时数据库运行。 No (it doesn't make them inaccessible), and Yes (you can run it without downtime). sp_updatestats can be run against a live database without downtime.

如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)

最终,我们选择了使用Spark Framework for Java实现的后端REST API。 这可能不是最强大的,用户反馈一直是个问题。 我们将命令行界面拆分为提交REST调用,并将结果显示给用户。 Ultimately, we chose to go the route of having a backend REST API that was implemented with the Spark Framework for Java. This may not be the most r

AESGCM解密失败的MAC(AESGCM decryption failing with MAC)

您不能将Encoding.UTF8.GetString应用于任意二进制数据。 它只能解码使用UTF-8编码字符串的结果的字节。 .net实现将默默地破坏数据,而不是默认情况下抛出异常。 您应该使用Base64: Convert.FromBase64String和Convert.ToBase64String You can't apply Encoding.UTF8.GetString to arbitrary binary data. It can only decode bytes that

Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)

我希望能看到更多你的Sass代码等,但我的猜测是你需要在所有嵌套行上使用nest行为。 在我看来,基金会在Sass中的行主要是为了在一个层面上使用。 嵌套在另一行中的任何行都应使用nest行为,除非您希望在列上添加额外的填充。 在你的CodePen中,我能够通过向所有行添加一类collapse来修复列上填充的问题,我认为这与执行$behavior: nest相同$behavior: nest在Sass中$behavior: nest :

湖北京山哪里有修平板计算机的

京山有个联想的专卖店,那里卖平板电脑,地址在中百前面的十字路口右拐 ,他们应该会提供相关的维修服务。

SimplePie问题(SimplePie Problem)

我怀疑由于内容的性质(包含代码),stackoverflow提要不起作用。 我使用许多feed解析器看似“正常”的feed有类似的问题,尽管我最近运气最多的是Zend_Feed。 试试吧 I suspect the stackoverflow feed is not working due to the nature of the content (contains code). I have had similar issues with seemingly "normal" feeds us

在不同的任务中,我们可以同时使用多少“上下文”?(How many 'context' we can use at a time simultaneously in different tasks?)

是的,您可以通过getApplicationContext()任意数量的时间(后台任务), getApplicationContext()仅返回应用程序的context 。 Yes, you can pass getApplicationContext() any number of time (Background Tasks ) you want, getApplicationContext() simply returns context of the application.

HTML / Javascript:从子目录启用文件夹访问(HTML/Javascript: Enabling folder access from a subdirectory)

这是我最终做的事情: 我无法以这种方式提供完全访问权限,而是在project level folder中设置了一个虚拟HTML页面,该页面单击自身以重定向到位于separate, non-project util folder的HTML文件。 这允许我保留除了那个之外的所有内容,非常小的文件分开但不存在文件访问问题。 Here is what I ended up doing: I wasn't able to provide full access exactly this way, but

为什么我会收到链接错误?(Why do I get a linker error?)

看起来您的编译器错误地将名称引入到全局名称空间中,而不是C ++ 11 3.5 / 7中指定的最内层名称空间( Bushman ): 如果没有找到具有链接的实体的块范围声明来引用某个其他声明,那么该实体是最内层封闭名称空间的成员。 代码按照预期在GCC上编译: http : //ideone.com/PR4KVC 你应该能够通过在构造函数的块作用域中声明它之前(或代替它)在正确的名称空间中声明该函数来解决该bug。 但是,我无法访问您的编译器来测试它。 It looks like your co

如何正确定义析构函数(How to properly define destructor)

在C ++中,你需要手动释放内存。 没有垃圾收集器。 您显然需要在析构函数内手动释放内存。 如果您使用new分配内存,则需要对在deconstructor中使用new分配的每个资源使用delete ,例如: class1::~class1(void) { delete resource1; delete resource2; etc... } In C++ you need to free the memory manually. There's no garbage